pub struct Kem { /* private fields */ }Expand description
KEM algorithm
§Example
use oqs;
oqs::init();
let kem = oqs::kem::Kem::new(oqs::kem::Algorithm::MlKem512).unwrap();
let (pk, sk) = kem.keypair().unwrap();
let (ct, ss) = kem.encapsulate(&pk).unwrap();
let ss2 = kem.decapsulate(&sk, &ct).unwrap();
assert_eq!(ss, ss2);Implementations§
Source§impl Kem
impl Kem
Sourcepub fn claimed_nist_level(&self) -> u8
pub fn claimed_nist_level(&self) -> u8
Get the claimed nist level
Sourcepub fn is_ind_cca(&self) -> bool
pub fn is_ind_cca(&self) -> bool
Is the algorithm ind_cca secure
Sourcepub fn length_public_key(&self) -> usize
pub fn length_public_key(&self) -> usize
Get the length of the public key
Sourcepub fn length_secret_key(&self) -> usize
pub fn length_secret_key(&self) -> usize
Get the length of the secret key
Sourcepub fn length_ciphertext(&self) -> usize
pub fn length_ciphertext(&self) -> usize
Get the length of the ciphertext
Get the length of a shared secret
Sourcepub fn length_keypair_seed(&self) -> usize
pub fn length_keypair_seed(&self) -> usize
Get the length of a keypair seed
Sourcepub fn secret_key_from_bytes<'a>(
&self,
buf: &'a [u8],
) -> Option<SecretKeyRef<'a>>
pub fn secret_key_from_bytes<'a>( &self, buf: &'a [u8], ) -> Option<SecretKeyRef<'a>>
Obtain a secret key objects from bytes
Returns None if the secret key is not the correct length.
Sourcepub fn public_key_from_bytes<'a>(
&self,
buf: &'a [u8],
) -> Option<PublicKeyRef<'a>>
pub fn public_key_from_bytes<'a>( &self, buf: &'a [u8], ) -> Option<PublicKeyRef<'a>>
Obtain a public key from bytes
Returns None if the public key is not the correct length.
Sourcepub fn ciphertext_from_bytes<'a>(
&self,
buf: &'a [u8],
) -> Option<CiphertextRef<'a>>
pub fn ciphertext_from_bytes<'a>( &self, buf: &'a [u8], ) -> Option<CiphertextRef<'a>>
Obtain a ciphertext from bytes
Returns None if the ciphertext is not the correct length.
Obtain a secret key from bytes
Returns None if the shared secret is not the correct length.
Sourcepub fn keypair_seed_from_bytes<'a>(
&self,
buf: &'a [u8],
) -> Option<KeypairSeedRef<'a>>
pub fn keypair_seed_from_bytes<'a>( &self, buf: &'a [u8], ) -> Option<KeypairSeedRef<'a>>
Obtain a keypair seed from bytes
Returns None if the shared secret is not the correct length.
Sourcepub fn keypair_derand<'a, S: Into<KeypairSeedRef<'a>>>(
&self,
seed: S,
) -> Result<(PublicKey, SecretKey)>
pub fn keypair_derand<'a, S: Into<KeypairSeedRef<'a>>>( &self, seed: S, ) -> Result<(PublicKey, SecretKey)>
Generate a new keypair from a seed
Sourcepub fn encapsulate<'a, P: Into<PublicKeyRef<'a>>>(
&self,
pk: P,
) -> Result<(Ciphertext, SharedSecret)>
pub fn encapsulate<'a, P: Into<PublicKeyRef<'a>>>( &self, pk: P, ) -> Result<(Ciphertext, SharedSecret)>
Encapsulate to the provided public key
Sourcepub fn decapsulate<'a, 'b, S: Into<SecretKeyRef<'a>>, C: Into<CiphertextRef<'b>>>(
&self,
sk: S,
ct: C,
) -> Result<SharedSecret>
pub fn decapsulate<'a, 'b, S: Into<SecretKeyRef<'a>>, C: Into<CiphertextRef<'b>>>( &self, sk: S, ct: C, ) -> Result<SharedSecret>
Decapsulate the provided ciphertext