pub fn encapsulate<R>(pk: &[u8], rng: &mut R) -> EncapsulatedExpand description
Encapsulates a public key and returns the ciphertext to send and the shared secret.
This function encapsulates a public key and returns the ciphertext and the shared secret.
§Arguments
pk- The public key as a slice of bytes.rng- The random number generator implementing theRngCoreandCryptoRngtraits.
§Errors
Returns KyberLibError::InvalidInput if pk has the wrong length, or
KyberLibError::InvalidKey if it fails the FIPS 203 §7.2 modulus check.
§Example
let mut rng = rand::thread_rng();
let keys = keypair(&mut rng)?;
let (ciphertext, shared_secret) = encapsulate(&keys.public, &mut rng)?;