Expand description
API for the KyberLib library. Legacy free-function KEM API.
Three top-level functions cover the ML-KEM-768 key encapsulation mechanism end-to-end:
keypair— generate a fresh (public, secret) keypair.encapsulate— encapsulate a 32-byte shared secret against a public key.decapsulate— recover the shared secret from a ciphertext + secret key.
The legacy Keypair struct bundles the two halves. Prefer the
v0.0.7 typed-state API for new code — it
prevents accidental mixing of EncapsulationKey / DecapsulationKey
at the type level and redacts secret material in Debug output.
§Example
use kyberlib::{keypair, encapsulate, decapsulate};
let mut rng = rand::thread_rng();
let bob = keypair(&mut rng)?;
let (ct, ss_a) = encapsulate(&bob.public, &mut rng)?;
let ss_b = decapsulate(&ct, &bob.secret)?;
assert_eq!(ss_a, ss_b);Structs§
- Keypair
- A public/secret keypair for use with Kyber.
Functions§
- decapsulate
- Decapsulates ciphertext with a secret key.
- derive
- Deterministically derive a keypair from a seed as specified in draft-schwabe-cfrg-kyber.
- encapsulate
- Encapsulates a public key and returns the ciphertext to send and the shared secret.
- keypair
- Generate a key pair for Kyber encryption with a provided RNG.
- keypairfrom
- Verify that given secret and public key matches and put them in the KeyPair structure after zeroize them if asked.
- public
- Extracts a public key from a private key.