oqs::kem

Struct Kem

source
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

source

pub fn new(algorithm: Algorithm) -> Result<Self>

Construct a new algorithm

source

pub fn algorithm(&self) -> Algorithm

Get the algorithm used by this Kem

source

pub fn version(&self) -> &'static str

Get the version of the implementation

source

pub fn claimed_nist_level(&self) -> u8

Get the claimed nist level

source

pub fn is_ind_cca(&self) -> bool

Is the algorithm ind_cca secure

source

pub fn length_public_key(&self) -> usize

Get the length of the public key

source

pub fn length_secret_key(&self) -> usize

Get the length of the secret key

source

pub fn length_ciphertext(&self) -> usize

Get the length of the ciphertext

source

pub fn length_shared_secret(&self) -> usize

Get the length of a shared secret

source

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.

source

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.

source

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.

source

pub fn shared_secret_from_bytes<'a>( &self, buf: &'a [u8], ) -> Option<SharedSecretRef<'a>>

Obtain a secret key from bytes

Returns None if the shared secret is not the correct length.

source

pub fn keypair(&self) -> Result<(PublicKey, SecretKey)>

Generate a new keypair

source

pub fn encapsulate<'a, P: Into<PublicKeyRef<'a>>>( &self, pk: P, ) -> Result<(Ciphertext, SharedSecret)>

Encapsulate to the provided public key

source

pub fn decapsulate<'a, 'b, S: Into<SecretKeyRef<'a>>, C: Into<CiphertextRef<'b>>>( &self, sk: S, ct: C, ) -> Result<SharedSecret>

Decapsulate the provided ciphertext

Trait Implementations§

source§

impl Drop for Kem

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl TryFrom<Algorithm> for Kem

source§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(alg: Algorithm) -> Result<Kem>

Performs the conversion.
source§

impl Send for Kem

source§

impl Sync for Kem

Auto Trait Implementations§

§

impl Freeze for Kem

§

impl RefUnwindSafe for Kem

§

impl Unpin for Kem

§

impl UnwindSafe for Kem

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.