Skip to content
Merged
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
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,os_rng
run: cargo hack build -p ${{ matrix.crate }} --target thumbv7em-none-eabi --release --each-feature --exclude-features default,std,getrandom

clippy:
name: Check that clippy is happy
Expand Down
13 changes: 6 additions & 7 deletions curve25519-dalek/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ features = [
]

[dev-dependencies]
sha2 = { version = "0.11.0-rc.2", default-features = false }
sha2 = { version = "0.11.0-rc.3", default-features = false }
bincode = "1"
criterion = { version = "0.5", features = ["html_reports"] }
hex = "0.4.2"
proptest = "1"
rand = "0.9"
rand_core = { version = "0.9", default-features = false, features = ["os_rng"] }
rand = "0.10.0-rc.5"

[build-dependencies]
rustc_version = "0.4.0"
Expand All @@ -55,10 +54,10 @@ required-features = ["alloc", "rand_core"]

[dependencies]
cfg-if = "1"
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.1", default-features = false, optional = true, features = [
ff = { version = "=0.14.0-pre.0", package = "rustcrypto-ff", default-features = false, optional = true }
group = { version = "=0.14.0-pre.0", package = "rustcrypto-group", default-features = false, optional = true }
rand_core = { version = "0.10.0-rc-2", default-features = false, optional = true }
digest = { version = "0.11.0-rc.4", default-features = false, optional = true, features = [
"block-api",
] }
subtle = { version = "2.6.0", default-features = false, features = [
Expand Down
24 changes: 12 additions & 12 deletions curve25519-dalek/src/edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ use {
subtle::CtOption,
};

#[cfg(any(test, feature = "rand_core"))]
#[cfg(feature = "rand_core")]
use rand_core::RngCore;

use subtle::Choice;
Expand Down Expand Up @@ -751,7 +751,7 @@ impl EdwardsPoint {
///
/// Uses rejection sampling, generating a random `CompressedEdwardsY` and then attempting point
/// decompression, rejecting invalid points.
#[cfg(any(test, feature = "rand_core"))]
#[cfg(feature = "rand_core")]
pub fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self {
let mut repr = CompressedEdwardsY([0u8; 32]);
loop {
Expand Down Expand Up @@ -1779,7 +1779,7 @@ impl CofactorGroup for EdwardsPoint {
mod test {
use super::*;

use rand_core::TryRngCore;
use rand::TryRngCore;

#[cfg(feature = "alloc")]
use alloc::vec::Vec;
Expand Down Expand Up @@ -2068,7 +2068,7 @@ mod test {
/// Check that mul_base_clamped and mul_clamped agree
#[test]
fn mul_base_clamped() {
let mut csprng = rand_core::OsRng;
let mut csprng = rand::rngs::OsRng;

// Make a random curve point in the curve. Give it torsion to make things interesting.
#[cfg(feature = "precomputed-tables")]
Expand Down Expand Up @@ -2182,7 +2182,7 @@ mod test {
}
}

#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
#[test]
fn compress_batch() {
let mut rng = rand::rng();
Expand Down Expand Up @@ -2239,7 +2239,7 @@ mod test {
}

// A single iteration of a consistency check for MSM.
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn multiscalar_consistency_iter(n: usize) {
let mut rng = rand::rng();

Expand All @@ -2266,7 +2266,7 @@ mod test {
// parameters.

#[test]
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn multiscalar_consistency_n_100() {
let iters = 50;
for _ in 0..iters {
Expand All @@ -2275,7 +2275,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn multiscalar_consistency_n_250() {
let iters = 50;
for _ in 0..iters {
Expand All @@ -2284,7 +2284,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn multiscalar_consistency_n_500() {
let iters = 50;
for _ in 0..iters {
Expand All @@ -2293,7 +2293,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn multiscalar_consistency_n_1000() {
let iters = 50;
for _ in 0..iters {
Expand All @@ -2302,7 +2302,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn batch_to_montgomery() {
let mut rng = rand::rng();

Expand All @@ -2327,7 +2327,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
let mut rng = rand::rng();

Expand Down
15 changes: 10 additions & 5 deletions curve25519-dalek/src/montgomery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ mod test {
use super::*;
use crate::constants;

use rand_core::{CryptoRng, RngCore, TryRngCore};
#[cfg(feature = "rand_core")]
use rand::CryptoRng;
use rand::{RngCore, TryRngCore};

#[test]
fn identity_in_different_coordinates() {
Expand Down Expand Up @@ -599,6 +601,7 @@ mod test {
}

/// Returns a random point on the prime-order subgroup
#[cfg(feature = "rand_core")]
fn rand_prime_order_point<R: CryptoRng + ?Sized>(rng: &mut R) -> EdwardsPoint {
let s: Scalar = Scalar::random(rng);
EdwardsPoint::mul_base(&s)
Expand All @@ -616,9 +619,10 @@ mod test {
})
}

#[cfg(feature = "rand_core")]
#[test]
fn montgomery_ladder_matches_edwards_scalarmult() {
let mut csprng = rand_core::OsRng.unwrap_err();
let mut csprng = rand::rngs::OsRng.unwrap_err();

for _ in 0..100 {
let p_edwards = rand_prime_order_point(&mut csprng);
Expand All @@ -634,9 +638,10 @@ mod test {

// Tests that, on the prime-order subgroup, MontgomeryPoint::mul_bits_be is the same as
// multiplying by the Scalar representation of the same bits
#[cfg(feature = "rand_core")]
#[test]
fn montgomery_mul_bits_be() {
let mut csprng = rand_core::OsRng.unwrap_err();
let mut csprng = rand::rngs::OsRng.unwrap_err();

for _ in 0..100 {
// Make a random prime-order point P
Expand All @@ -661,7 +666,7 @@ mod test {
// integers b₁, b₂ and random (curve or twist) point P.
#[test]
fn montgomery_mul_bits_be_twist() {
let mut csprng = rand_core::OsRng.unwrap_err();
let mut csprng = rand::rngs::OsRng.unwrap_err();

for _ in 0..100 {
// Make a random point P on the curve or its twist
Expand Down Expand Up @@ -694,7 +699,7 @@ mod test {
/// Check that mul_base_clamped and mul_clamped agree
#[test]
fn mul_base_clamped() {
let mut csprng = rand_core::OsRng;
let mut csprng = rand::rngs::OsRng;

// Test agreement on a large integer. Even after clamping, this is not reduced mod l.
let a_bytes = [0xff; 32];
Expand Down
24 changes: 13 additions & 11 deletions curve25519-dalek/src/ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ use {
subtle::CtOption,
};

#[cfg(any(test, feature = "rand_core"))]
#[cfg(feature = "rand_core")]
use {
core::convert::Infallible,
rand_core::{CryptoRng, TryCryptoRng},
Expand Down Expand Up @@ -543,7 +543,7 @@ impl RistrettoPoint {
#[cfg_attr(feature = "rand_core", doc = "```")]
#[cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
/// # use curve25519_dalek::ristretto::RistrettoPoint;
/// use rand_core::{OsRng, TryRngCore};
/// use rand::{rngs::OsRng, TryRngCore};
///
/// # // Need fn main() here in comment so the doctest compiles
/// # // See https://doc.rust-lang.org/book/documentation.html#documentation-as-tests
Expand Down Expand Up @@ -656,7 +656,6 @@ impl RistrettoPoint {
]
}

#[cfg(any(test, feature = "rand_core"))]
/// Return a `RistrettoPoint` chosen uniformly at random using a user-provided RNG.
///
/// # Inputs
Expand All @@ -673,13 +672,13 @@ impl RistrettoPoint {
/// discrete log of the output point with respect to any other
/// point should be unknown. The map is applied twice and the
/// results are added, to ensure a uniform distribution.
#[cfg(feature = "rand_core")]
pub fn random<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
Self::try_from_rng(rng)
.map_err(|_: Infallible| {})
.expect("[bug] unfallible rng failed")
}

#[cfg(any(test, feature = "rand_core"))]
/// Return a `RistrettoPoint` chosen uniformly at random using a user-provided RNG.
///
/// # Inputs
Expand All @@ -696,6 +695,7 @@ impl RistrettoPoint {
/// discrete log of the output point with respect to any other
/// point should be unknown. The map is applied twice and the
/// results are added, to ensure a uniform distribution.
#[cfg(feature = "rand_core")]
pub fn try_from_rng<R: TryCryptoRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
let mut uniform_bytes = [0u8; 64];
rng.try_fill_bytes(&mut uniform_bytes)?;
Expand Down Expand Up @@ -1277,8 +1277,8 @@ mod test {
use crate::edwards::CompressedEdwardsY;
#[cfg(feature = "group")]
use proptest::prelude::*;

use rand_core::{OsRng, TryRngCore};
#[cfg(feature = "rand_core")]
use rand::{TryRngCore, rngs::OsRng};

#[test]
#[cfg(feature = "serde")]
Expand Down Expand Up @@ -1469,6 +1469,7 @@ mod test {
}
}

#[cfg(feature = "rand_core")]
#[test]
fn four_torsion_random() {
let mut rng = OsRng.unwrap_err();
Expand All @@ -1479,6 +1480,7 @@ mod test {
}
}

#[cfg(feature = "rand_core")]
#[test]
fn random_roundtrip() {
let mut rng = OsRng.unwrap_err();
Expand Down Expand Up @@ -1542,7 +1544,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
let mut rng = rand::rng();

Expand Down Expand Up @@ -1593,7 +1595,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn partial_precomputed_mixed_multiscalar_empty() {
let mut rng = rand::rng();

Expand Down Expand Up @@ -1636,7 +1638,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn partial_precomputed_mixed_multiscalar() {
let mut rng = rand::rng();

Expand Down Expand Up @@ -1681,7 +1683,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn partial_precomputed_multiscalar() {
let mut rng = rand::rng();

Expand Down Expand Up @@ -1710,7 +1712,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", feature = "rand_core"))]
fn partial_precomputed_multiscalar_empty() {
let mut rng = rand::rng();

Expand Down
10 changes: 6 additions & 4 deletions curve25519-dalek/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ use group::ff::{FieldBits, PrimeFieldBits};
#[cfg(feature = "group")]
use rand_core::TryRngCore;

#[cfg(any(test, feature = "rand_core"))]
#[cfg(feature = "rand_core")]
use rand_core::CryptoRng;

#[cfg(feature = "digest")]
Expand Down Expand Up @@ -567,7 +567,6 @@ impl Scalar {
],
};

#[cfg(any(test, feature = "rand_core"))]
/// Return a `Scalar` chosen uniformly at random using a user-provided RNG.
///
/// # Inputs
Expand All @@ -584,11 +583,12 @@ impl Scalar {
/// # fn main() {
/// use curve25519_dalek::scalar::Scalar;
///
/// use rand_core::{OsRng, TryRngCore};
/// use rand::{rngs::OsRng, TryRngCore};
///
/// let mut csprng = OsRng.unwrap_err();
/// let a: Scalar = Scalar::random(&mut csprng);
/// # }
#[cfg(feature = "rand_core")]
pub fn random<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
let mut scalar_bytes = [0u8; 64];
rng.fill_bytes(&mut scalar_bytes);
Expand Down Expand Up @@ -1430,7 +1430,7 @@ pub const fn clamp_integer(mut bytes: [u8; 32]) -> [u8; 32] {
#[cfg(test)]
pub(crate) mod test {
use super::*;
use rand_core::RngCore;
use rand::RngCore;

#[cfg(feature = "alloc")]
use alloc::vec::Vec;
Expand Down Expand Up @@ -1570,6 +1570,7 @@ pub(crate) mod test {
}
}

#[cfg(feature = "rand_core")]
fn non_adjacent_form_iter(w: usize, x: &Scalar) {
let naf = x.non_adjacent_form(w);

Expand All @@ -1588,6 +1589,7 @@ pub(crate) mod test {
assert_eq!(*x, y);
}

#[cfg(feature = "rand_core")]
#[test]
fn non_adjacent_form_random() {
let mut rng = rand::rng();
Expand Down
Loading