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
| 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. |
| 80 | pub 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 | |
| 119 | impl<K: Kem> Mkem for K |
| 120 | where |
nothing calls this directly
no outgoing calls
no test coverage detected