Skip to content

Add Scalar::halve() #804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions curve25519-dalek/src/ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,35 @@ mod test {
}
}

#[test]
#[cfg(all(feature = "alloc", feature = "rand_core", feature = "group"))]
fn multiply_double_and_compress_1024_random_points() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should really get proptest set up, this is fine for now though.

cc @rozbb

use ff::Field;
use group::Group;
let mut rng = OsRng;

let mut scalars: Vec<Scalar> = (0..1024)
.map(|_| Scalar::try_from_rng(&mut rng).unwrap())
.collect();
scalars[500] = Scalar::ZERO;

let mut points: Vec<RistrettoPoint> = (0..1024)
.map(|_| RistrettoPoint::try_from_rng(&mut rng).unwrap())
.collect();
points[500] = <RistrettoPoint as Group>::identity();

let multiplied_points: Vec<RistrettoPoint> = scalars
.iter()
.zip(&points)
.map(|(scalar, point)| scalar.div_by_2() * point)
.collect();
let compressed = RistrettoPoint::double_and_compress_batch(&multiplied_points);

for ((s, P), P2_compressed) in scalars.iter().zip(points).zip(compressed) {
assert_eq!(P2_compressed, (s * P).compress());
}
}

#[test]
#[cfg(feature = "alloc")]
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
Expand Down