Skip to content

Commit 14ff8c7

Browse files
committed
Test with Proptest
1 parent 25b424a commit 14ff8c7

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

curve25519-dalek/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ sha2 = { version = "0.11.0-rc.0", default-features = false }
4141
bincode = "1"
4242
criterion = { version = "0.5", features = ["html_reports"] }
4343
hex = "0.4.2"
44+
proptest = "1"
4445
rand = "0.9"
4546
rand_core = { version = "0.9", default-features = false, features = ["os_rng"] }
4647

curve25519-dalek/src/ristretto.rs

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,8 @@ impl Zeroize for RistrettoPoint {
13211321
mod test {
13221322
use super::*;
13231323
use crate::edwards::CompressedEdwardsY;
1324+
#[cfg(feature = "group")]
1325+
use proptest::prelude::*;
13241326

13251327
use rand_core::{OsRng, TryRngCore};
13261328

@@ -1867,32 +1869,36 @@ mod test {
18671869
}
18681870
}
18691871

1870-
#[test]
1871-
#[cfg(all(feature = "alloc", feature = "rand_core", feature = "group"))]
1872-
fn multiply_double_and_compress_1024_random_points() {
1873-
use ff::Field;
1874-
use group::Group;
1875-
let mut rng = OsRng;
1876-
1877-
let mut scalars: Vec<Scalar> = (0..1024)
1878-
.map(|_| Scalar::try_from_rng(&mut rng).unwrap())
1879-
.collect();
1880-
scalars[500] = Scalar::ZERO;
1881-
1882-
let mut points: Vec<RistrettoPoint> = (0..1024)
1883-
.map(|_| RistrettoPoint::try_from_rng(&mut rng).unwrap())
1884-
.collect();
1885-
points[500] = <RistrettoPoint as Group>::identity();
1886-
1887-
let multiplied_points: Vec<RistrettoPoint> = scalars
1888-
.iter()
1889-
.zip(&points)
1890-
.map(|(scalar, point)| scalar.div_by_2() * point)
1891-
.collect();
1892-
let compressed = RistrettoPoint::double_and_compress_batch(&multiplied_points);
1893-
1894-
for ((s, P), P2_compressed) in scalars.iter().zip(points).zip(compressed) {
1895-
assert_eq!(P2_compressed, (s * P).compress());
1872+
#[cfg(feature = "group")]
1873+
proptest! {
1874+
#[test]
1875+
fn multiply_double_and_compress_random_points(
1876+
p1 in any::<[u8; 64]>(),
1877+
p2 in any::<[u8; 64]>(),
1878+
s1 in any::<[u8; 32]>(),
1879+
s2 in any::<[u8; 32]>(),
1880+
) {
1881+
use group::Group;
1882+
1883+
let scalars = [
1884+
Scalar::from_bytes_mod_order(s1),
1885+
Scalar::ZERO,
1886+
Scalar::from_bytes_mod_order(s2),
1887+
];
1888+
1889+
let points = [
1890+
RistrettoPoint::from_uniform_bytes(&p1),
1891+
<RistrettoPoint as Group>::identity(),
1892+
RistrettoPoint::from_uniform_bytes(&p2),
1893+
];
1894+
1895+
let multiplied_points: [_; 3] =
1896+
core::array::from_fn(|i| scalars[i].div_by_2() * points[i]);
1897+
let compressed = RistrettoPoint::double_and_compress_batch(&multiplied_points);
1898+
1899+
for ((s, P), P2_compressed) in scalars.iter().zip(points).zip(compressed) {
1900+
prop_assert_eq!(P2_compressed, (s * P).compress());
1901+
}
18961902
}
18971903
}
18981904

0 commit comments

Comments
 (0)