Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions kem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use common::{

use common::array::{self, ArraySize};
use core::{array::TryFromSliceError, convert::Infallible};
use rand_core::TryCryptoRng;
use rand_core::CryptoRng;

#[cfg(feature = "getrandom")]
use common::getrandom::{SysRng, rand_core::UnwrapErr};
Expand Down Expand Up @@ -50,17 +50,14 @@ pub trait KemParams {
pub trait Encapsulate: KemParams + TryKeyInit + KeyExport {
/// Encapsulates a fresh [`SharedSecret`] generated using the supplied random number
/// generator `R`.
fn encapsulate_with_rng<R: TryCryptoRng + ?Sized>(
&self,
rng: &mut R,
) -> Result<(Ciphertext<Self>, SharedSecret<Self>), R::Error>;
fn encapsulate_with_rng<R>(&self, rng: &mut R) -> (Ciphertext<Self>, SharedSecret<Self>)
where
R: CryptoRng + ?Sized;

/// Encapsulate a fresh shared secret generated using the system's secure RNG.
#[cfg(feature = "getrandom")]
fn encapsulate(&self) -> (Ciphertext<Self>, SharedSecret<Self>) {
match self.encapsulate_with_rng(&mut UnwrapErr(SysRng)) {
Ok(ret) => ret,
}
self.encapsulate_with_rng(&mut UnwrapErr(SysRng))
}
}

Expand Down