From 923107512336896cadc5577843f7723d78d14c48 Mon Sep 17 00:00:00 2001 From: Jack Wampler Date: Tue, 21 Jan 2025 13:14:56 -0700 Subject: [PATCH] Add Clone to `KemCore` and `KemCore::EncapsulationKey` (#79) 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 { // ... ek: ::EncapsulationKey, // ... } ``` Co-authored-by: jmwample <8297368+jmwample@users.noreply.github.com> --- ml-kem/src/kem.rs | 1 + ml-kem/src/lib.rs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ml-kem/src/kem.rs b/ml-kem/src/kem.rs index 4abc52a..3e6cf8a 100644 --- a/ml-kem/src/kem.rs +++ b/ml-kem/src/kem.rs @@ -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

where P: KemParams, diff --git a/ml-kem/src/lib.rs b/ml-kem/src/lib.rs index 51b98d0..5feb4ab 100644 --- a/ml-kem/src/lib.rs +++ b/ml-kem/src/lib.rs @@ -111,7 +111,7 @@ pub trait EncapsulateDeterministic { } /// 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; @@ -128,6 +128,7 @@ pub trait KemCore { #[cfg(not(feature = "deterministic"))] type EncapsulationKey: Encapsulate, SharedKey> + EncodedSizeUser + + Clone + Debug + PartialEq; @@ -136,6 +137,7 @@ pub trait KemCore { type EncapsulationKey: Encapsulate, SharedKey> + EncapsulateDeterministic, SharedKey> + EncodedSizeUser + + Clone + Debug + PartialEq;