Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/curve25519-dalek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
run: cargo test --no-default-features --features alloc,precomputed-tables,zeroize,group-bits --target x86_64-unknown-linux-gnu

msrv:
name: Current MSRV is 1.60.0
name: Current MSRV is 1.85.0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -139,7 +139,7 @@ jobs:
- run: cargo update -Z minimal-versions
# Now check that `cargo build` works with respect to the oldest possible
# deps and the stated MSRV
- uses: dtolnay/rust-toolchain@1.60.0
- uses: dtolnay/rust-toolchain@1.85.0
- run: cargo build --no-default-features --features serde
# Also make sure the AVX2 build works
- run: cargo build --target x86_64-unknown-linux-gnu
4 changes: 2 additions & 2 deletions .github/workflows/ed25519-dalek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env:
jobs:

msrv:
name: Current MSRV is 1.81.0
name: Current MSRV is 1.85.0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -29,5 +29,5 @@ jobs:
- run: cargo update -Z minimal-versions
# Now check that `cargo build` works with respect to the oldest possible
# deps and the stated MSRV
- uses: dtolnay/rust-toolchain@1.81.0
- uses: dtolnay/rust-toolchain@1.85.0
- run: cargo build
2 changes: 1 addition & 1 deletion .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- name: no_std / no feat ${{ matrix.crate }}
run: cargo build -p ${{ matrix.crate }} --target thumbv7em-none-eabi --release --no-default-features
- name: no_std / cargo hack ${{ matrix.crate }}
run: cargo hack build -p ${{ matrix.crate }} --target thumbv7em-none-eabi --release --each-feature --exclude-features default,std,getrandom
run: cargo hack build -p ${{ matrix.crate }} --target thumbv7em-none-eabi --release --each-feature --exclude-features default,std,os_rng

clippy:
name: Check that clippy is happy
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/x25519-dalek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env:
jobs:

msrv:
name: Current MSRV is 1.60.0
name: Current MSRV is 1.85.0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -29,5 +29,7 @@ jobs:
- run: cargo update -Z minimal-versions
# Now check that `cargo build` works with respect to the oldest possible
# deps and the stated MSRV
- uses: dtolnay/rust-toolchain@1.60.0
- uses: dtolnay/rust-toolchain@1.85.0
- # zeroize_derive 1.3 will throw warnings on rust 1.85 which are rejected in CI.
run: cargo update -p zeroize_derive
- run: cargo build
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ resolver = "2"

[profile.dev]
opt-level = 2

