#ml #lattice #fips #kem #203

fips203-ffi

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

1 unstable release

0.2.1 May 25, 2024

#1251 in Cryptography

Download history 173/week @ 2024-05-24 11/week @ 2024-05-31 4/week @ 2024-06-07

188 downloads per month

MIT/Apache

390KB
1.5K SLoC

Rust 1K SLoC // 0.2% comments Python 220 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)
$ 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–2MB
~29K SLoC