Skip to content

Commit e1ededa

Browse files
authored
lms,ml-dsa: relax Sized requirement on the rng (#918)
1 parent 3d5016a commit e1ededa

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

lms/src/lms/private.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::types::{Identifier, Typecode};
77

88
use digest::{Digest, Output, OutputSizeUser};
99
use hybrid_array::{Array, ArraySize};
10-
use rand::Rng;
1110
use rand_core::{CryptoRng, TryCryptoRng};
1211
use signature::{Error, RandomizedSignerMut};
1312

@@ -32,7 +31,7 @@ pub struct SigningKey<Mode: LmsMode> {
3231
impl<Mode: LmsMode> SigningKey<Mode> {
3332
/// Creates a new private key with a random identifier using
3433
/// algorithm 5 from <https://datatracker.ietf.org/doc/html/rfc8554#section-5.2>
35-
pub fn new(mut rng: impl Rng + CryptoRng) -> Self {
34+
pub fn new<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
3635
let mut id = Identifier::default();
3736
rng.fill_bytes(id.as_mut());
3837

lms/src/lms/public.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ mod tests {
258258
<Mode::Hasher as OutputSizeUser>::OutputSize: Add<U24>,
259259
Sum<<Mode::Hasher as OutputSizeUser>::OutputSize, U24>: ArraySize,
260260
{
261-
let rng = rand::rng();
262-
let lms_priv = SigningKey::<Mode>::new(rng);
261+
let mut rng = rand::rng();
262+
let lms_priv = SigningKey::<Mode>::new(&mut rng);
263263
let lms_pub = lms_priv.public();
264264
let lms_pub_serialized: Array<u8, Sum<<Mode::Hasher as OutputSizeUser>::OutputSize, U24>> =
265265
lms_pub.clone().into();

ml-dsa/benches/ml_dsa.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use criterion::{Criterion, criterion_group, criterion_main};
22
use hybrid_array::{Array, ArraySize};
33
use ml_dsa::{B32, KeyGen, MlDsa65, Signature, SigningKey, VerifyingKey};
4-
use rand::{CryptoRng, RngCore};
4+
use rand::CryptoRng;
55

6-
pub fn rand<L: ArraySize>(rng: &mut (impl RngCore + CryptoRng)) -> Array<u8, L> {
6+
pub fn rand<L: ArraySize, R: CryptoRng + ?Sized>(rng: &mut R) -> Array<u8, L> {
77
let mut val = Array::<u8, L>::default();
88
rng.fill_bytes(&mut val);
99
val

ml-dsa/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ pub trait KeyGen: MlDsaParams {
780780

781781
/// Generate a signing key pair from the specified RNG
782782
#[cfg(feature = "rand_core")]
783-
fn key_gen<R: CryptoRng>(rng: &mut R) -> Self::KeyPair;
783+
fn key_gen<R: CryptoRng + ?Sized>(rng: &mut R) -> Self::KeyPair;
784784

785785
/// Deterministically generate a signing key pair from the specified seed
786786
// TODO(RLB): Only expose this based on a feature.
@@ -796,7 +796,7 @@ where
796796
/// Generate a signing key pair from the specified RNG
797797
// Algorithm 1 ML-DSA.KeyGen()
798798
#[cfg(feature = "rand_core")]
799-
fn key_gen<R: CryptoRng>(rng: &mut R) -> KeyPair<P> {
799+
fn key_gen<R: CryptoRng + ?Sized>(rng: &mut R) -> KeyPair<P> {
800800
let mut xi = B32::default();
801801
rng.fill_bytes(&mut xi);
802802
Self::key_gen_internal(&xi)

0 commit comments

Comments
 (0)