Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sealed trait to make (De|En)capsulationKeys more usable #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 10 additions & 5 deletions ml-kem/src/kem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ pub use ::kem::{Decapsulate, Encapsulate};
/// A shared key resulting from an ML-KEM transaction
pub(crate) type SharedKey = B32;

/// Derived parameters relevant to ML-KEM
pub trait Params: KemParams {}

impl<K: KemParams> Params for K {}

/// A `DecapsulationKey` provides the ability to generate a new key pair, and decapsulate an
/// encapsulated shared key.
#[derive(Clone, Debug, PartialEq)]
pub struct DecapsulationKey<P>
where
P: KemParams,
P: Params,
{
dk_pke: DecryptionKey<P>,
ek: EncapsulationKey<P>,
Expand Down Expand Up @@ -147,7 +152,7 @@ where
#[derive(Clone, Debug, PartialEq)]
pub struct EncapsulationKey<P>
where
P: KemParams,
P: Params,
{
ek_pke: EncryptionKey<P>,
h: B32,
Expand Down Expand Up @@ -218,7 +223,7 @@ where
/// together all of the other related types and sizes.
pub struct Kem<P>
where
P: KemParams,
P: Params,
{
_phantom: PhantomData<P>,
}
Expand Down Expand Up @@ -258,7 +263,7 @@ mod test {

fn round_trip_test<P>()
where
P: KemParams,
P: Params,
{
let mut rng = rand::thread_rng();

Expand All @@ -279,7 +284,7 @@ mod test {

fn codec_test<P>()
where
P: KemParams,
P: Params,
{
let mut rng = rand::thread_rng();
let dk_original = DecapsulationKey::<P>::generate(&mut rng);
Expand Down