Skip to content

Commit 9202a0b

Browse files
committed
Added random points to compress_batch tests
1 parent 8602ad2 commit 9202a0b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

curve25519-dalek/src/edwards.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ use {
111111
subtle::CtOption,
112112
};
113113

114-
#[cfg(feature = "rand_core")]
114+
#[cfg(any(test, feature = "rand_core"))]
115115
use rand_core::RngCore;
116116

117117
use subtle::Choice;
@@ -643,7 +643,7 @@ impl EdwardsPoint {
643643
///
644644
/// Uses rejection sampling, generating a random `CompressedEdwardsY` and then attempting point
645645
/// decompression, rejecting invalid points.
646-
#[cfg(feature = "rand_core")]
646+
#[cfg(any(test, feature = "rand_core"))]
647647
pub fn random(mut rng: impl RngCore) -> Self {
648648
let mut repr = CompressedEdwardsY([0u8; 32]);
649649
loop {
@@ -2072,12 +2072,17 @@ mod test {
20722072
#[cfg(feature = "alloc")]
20732073
#[test]
20742074
fn compress_batch() {
2075+
let mut rng = rand::thread_rng();
2076+
20752077
// TODO(tarcieri): proptests?
2076-
let points = (1u64..16)
2078+
// Make some points deterministically then randomly
2079+
let mut points = (1u64..16)
20772080
.map(|n| constants::ED25519_BASEPOINT_POINT * Scalar::from(n))
20782081
.collect::<Vec<_>>();
2082+
points.extend(core::iter::repeat_with(|| EdwardsPoint::random(&mut rng)).take(100));
20792083
let compressed = EdwardsPoint::compress_batch(&points);
20802084

2085+
// Check that the batch-compressed points match the individually compressed ones
20812086
for (point, compressed) in points.iter().zip(&compressed) {
20822087
assert_eq!(&point.compress(), compressed);
20832088
}

0 commit comments

Comments
 (0)