20 changes: 10 additions & 10 deletions curve25519-dalek/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ name = "curve25519-dalek"
# - update README if required by semver
# - if README was updated, also update module documentation in src/lib.rs
version = "4.1.3"
edition = "2021"
rust-version = "1.60.0"
edition = "2024"
rust-version = "1.85.0"
authors = ["Isis Lovecruft <isis@patternsinthevoid.net>",
"Henry de Valence <hdevalence@hdevalence.ca>"]
readme = "README.md"
Expand All @@ -30,12 +30,12 @@ rustdoc-args = [
features = ["serde", "rand_core", "digest", "legacy_compatibility", "group-bits"]

[dev-dependencies]
sha2 = { version = "0.10", default-features = false }
sha2 = { version = "0.11.0-rc.0", default-features = false }
bincode = "1"
criterion = { version = "0.5", features = ["html_reports"] }
hex = "0.4.2"
rand = "0.8"
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
rand = "0.9"
rand_core = { version = "0.9", default-features = false, features = ["os_rng"] }

[build-dependencies]
rustc_version = "0.4.0"
Expand All @@ -47,11 +47,11 @@ required-features = ["alloc", "rand_core"]

[dependencies]
cfg-if = "1"
ff = { version = "0.13", default-features = false, optional = true }
group = { version = "0.13", default-features = false, optional = true }
rand_core = { version = "0.6.4", default-features = false, optional = true }
digest = { version = "0.10", default-features = false, optional = true }
subtle = { version = "2.6.0", default-features = false, features = ["const-generics"]}
ff = { version = "=0.14.0-pre.0", default-features = false, optional = true }
group = { version = "=0.14.0-pre.0", default-features = false, optional = true }
rand_core = { version = "0.9", default-features = false, optional = true }
digest = { version = "0.11.0-rc.0", default-features = false, optional = true }
subtle = { version = "2.6.0", default-features = false, features = ["const-generics"] }
serde = { version = "1.0", default-features = false, optional = true, features = ["derive"] }
zeroize = { version = "1", default-features = false, optional = true }

Expand Down
18 changes: 9 additions & 9 deletions curve25519-dalek/benches/dalek_benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![allow(non_snake_case)]

use rand::{rngs::OsRng, thread_rng};
use rand::{TryRngCore, rng, rngs::OsRng};

use criterion::{
criterion_main, measurement::Measurement, BatchSize, BenchmarkGroup, BenchmarkId, Criterion,
BatchSize, BenchmarkGroup, BenchmarkId, Criterion, criterion_main, measurement::Measurement,
};

use curve25519_dalek::constants;
Expand All @@ -29,7 +29,7 @@ mod edwards_benches {
BenchmarkId::new("Batch EdwardsPoint compression", batch_size),
&batch_size,
|b, &size| {
let mut rng = OsRng;
let mut rng = OsRng.unwrap_err();
let points: Vec<EdwardsPoint> =
(0..size).map(|_| EdwardsPoint::random(&mut rng)).collect();
b.iter(|| EdwardsPoint::compress_batch(&points));
Expand Down Expand Up @@ -62,7 +62,7 @@ mod edwards_benches {

fn vartime_double_base_scalar_mul<M: Measurement>(c: &mut BenchmarkGroup<M>) {
c.bench_function("Variable-time aA+bB, A variable, B fixed", |bench| {
let mut rng = thread_rng();
let mut rng = rng();
let A = EdwardsPoint::mul_base(&Scalar::random(&mut rng));
bench.iter_batched(
|| (Scalar::random(&mut rng), Scalar::random(&mut rng)),
Expand Down Expand Up @@ -96,12 +96,12 @@ mod multiscalar_benches {
use curve25519_dalek::traits::VartimePrecomputedMultiscalarMul;

fn construct_scalars(n: usize) -> Vec<Scalar> {
let mut rng = thread_rng();
let mut rng = rng();
(0..n).map(|_| Scalar::random(&mut rng)).collect()
}

fn construct_points(n: usize) -> Vec<EdwardsPoint> {
let mut rng = thread_rng();
let mut rng = rng();
(0..n)
.map(|_| EdwardsPoint::mul_base(&Scalar::random(&mut rng)))
.collect()
Expand Down Expand Up @@ -269,7 +269,7 @@ mod ristretto_benches {
|b, &&size| {
let mut rng = OsRng;
let points: Vec<RistrettoPoint> = (0..size)
.map(|_| RistrettoPoint::random(&mut rng))
.map(|_| RistrettoPoint::try_from_rng(&mut rng).unwrap())
.collect();
b.iter(|| RistrettoPoint::double_and_compress_batch(&points));
},
Expand Down Expand Up @@ -319,7 +319,7 @@ mod scalar_benches {
use super::*;

fn scalar_arith<M: Measurement>(c: &mut BenchmarkGroup<M>) {
let mut rng = thread_rng();
let mut rng = rng();

c.bench_function("Scalar inversion", |b| {
let s = Scalar::from(897987897u64).invert();
Expand Down Expand Up @@ -354,7 +354,7 @@ mod scalar_benches {
BenchmarkId::new("Batch scalar inversion", *batch_size),
&batch_size,
|b, &&size| {
let mut rng = OsRng;
let mut rng = OsRng.unwrap_err();
let scalars: Vec<Scalar> =
(0..size).map(|_| Scalar::random(&mut rng)).collect();
b.iter(|| {
Expand Down
4 changes: 3 additions & 1 deletion curve25519-dalek/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ fn main() {
}
}
Ok("unstable_avx512") if !nightly => {
panic!("Could not override curve25519_dalek_backend to unstable_avx512, as this is nightly only");
panic!(
"Could not override curve25519_dalek_backend to unstable_avx512, as this is nightly only"
);
}
// default between serial / simd (if potentially capable)
_ => match is_capable_simd(&target_arch, curve25519_dalek_bits) {
Expand Down
7 changes: 5 additions & 2 deletions curve25519-dalek/src/backend/serial/curve_models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,10 @@ impl Debug for AffineNielsPoint {

impl Debug for ProjectiveNielsPoint {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "ProjectiveNielsPoint{{\n\tY_plus_X: {:?},\n\tY_minus_X: {:?},\n\tZ: {:?},\n\tT2d: {:?}\n}}",
&self.Y_plus_X, &self.Y_minus_X, &self.Z, &self.T2d)
write!(
f,
"ProjectiveNielsPoint{{\n\tY_plus_X: {:?},\n\tY_minus_X: {:?},\n\tZ: {:?},\n\tT2d: {:?}\n}}",
&self.Y_plus_X, &self.Y_minus_X, &self.Z, &self.T2d
)
}
}
2 changes: 1 addition & 1 deletion curve25519-dalek/src/backend/vector/avx2/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use core::ops::{Add, Mul, Neg};

use crate::backend::serial::u64::field::FieldElement51;
use crate::backend::vector::avx2::constants::{
P_TIMES_16_HI, P_TIMES_16_LO, P_TIMES_2_HI, P_TIMES_2_LO,
P_TIMES_2_HI, P_TIMES_2_LO, P_TIMES_16_HI, P_TIMES_16_LO,
};

use curve25519_dalek_derive::unsafe_target_feature;
Expand Down
48 changes: 27 additions & 21 deletions curve25519-dalek/src/edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ use core::ops::{AddAssign, SubAssign};
use core::ops::{Mul, MulAssign};

#[cfg(feature = "digest")]
use digest::{generic_array::typenum::U64, Digest};
use digest::{Digest, array::typenum::U64};

#[cfg(feature = "group")]
use {
group::{cofactor::CofactorGroup, prime::PrimeGroup, GroupEncoding},
group::{GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup},
rand_core::TryRngCore,
subtle::CtOption,
};

Expand All @@ -127,7 +128,7 @@ use zeroize::Zeroize;
use crate::constants;

use crate::field::FieldElement;
use crate::scalar::{clamp_integer, Scalar};
use crate::scalar::{Scalar, clamp_integer};

use crate::montgomery::MontgomeryPoint;

Expand All @@ -138,8 +139,8 @@ use crate::backend::serial::curve_models::ProjectivePoint;

#[cfg(feature = "precomputed-tables")]
use crate::window::{
LookupTableRadix128, LookupTableRadix16, LookupTableRadix256, LookupTableRadix32,
LookupTableRadix64,
LookupTableRadix16, LookupTableRadix32, LookupTableRadix64, LookupTableRadix128,
LookupTableRadix256,
};

#[cfg(feature = "precomputed-tables")]
Expand Down Expand Up @@ -667,7 +668,7 @@ impl EdwardsPoint {
/// Uses rejection sampling, generating a random `CompressedEdwardsY` and then attempting point
/// decompression, rejecting invalid points.
#[cfg(any(test, feature = "rand_core"))]
pub fn random(mut rng: impl RngCore) -> Self {
pub fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self {
let mut repr = CompressedEdwardsY([0u8; 32]);
loop {
rng.fill_bytes(&mut repr.0);
Expand Down Expand Up @@ -1364,9 +1365,16 @@ impl Debug for EdwardsPoint {
impl group::Group for EdwardsPoint {
type Scalar = Scalar;

fn random(rng: impl RngCore) -> Self {
// Call the inherent `pub fn random` defined above
Self::random(rng)
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
let mut repr = CompressedEdwardsY([0u8; 32]);
loop {
rng.try_fill_bytes(&mut repr.0)?;
if let Some(p) = repr.decompress() {
if !IsIdentity::is_identity(&p) {
break Ok(p);
}
}
}
}

fn identity() -> Self {
Expand Down Expand Up @@ -1609,20 +1617,20 @@ impl Zeroize for SubgroupPoint {
impl group::Group for SubgroupPoint {
type Scalar = Scalar;

fn random(mut rng: impl RngCore) -> Self {
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
use group::ff::Field;

// This will almost never loop, but `Group::random` is documented as returning a
// non-identity element.
let s = loop {
let s: Scalar = Field::random(&mut rng);
let s: Scalar = Field::try_from_rng(rng)?;
if !s.is_zero_vartime() {
break s;
}
};

// This gives an element of the prime-order subgroup.
Self::generator() * s
Ok(Self::generator() * s)
}

fn identity() -> Self {
Expand Down Expand Up @@ -1688,9 +1696,7 @@ impl CofactorGroup for EdwardsPoint {
mod test {
use super::*;

// If `group` is set, then this is already imported in super
#[cfg(not(feature = "group"))]
use rand_core::RngCore;
use rand_core::TryRngCore;

#[cfg(feature = "alloc")]
use alloc::vec::Vec;
Expand Down Expand Up @@ -1985,7 +1991,7 @@ mod test {
#[cfg(feature = "precomputed-tables")]
let random_point = {
let mut b = [0u8; 32];
csprng.fill_bytes(&mut b);
csprng.try_fill_bytes(&mut b).unwrap();
EdwardsPoint::mul_base_clamped(b) + constants::EIGHT_TORSION[1]
};
// Make a basepoint table from the random point. We'll use this with mul_base_clamped
Expand All @@ -2011,7 +2017,7 @@ mod test {
for _ in 0..100 {
// This will be reduced mod l with probability l / 2^256 ≈ 6.25%
let mut a_bytes = [0u8; 32];
csprng.fill_bytes(&mut a_bytes);
csprng.try_fill_bytes(&mut a_bytes).unwrap();

assert_eq!(
EdwardsPoint::mul_base_clamped(a_bytes),
Expand Down Expand Up @@ -2096,7 +2102,7 @@ mod test {
#[cfg(feature = "alloc")]
#[test]
fn compress_batch() {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

// TODO(tarcieri): proptests?
// Make some points deterministically then randomly
Expand Down Expand Up @@ -2152,7 +2158,7 @@ mod test {
// A single iteration of a consistency check for MSM.
#[cfg(feature = "alloc")]
fn multiscalar_consistency_iter(n: usize) {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

// Construct random coefficients x0, ..., x_{n-1},
// followed by some extra hardcoded ones.
Expand Down Expand Up @@ -2215,7 +2221,7 @@ mod test {
#[test]
#[cfg(feature = "alloc")]
fn batch_to_montgomery() {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

let scalars = (0..128)
.map(|_| Scalar::random(&mut rng))
Expand All @@ -2240,7 +2246,7 @@ mod test {
#[test]
#[cfg(feature = "alloc")]
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

let static_scalars = (0..128)
.map(|_| Scalar::random(&mut rng))
Expand Down
2 changes: 1 addition & 1 deletion curve25519-dalek/src/edwards/affine.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{CompressedEdwardsY, EdwardsPoint};
use crate::traits::Identity;
use crate::{field::FieldElement, Scalar};
use crate::{Scalar, field::FieldElement};
use core::ops::Mul;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};

Expand Down
Loading