Skip to content

Commit 9a17f93

Browse files
authored
ml-kem+xwing: add KeyInit and KeySizeUser impls (#156)
...to the decapsulator types, which initialize from a seed
1 parent fe2c255 commit 9a17f93

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

Cargo.lock

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ debug = true
1212

1313
[patch.crates-io]
1414
ml-kem = { path = "./ml-kem" }
15+
16+
kem = { git = "https://github.com/RustCrypto/traits" }

ml-kem/src/kem.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::convert::Infallible;
22
use core::marker::PhantomData;
3-
use hybrid_array::typenum::U32;
3+
use hybrid_array::typenum::{U32, U64};
44
use rand_core::{CryptoRng, TryCryptoRng};
55
use subtle::{ConditionallySelectable, ConstantTimeEq};
66

@@ -98,6 +98,23 @@ where
9898
}
9999
}
100100

101+
impl<P> ::kem::KeySizeUser for DecapsulationKey<P>
102+
where
103+
P: KemParams,
104+
{
105+
type KeySize = U64;
106+
}
107+
108+
impl<P> ::kem::KeyInit for DecapsulationKey<P>
109+
where
110+
P: KemParams,
111+
{
112+
#[inline]
113+
fn new(seed: &Seed) -> Self {
114+
Self::from_seed(*seed)
115+
}
116+
}
117+
101118
impl<P> ::kem::Decapsulate<EncodedCiphertext<P>, SharedKey> for DecapsulationKey<P>
102119
where
103120
P: KemParams,

x-wing/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
pub use kem::{self, Decapsulate, Encapsulate};
3030

3131
use core::convert::Infallible;
32-
use ml_kem::array::ArrayN;
32+
use ml_kem::array::{ArrayN, typenum::consts::U32};
3333
use ml_kem::{B32, EncodedSizeUser, KemCore, MlKem768, MlKem768Params};
3434
use rand_core::{CryptoRng, TryCryptoRng};
3535
#[cfg(feature = "os_rng")]
@@ -145,6 +145,16 @@ impl Decapsulate<Ciphertext, SharedSecret> for DecapsulationKey {
145145
}
146146
}
147147

148+
impl ::kem::KeySizeUser for DecapsulationKey {
149+
type KeySize = U32;
150+
}
151+
152+
impl ::kem::KeyInit for DecapsulationKey {
153+
fn new(key: &ArrayN<u8, 32>) -> Self {
154+
Self { sk: key.0 }
155+
}
156+
}
157+
148158
impl DecapsulationKey {
149159
/// Generate a new `DecapsulationKey` using `OsRng`.
150160
#[cfg(feature = "os_rng")]

0 commit comments

Comments
 (0)