-
Notifications
You must be signed in to change notification settings - Fork 230
Closed
Description
The one remaining gap in the kem API is a way to obtain the bytes serialization of EK and SS (encapsulated key and shared secret respectively), and for EK, a way to deserialize it from bytes before passing it to Decapsulate::decapsulate.
I was first wondering if there's actually a use case for overlapping impls with these traits and if not, perhaps these should be associated types instead? That would make it easier to give them bounds. Something like:
pub trait Encapsulate: TryKeyInit + KeyExport {
/// Shared secret after being encrypted by this encapsulator
type EncapsulatedKey: TryKeyInit + KeyExport;
/// Shared secret value which results after the `EncapsulatedKey` has been decrypted.
type SharedSecret: AsRef<[u8]>;
/// Encapsulates a fresh shared secret
fn encapsulate_with_rng<R>(&self, rng: &mut R) -> Result<(EK, SS), R::Error>
where
R: TryCryptoRng + ?Sized;
/// Encapsulate a fresh shared secret generated using the system's secure RNG.
#[cfg(feature = "getrandom")]
fn encapsulate(&self) -> (EK, SS) {
let Ok(ret) = self.encapsulate_with_rng(&mut SysRng.unwrap_err());
ret
}
}
pub trait Decapsulate {
/// Encapsulator which corresponds to this decapsulator.
type Encapsulator: Encapsulate<
EncapsulatedKey = Self::EncapsulatedKey,
SharedSecret = Self::SharedSecret
>;
/// Shared secret after being encrypted by this encapsulator
type EncapsulatedKey: TryKeyInit + KeyExport;
/// Shared secret value which results after the `EncapsulatedKey` has been decrypted.
type SharedSecret: AsRef<[u8]>;
/// Decapsulates the given encapsulated key
fn decapsulate(&self, encapsulated_key: &EK) -> SS;
/// Retrieve the encapsulator associated with this decapsulator.
fn encapsulator(&self) -> Self::Encapsulator;
}We could also consider a third trait that removes the duplicated associated types, perhaps (possibly Kem?)
Metadata
Metadata
Assignees
Labels
No labels