#fips #ml #lattice #kem #fips203

fips203-ffi

C shared library exposing FIPS 203: Module-Lattice-Based Key-Encapsulation Mechanism

2 unstable releases

0.4.1 Oct 13, 2024
0.2.1 May 25, 2024

#1261 in Cryptography

Download history 2/week @ 2024-09-21 177/week @ 2024-10-12 13/week @ 2024-10-19 4/week @ 2024-11-02

194 downloads per month

MIT/Apache

790KB
1.5K SLoC

Rust 1.5K SLoC // 0.2% comments Python 333 SLoC // 0.3% comments

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