Skip to main content

encapsulate

Function encapsulate 

Source
pub fn encapsulate<R>(pk: &[u8], rng: &mut R) -> Encapsulated
where R: CryptoRng + RngCore,
Expand 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 the RngCore and CryptoRng traits.

§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)?;