2 unstable releases
0.4.1 | Oct 13, 2024 |
---|---|
0.2.1 | May 25, 2024 |
#1261 in Cryptography
194 downloads per month
790KB
1.5K
SLoC
C Shared Object for ML-KEM
This crate provides a shared object (dynamically-linked library) using standard C FFI ABI that provides a functional implementation of ML-KEM.
The goals of this implementation are:
- simplicity
- correctness
- caller deals only with serialized objects
- no library-specific memory management (caller manages all objects)
- no internal state held by the library between calls
- minimal symbol visibility
- stable API/ABI
security-related goals:
- constant-time operations
- clean library RAM (objects should be zeroed out of any library-allocated memory before function exit)
non-goals are:
- speed
- efficiency
- size
Outstanding work
- better internal error handling
- testing!
- reduce symbol visibility in shared object
Paths considered but discarded
- Autogenerate stable C headers (e.g. with cbindgen); manually-crafted headers are probably fine, given the simplicity of the API/ABI
Quick start
$ cd ffi # this directory
$ cargo build
$ (cd tests && make)
$ cd python
$ python3
>>> from fips203 import ML_KEM_512
>>>
>>> (encapsulation_key, decapsulation_key) = ML_KEM_512.keygen()
>>> (ciphertext, shared_secret_1) = encapsulation_key.encaps()
>>> shared_secret_2 = decapsulation_key.decaps(ciphertext)
>>> assert(shared_secret_1 == shared_secret_2)
Dependencies
~1.5–2.2MB
~30K SLoC