|
21 | 21 | //! computers. |
22 | 22 | //! |
23 | 23 | //! ``` |
24 | | -//! # use ml_kem::*; |
25 | | -//! # use ::kem::{Decapsulate, Encapsulate}; |
26 | | -//! let mut rng = rand::rng(); |
| 24 | +//! use ml_kem::{ |
| 25 | +//! ml_kem_768::DecapsulationKey, |
| 26 | +//! kem::{Decapsulate, Encapsulate, KeyInit} |
| 27 | +//! }; |
27 | 28 | //! |
28 | | -//! // Generate a (decapsulation key, encapsulation key) pair |
29 | | -//! let (dk, ek) = MlKem768::generate(&mut rng); |
| 29 | +//! // Generate a decapsulation/encapsulation keypair |
| 30 | +//! let mut rng = rand::rng(); |
| 31 | +//! let seed = DecapsulationKey::generate_key_with_rng(&mut rng); |
| 32 | +//! let dk = DecapsulationKey::new(&seed); |
| 33 | +//! let ek = dk.encapsulator(); |
30 | 34 | //! |
31 | 35 | //! // Encapsulate a shared key to the holder of the decapsulation key, receive the shared |
32 | 36 | //! // secret `k_send` and the encapsulated form `ct`. |
@@ -81,50 +85,95 @@ pub use hybrid_array as array; |
81 | 85 | #[cfg(feature = "deterministic")] |
82 | 86 | pub use util::B32; |
83 | 87 |
|
| 88 | +pub use ml_kem_512::MlKem512Params; |
| 89 | +pub use ml_kem_768::MlKem768Params; |
| 90 | +pub use ml_kem_1024::MlKem1024Params; |
84 | 91 | pub use param::{ArraySize, ParameterSet}; |
85 | 92 | pub use traits::*; |
86 | 93 |
|
87 | 94 | /// ML-KEM seeds are decapsulation (private) keys, which are consistently 64-bytes across all |
88 | 95 | /// security levels, and are the preferred serialization for representing such keys. |
89 | 96 | pub type Seed = Array<u8, U64>; |
90 | 97 |
|
91 | | -/// `MlKem512` is the parameter set for security category 1, corresponding to key search on a block |
| 98 | +/// ML-KEM-512 is the parameter set for security category 1, corresponding to key search on a block |
92 | 99 | /// cipher with a 128-bit key. |
93 | | -#[derive(Default, Clone, Debug, PartialEq)] |
94 | | -pub struct MlKem512Params; |
95 | | - |
96 | | -impl ParameterSet for MlKem512Params { |
97 | | - type K = U2; |
98 | | - type Eta1 = U3; |
99 | | - type Eta2 = U2; |
100 | | - type Du = U10; |
101 | | - type Dv = U4; |
| 100 | +pub mod ml_kem_512 { |
| 101 | + use super::{Debug, ParameterSet, U2, U3, U4, U10, kem}; |
| 102 | + |
| 103 | + /// `MlKem512` is the parameter set for security category 1, corresponding to key search on a |
| 104 | + /// block cipher with a 128-bit key. |
| 105 | + #[derive(Default, Clone, Debug, PartialEq)] |
| 106 | + pub struct MlKem512Params; |
| 107 | + |
| 108 | + impl ParameterSet for MlKem512Params { |
| 109 | + type K = U2; |
| 110 | + type Eta1 = U3; |
| 111 | + type Eta2 = U2; |
| 112 | + type Du = U10; |
| 113 | + type Dv = U4; |
| 114 | + } |
| 115 | + |
| 116 | + /// An ML-KEM-512 `DecapsulationKey` which provides the ability to generate a new key pair, and |
| 117 | + /// decapsulate an encapsulated shared key. |
| 118 | + pub type DecapsulationKey = kem::DecapsulationKey<MlKem512Params>; |
| 119 | + |
| 120 | + /// An ML-KEM-512 `EncapsulationKey` provides the ability to encapsulate a shared key so that it |
| 121 | + /// can only be decapsulated by the holder of the corresponding decapsulation key. |
| 122 | + pub type EncapsulationKey = kem::EncapsulationKey<MlKem512Params>; |
102 | 123 | } |
103 | 124 |
|
104 | | -/// `MlKem768` is the parameter set for security category 3, corresponding to key search on a block |
| 125 | +/// ML-KEM-768 is the parameter set for security category 3, corresponding to key search on a block |
105 | 126 | /// cipher with a 192-bit key. |
106 | | -#[derive(Default, Clone, Debug, PartialEq)] |
107 | | -pub struct MlKem768Params; |
108 | | - |
109 | | -impl ParameterSet for MlKem768Params { |
110 | | - type K = U3; |
111 | | - type Eta1 = U2; |
112 | | - type Eta2 = U2; |
113 | | - type Du = U10; |
114 | | - type Dv = U4; |
| 127 | +pub mod ml_kem_768 { |
| 128 | + use super::{Debug, ParameterSet, U2, U3, U4, U10, kem}; |
| 129 | + |
| 130 | + /// `MlKem768` is the parameter set for security category 3, corresponding to key search on a |
| 131 | + /// block cipher with a 192-bit key. |
| 132 | + #[derive(Default, Clone, Debug, PartialEq)] |
| 133 | + pub struct MlKem768Params; |
| 134 | + |
| 135 | + impl ParameterSet for MlKem768Params { |
| 136 | + type K = U3; |
| 137 | + type Eta1 = U2; |
| 138 | + type Eta2 = U2; |
| 139 | + type Du = U10; |
| 140 | + type Dv = U4; |
| 141 | + } |
| 142 | + |
| 143 | + /// An ML-KEM-768 `DecapsulationKey` which provides the ability to generate a new key pair, and |
| 144 | + /// decapsulate an encapsulated shared key. |
| 145 | + pub type DecapsulationKey = kem::DecapsulationKey<MlKem768Params>; |
| 146 | + |
| 147 | + /// An ML-KEM-768 `EncapsulationKey` provides the ability to encapsulate a shared key so that it |
| 148 | + /// can only be decapsulated by the holder of the corresponding decapsulation key. |
| 149 | + pub type EncapsulationKey = kem::EncapsulationKey<MlKem768Params>; |
115 | 150 | } |
116 | 151 |
|
117 | | -/// `MlKem1024` is the parameter set for security category 5, corresponding to key search on a block |
| 152 | +/// ML-KEM-1024 is the parameter set for security category 5, corresponding to key search on a block |
118 | 153 | /// cipher with a 256-bit key. |
119 | | -#[derive(Default, Clone, Debug, PartialEq)] |
120 | | -pub struct MlKem1024Params; |
121 | | - |
122 | | -impl ParameterSet for MlKem1024Params { |
123 | | - type K = U4; |
124 | | - type Eta1 = U2; |
125 | | - type Eta2 = U2; |
126 | | - type Du = U11; |
127 | | - type Dv = U5; |
| 154 | +pub mod ml_kem_1024 { |
| 155 | + use super::{Debug, ParameterSet, U2, U4, U5, U11, kem}; |
| 156 | + |
| 157 | + /// `MlKem1024` is the parameter set for security category 5, corresponding to key search on a |
| 158 | + /// block cipher with a 256-bit key. |
| 159 | + #[derive(Default, Clone, Debug, PartialEq)] |
| 160 | + pub struct MlKem1024Params; |
| 161 | + |
| 162 | + impl ParameterSet for MlKem1024Params { |
| 163 | + type K = U4; |
| 164 | + type Eta1 = U2; |
| 165 | + type Eta2 = U2; |
| 166 | + type Du = U11; |
| 167 | + type Dv = U5; |
| 168 | + } |
| 169 | + |
| 170 | + /// An ML-KEM-1024 `DecapsulationKey` which provides the ability to generate a new key pair, and |
| 171 | + /// decapsulate an encapsulated shared key. |
| 172 | + pub type DecapsulationKey = kem::DecapsulationKey<MlKem1024Params>; |
| 173 | + |
| 174 | + /// An ML-KEM-1024 `EncapsulationKey` provides the ability to encapsulate a shared key so that |
| 175 | + /// it can only be decapsulated by the holder of the corresponding decapsulation key. |
| 176 | + pub type EncapsulationKey = kem::EncapsulationKey<MlKem1024Params>; |
128 | 177 | } |
129 | 178 |
|
130 | 179 | /// A shared key produced by the KEM `K` |
|
0 commit comments