Skip to content

Commit

Permalink
Add Clone to KemCore and KemCore::EncapsulationKey (#79)
Browse files Browse the repository at this point in the history
Add Clone to `KemCore` and `KemCore::EncapsulationKey` so that
downstream it is possible to make items using generic elements Clone as
well. For example doing something like the following requires not only
`KemCore::EncapsulationKey` to implement `Clone` but also `KemCore`
itself.

```rs
#[derive(Clone)]
struct HandshakeMaterials<K: KemCore> {
    // ...
    ek: <K as KemCore>::EncapsulationKey,
    // ...
}
```

Co-authored-by: jmwample <[email protected]>
  • Loading branch information
jmwample and jmwample authored Jan 21, 2025
1 parent 17811e5 commit 9231075
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions ml-kem/src/kem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ where

/// An implementation of overall ML-KEM functionality. Generic over parameter sets, but then ties
/// together all of the other related types and sizes.
#[derive(Clone)]
pub struct Kem<P>
where
P: KemParams,
Expand Down
4 changes: 3 additions & 1 deletion ml-kem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub trait EncapsulateDeterministic<EK, SS> {
}

/// A generic interface to a Key Encapsulation Method
pub trait KemCore {
pub trait KemCore: Clone {
/// The size of a shared key generated by this KEM
type SharedKeySize: ArraySize;

Expand All @@ -128,6 +128,7 @@ pub trait KemCore {
#[cfg(not(feature = "deterministic"))]
type EncapsulationKey: Encapsulate<Ciphertext<Self>, SharedKey<Self>>
+ EncodedSizeUser
+ Clone
+ Debug
+ PartialEq;

Expand All @@ -136,6 +137,7 @@ pub trait KemCore {
type EncapsulationKey: Encapsulate<Ciphertext<Self>, SharedKey<Self>>
+ EncapsulateDeterministic<Ciphertext<Self>, SharedKey<Self>>
+ EncodedSizeUser
+ Clone
+ Debug
+ PartialEq;

Expand Down

0 comments on commit 9231075

Please sign in to comment.