Skip to content

Commit 25b424a

Browse files
authored
Test multiply by half scalar, double and compress (#804)
1 parent 58c8f39 commit 25b424a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

curve25519-dalek/src/ristretto.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,35 @@ mod test {
18671867
}
18681868
}
18691869

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());
1896+
}
1897+
}
1898+
18701899
#[test]
18711900
#[cfg(feature = "alloc")]
18721901
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {

0 commit comments

Comments
 (0)