MCPcopy Create free account
hub / github.com/encrypted-spaces/prototype / Mkem

Interface Mkem

crypto/src/pke.rs:80–117  ·  view source on GitHub ↗

A multi-recipient key encapsulation mechanism (mKEM). This trait provides all the functions that are needed by the cryptographic system, and they can be put in the same implementation block, however the type [`KemKeyPair`] is most likely more appropriate for development. # Implementations Any key encapsulation mechanism is also a multi-recipient key-encapsulation mechanism. As such, there is a

Source from the content-addressed store, hash-verified

78/// Any key encapsulation mechanism is also a multi-recipient key-encapsulation mechanism.
79/// As such, there is a blanket implementation of this trait for any [`Kem`] to facilitate future adoptions.
80pub trait Mkem: Clone + Send + Sync + Default {
81 /// The name of the mKEM (for domain separation).
82 const NAME: &'static str;
83
84 /// The type of the public key to be used in the system.
85 type PublicKey: Clone + Send + Sync + Serialize + DeserializeOwned;
86 /// The ciphertexts to be decrypted by the user
87 type IndividualCiphertext: Clone + Send + Sync + Serialize + DeserializeOwned;
88 /// The (multi-recipient) ciphertext produced by the key-encapsulation function.
89 type Ciphertext: Clone + Send + Sync + Serialize + DeserializeOwned;
90 //// The secret key type.
91 type SecretKey: Clone + Serialize + DeserializeOwned;
92
93 /// The key generation function.
94 fn keygen<R: CryptoRng + RngCore>(&self, rng: &mut R) -> (Self::PublicKey, Self::SecretKey);
95
96 /// The key encapsulation function.
97 ///
98 /// # Determinism
99 ///
100 /// This function should produce deterministic outputs when the random number generator `rng` is a [`rand::SeedableRng`].
101 fn encaps<R: CryptoRng + RngCore>(
102 &self,
103 rng: &mut R,
104 pks: &[Self::PublicKey],
105 ) -> (Self::Ciphertext, KeyMaterial);
106
107 /// The ciphertext extraction function.
108 ///
109 /// Return the i-th individual ciphertext from a batch, or `None` if no such index is found.
110 fn get(&self, cts: &Self::Ciphertext, index: usize) -> Option<Self::IndividualCiphertext>;
111
112 /// The key decapsulation mechanism.
113 ///
114 /// Return the de-caps'd key material using the i-th secret key and the i-th ciphertext.
115 /// If decryption fails, [`None`][Option] is returned
116 fn decaps(&self, sk: &Self::SecretKey, ct: &Self::IndividualCiphertext) -> Option<KeyMaterial>;
117}
118
119impl<K: Kem> Mkem for K
120where

Callers

nothing calls this directly

Implementers 4

pke.rscrypto/src/pke.rs
xwing.rscrypto/src/pke/xwing.rs
ristretto255.rscrypto/src/pke/ristretto255.rs
xwing_ristretto255.rscrypto/src/pke/xwing_ristretto255.rs

Calls

no outgoing calls

Tested by

no test coverage detected