@@ -49,7 +49,9 @@ use hybrid_array::{
49
49
} ,
50
50
Array ,
51
51
} ;
52
- use rand:: { CryptoRng , RngCore } ;
52
+
53
+ #[ cfg( feature = "rand_core" ) ]
54
+ use rand_core:: CryptoRngCore ;
53
55
54
56
use crate :: algebra:: { AlgebraExt , Elem , NttMatrix , NttVector , Truncate , Vector } ;
55
57
use crate :: crypto:: H ;
@@ -270,11 +272,12 @@ impl<P: MlDsaParams> SigningKey<P> {
270
272
/// This method will return an opaque error if the context string is more than 255 bytes long,
271
273
/// or if it fails to get enough randomness.
272
274
// Algorithm 2 ML-DSA.Sign
275
+ #[ cfg( feature = "rand_core" ) ]
273
276
pub fn sign_randomized (
274
277
& self ,
275
278
M : & [ u8 ] ,
276
279
ctx : & [ u8 ] ,
277
- rng : & mut ( impl CryptoRng + RngCore ) ,
280
+ rng : & mut impl CryptoRngCore ,
278
281
) -> Result < Signature < P > , Error > {
279
282
if ctx. len ( ) > 255 {
280
283
return Err ( Error :: new ( ) ) ;
@@ -359,7 +362,7 @@ impl<P: MlDsaParams> signature::RandomizedSigner<Signature<P>> for SigningKey<P>
359
362
rng : & mut impl CryptoRngCore ,
360
363
msg : & [ u8 ] ,
361
364
) -> Result < Signature < P > , Error > {
362
- self . sign ( msg, & [ ] , rng)
365
+ self . sign_randomized ( msg, & [ ] , rng)
363
366
}
364
367
}
365
368
@@ -524,7 +527,8 @@ pub trait KeyGen: MlDsaParams {
524
527
type KeyPair : signature:: Keypair ;
525
528
526
529
/// Generate a signing key pair from the specified RNG
527
- fn key_gen ( rng : & mut ( impl CryptoRng + RngCore ) ) -> Self :: KeyPair ;
530
+ #[ cfg( feature = "rand_core" ) ]
531
+ fn key_gen ( rng : & mut impl CryptoRngCore ) -> Self :: KeyPair ;
528
532
529
533
/// Deterministically generate a signing key pair from the specified seed
530
534
// TODO(RLB): Only expose this based on a feature.
@@ -539,7 +543,8 @@ where
539
543
540
544
/// Generate a signing key pair from the specified RNG
541
545
// Algorithm 1 ML-DSA.KeyGen()
542
- fn key_gen ( rng : & mut ( impl CryptoRng + RngCore ) ) -> KeyPair < P > {
546
+ #[ cfg( feature = "rand_core" ) ]
547
+ fn key_gen ( rng : & mut impl CryptoRngCore ) -> KeyPair < P > {
543
548
let mut xi = B32 :: default ( ) ;
544
549
rng. fill_bytes ( & mut xi) ;
545
550
Self :: key_gen_internal ( & xi)
@@ -612,7 +617,12 @@ mod test {
612
617
where
613
618
P : MlDsaParams + PartialEq ,
614
619
{
620
+ #[ cfg( feature = "rand_core" ) ]
615
621
let kp = P :: key_gen ( & mut rand:: thread_rng ( ) ) ;
622
+
623
+ #[ cfg( not( feature = "rand_core" ) ) ]
624
+ let kp = P :: key_gen_internal ( & Default :: default ( ) ) ;
625
+
616
626
let sk = kp. signing_key ;
617
627
let vk = kp. verifying_key ;
618
628
@@ -643,8 +653,12 @@ mod test {
643
653
where
644
654
P : MlDsaParams ,
645
655
{
646
- let mut rng = rand:: thread_rng ( ) ;
647
- let kp = P :: key_gen ( & mut rng) ;
656
+ #[ cfg( feature = "rand_core" ) ]
657
+ let kp = P :: key_gen ( & mut rand:: thread_rng ( ) ) ;
658
+
659
+ #[ cfg( not( feature = "rand_core" ) ) ]
660
+ let kp = P :: key_gen_internal ( & Default :: default ( ) ) ;
661
+
648
662
let sk = kp. signing_key ;
649
663
let vk = kp. verifying_key ;
650
664
0 commit comments