@@ -111,7 +111,7 @@ use {
111
111
subtle:: CtOption ,
112
112
} ;
113
113
114
- #[ cfg( feature = "rand_core" ) ]
114
+ #[ cfg( any ( test , feature = "rand_core" ) ) ]
115
115
use rand_core:: RngCore ;
116
116
117
117
use subtle:: Choice ;
@@ -643,7 +643,7 @@ impl EdwardsPoint {
643
643
///
644
644
/// Uses rejection sampling, generating a random `CompressedEdwardsY` and then attempting point
645
645
/// decompression, rejecting invalid points.
646
- #[ cfg( feature = "rand_core" ) ]
646
+ #[ cfg( any ( test , feature = "rand_core" ) ) ]
647
647
pub fn random ( mut rng : impl RngCore ) -> Self {
648
648
let mut repr = CompressedEdwardsY ( [ 0u8 ; 32 ] ) ;
649
649
loop {
@@ -2072,12 +2072,17 @@ mod test {
2072
2072
#[ cfg( feature = "alloc" ) ]
2073
2073
#[ test]
2074
2074
fn compress_batch ( ) {
2075
+ let mut rng = rand:: thread_rng ( ) ;
2076
+
2075
2077
// TODO(tarcieri): proptests?
2076
- let points = ( 1u64 ..16 )
2078
+ // Make some points deterministically then randomly
2079
+ let mut points = ( 1u64 ..16 )
2077
2080
. map ( |n| constants:: ED25519_BASEPOINT_POINT * Scalar :: from ( n) )
2078
2081
. collect :: < Vec < _ > > ( ) ;
2082
+ points. extend ( core:: iter:: repeat_with ( || EdwardsPoint :: random ( & mut rng) ) . take ( 100 ) ) ;
2079
2083
let compressed = EdwardsPoint :: compress_batch ( & points) ;
2080
2084
2085
+ // Check that the batch-compressed points match the individually compressed ones
2081
2086
for ( point, compressed) in points. iter ( ) . zip ( & compressed) {
2082
2087
assert_eq ! ( & point. compress( ) , compressed) ;
2083
2088
}
0 commit comments