Bump rand_core to v0.10.0-rc-6 (#873)

This also rips out `rand`: it's just acting as a facade for what we're
using that complicates these sorts of upgrades.
This commit is contained in:
Tony Arcieri 2026-01-24 17:29:05 -07:00 committed by GitHub
parent 56a6bc07b8
commit b7531ca318
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 157 additions and 155 deletions

View file

@ -30,12 +30,12 @@ rustdoc-args = [
all-features = true all-features = true
[dev-dependencies] [dev-dependencies]
sha2 = { version = "0.11.0-rc.3", default-features = false }
bincode = "1" bincode = "1"
criterion = { version = "0.5", features = ["html_reports"] } criterion = { version = "0.5", features = ["html_reports"] }
getrandom = { version = "0.4.0-rc.1", features = ["sys_rng"] }
hex = "0.4.2" hex = "0.4.2"
proptest = "1" proptest = "1"
rand = "0.10.0-rc.7" sha2 = { version = "0.11.0-rc.4", default-features = false }
[build-dependencies] [build-dependencies]
rustc_version = "0.4.0" rustc_version = "0.4.0"
@ -47,10 +47,10 @@ required-features = ["alloc", "rand_core"]
[dependencies] [dependencies]
cfg-if = "1" cfg-if = "1"
ff = { version = "=0.14.0-pre.0", package = "rustcrypto-ff", default-features = false, optional = true } ff = { version = "=0.14.0-pre.1", package = "rustcrypto-ff", default-features = false, optional = true }
group = { version = "=0.14.0-pre.0", package = "rustcrypto-group", default-features = false, optional = true } group = { version = "=0.14.0-pre.1", package = "rustcrypto-group", default-features = false, optional = true }
rand_core = { version = "0.10.0-rc-5", default-features = false, optional = true } rand_core = { version = "0.10.0-rc-6", default-features = false, optional = true }
digest = { version = "0.11.0-rc.4", default-features = false, optional = true, features = [ digest = { version = "0.11.0-rc.8", default-features = false, optional = true, features = [
"block-api", "block-api",
] } ] }
subtle = { version = "2.6.0", default-features = false, features = [ subtle = { version = "2.6.0", default-features = false, features = [

View file

@ -1,6 +1,7 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
use rand::{RngCore, TryRngCore, rng, rngs::SysRng}; use getrandom::SysRng;
use rand_core::{Rng, UnwrapErr};
use criterion::{ use criterion::{
BatchSize, BenchmarkGroup, BenchmarkId, Criterion, criterion_main, measurement::Measurement, BatchSize, BenchmarkGroup, BenchmarkId, Criterion, criterion_main, measurement::Measurement,
@ -31,7 +32,7 @@ mod edwards_benches {
BenchmarkId::new("Batch EdwardsPoint compression", batch_size), BenchmarkId::new("Batch EdwardsPoint compression", batch_size),
&batch_size, &batch_size,
|b, &size| { |b, &size| {
let mut rng = SysRng.unwrap_err(); let mut rng = UnwrapErr(SysRng);
let points: Vec<EdwardsPoint> = let points: Vec<EdwardsPoint> =
(0..size).map(|_| EdwardsPoint::random(&mut rng)).collect(); (0..size).map(|_| EdwardsPoint::random(&mut rng)).collect();
b.iter(|| EdwardsPoint::compress_batch_alloc(&points)); b.iter(|| EdwardsPoint::compress_batch_alloc(&points));
@ -64,7 +65,7 @@ mod edwards_benches {
fn vartime_double_base_scalar_mul<M: Measurement>(c: &mut BenchmarkGroup<M>) { fn vartime_double_base_scalar_mul<M: Measurement>(c: &mut BenchmarkGroup<M>) {
c.bench_function("Variable-time aA+bB, A variable, B fixed", |bench| { c.bench_function("Variable-time aA+bB, A variable, B fixed", |bench| {
let mut rng = rng(); let mut rng = UnwrapErr(SysRng);
let A = EdwardsPoint::mul_base(&Scalar::random(&mut rng)); let A = EdwardsPoint::mul_base(&Scalar::random(&mut rng));
bench.iter_batched( bench.iter_batched(
|| (Scalar::random(&mut rng), Scalar::random(&mut rng)), || (Scalar::random(&mut rng), Scalar::random(&mut rng)),
@ -76,7 +77,7 @@ mod edwards_benches {
#[cfg(feature = "digest")] #[cfg(feature = "digest")]
fn encode_to_curve<M: Measurement>(c: &mut BenchmarkGroup<M>) { fn encode_to_curve<M: Measurement>(c: &mut BenchmarkGroup<M>) {
let mut rng = rng(); let mut rng = UnwrapErr(SysRng);
let mut msg = [0u8; 32]; let mut msg = [0u8; 32];
let mut domain_sep = [0u8; 32]; let mut domain_sep = [0u8; 32];
@ -91,7 +92,7 @@ mod edwards_benches {
#[cfg(feature = "digest")] #[cfg(feature = "digest")]
fn hash_to_curve<M: Measurement>(c: &mut BenchmarkGroup<M>) { fn hash_to_curve<M: Measurement>(c: &mut BenchmarkGroup<M>) {
let mut rng = rng(); let mut rng = UnwrapErr(SysRng);
let mut msg = [0u8; 32]; let mut msg = [0u8; 32];
let mut domain_sep = [0u8; 32]; let mut domain_sep = [0u8; 32];
@ -130,12 +131,12 @@ mod multiscalar_benches {
use curve25519_dalek::traits::VartimePrecomputedMultiscalarMul; use curve25519_dalek::traits::VartimePrecomputedMultiscalarMul;
fn construct_scalars(n: usize) -> Vec<Scalar> { fn construct_scalars(n: usize) -> Vec<Scalar> {
let mut rng = rng(); let mut rng = UnwrapErr(SysRng);
(0..n).map(|_| Scalar::random(&mut rng)).collect() (0..n).map(|_| Scalar::random(&mut rng)).collect()
} }
fn construct_points(n: usize) -> Vec<EdwardsPoint> { fn construct_points(n: usize) -> Vec<EdwardsPoint> {
let mut rng = rng(); let mut rng = UnwrapErr(SysRng);
(0..n) (0..n)
.map(|_| EdwardsPoint::mul_base(&Scalar::random(&mut rng))) .map(|_| EdwardsPoint::mul_base(&Scalar::random(&mut rng)))
.collect() .collect()
@ -353,7 +354,7 @@ mod scalar_benches {
use super::*; use super::*;
fn scalar_arith<M: Measurement>(c: &mut BenchmarkGroup<M>) { fn scalar_arith<M: Measurement>(c: &mut BenchmarkGroup<M>) {
let mut rng = rng(); let mut rng = UnwrapErr(SysRng);
c.bench_function("Scalar inversion", |b| { c.bench_function("Scalar inversion", |b| {
let s = Scalar::from(897987897u64).invert(); let s = Scalar::from(897987897u64).invert();
@ -388,7 +389,7 @@ mod scalar_benches {
BenchmarkId::new("Batch scalar inversion", *batch_size), BenchmarkId::new("Batch scalar inversion", *batch_size),
&batch_size, &batch_size,
|b, &&size| { |b, &&size| {
let mut rng = SysRng.unwrap_err(); let mut rng = UnwrapErr(SysRng);
let scalars: Vec<Scalar> = let scalars: Vec<Scalar> =
(0..size).map(|_| Scalar::random(&mut rng)).collect(); (0..size).map(|_| Scalar::random(&mut rng)).collect();
b.iter(|| { b.iter(|| {

View file

@ -113,12 +113,12 @@ use digest::{
#[cfg(feature = "group")] #[cfg(feature = "group")]
use { use {
group::{GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup}, group::{GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup},
rand_core::TryRngCore, rand_core::TryRng,
subtle::CtOption, subtle::CtOption,
}; };
#[cfg(feature = "rand_core")] #[cfg(feature = "rand_core")]
use rand_core::RngCore; use rand_core::Rng;
use subtle::Choice; use subtle::Choice;
use subtle::ConditionallyNegatable; use subtle::ConditionallyNegatable;
@ -753,7 +753,7 @@ impl EdwardsPoint {
/// ///
/// # Inputs /// # Inputs
/// ///
/// * `rng`: any RNG which implements `RngCore` /// * `rng`: any RNG which implements `Rng`
/// ///
/// # Returns /// # Returns
/// ///
@ -764,7 +764,7 @@ impl EdwardsPoint {
/// Uses rejection sampling, generating a random `CompressedEdwardsY` and then attempting point /// Uses rejection sampling, generating a random `CompressedEdwardsY` and then attempting point
/// decompression, rejecting invalid points. /// decompression, rejecting invalid points.
#[cfg(feature = "rand_core")] #[cfg(feature = "rand_core")]
pub fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self { pub fn random<R: Rng + ?Sized>(rng: &mut R) -> Self {
let mut repr = CompressedEdwardsY([0u8; 32]); let mut repr = CompressedEdwardsY([0u8; 32]);
loop { loop {
rng.fill_bytes(&mut repr.0); rng.fill_bytes(&mut repr.0);
@ -1461,7 +1461,7 @@ impl Debug for EdwardsPoint {
impl group::Group for EdwardsPoint { impl group::Group for EdwardsPoint {
type Scalar = Scalar; type Scalar = Scalar;
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error> { fn try_from_rng<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
let mut repr = CompressedEdwardsY([0u8; 32]); let mut repr = CompressedEdwardsY([0u8; 32]);
loop { loop {
rng.try_fill_bytes(&mut repr.0)?; rng.try_fill_bytes(&mut repr.0)?;
@ -1713,7 +1713,7 @@ impl Zeroize for SubgroupPoint {
impl group::Group for SubgroupPoint { impl group::Group for SubgroupPoint {
type Scalar = Scalar; type Scalar = Scalar;
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error> { fn try_from_rng<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
use group::ff::Field; use group::ff::Field;
// This will almost never loop, but `Group::random` is documented as returning a // This will almost never loop, but `Group::random` is documented as returning a
@ -1790,8 +1790,10 @@ impl CofactorGroup for EdwardsPoint {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use getrandom::{
use rand::TryRngCore; SysRng,
rand_core::{TryRng, UnwrapErr},
};
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use alloc::vec::Vec; use alloc::vec::Vec;
@ -2080,7 +2082,7 @@ mod test {
/// Check that mul_base_clamped and mul_clamped agree /// Check that mul_base_clamped and mul_clamped agree
#[test] #[test]
fn mul_base_clamped() { fn mul_base_clamped() {
let mut csprng = rand::rngs::SysRng; let mut csprng = UnwrapErr(SysRng);
// Make a random curve point in the curve. Give it torsion to make things interesting. // Make a random curve point in the curve. Give it torsion to make things interesting.
#[cfg(feature = "precomputed-tables")] #[cfg(feature = "precomputed-tables")]
@ -2201,7 +2203,7 @@ mod test {
#[cfg(feature = "rand_core")] #[cfg(feature = "rand_core")]
#[test] #[test]
fn compress_batch() { fn compress_batch() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
// TODO(tarcieri): proptests? // TODO(tarcieri): proptests?
@ -2272,7 +2274,7 @@ mod test {
// A single iteration of a consistency check for MSM. // A single iteration of a consistency check for MSM.
#[cfg(all(feature = "alloc", feature = "rand_core"))] #[cfg(all(feature = "alloc", feature = "rand_core"))]
fn multiscalar_consistency_iter(n: usize) { fn multiscalar_consistency_iter(n: usize) {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
// Construct random coefficients x0, ..., x_{n-1}, // Construct random coefficients x0, ..., x_{n-1},
// followed by some extra hardcoded ones. // followed by some extra hardcoded ones.
@ -2335,7 +2337,7 @@ mod test {
#[test] #[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))] #[cfg(all(feature = "alloc", feature = "rand_core"))]
fn batch_to_montgomery() { fn batch_to_montgomery() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
let scalars = (0..128) let scalars = (0..128)
.map(|_| Scalar::random(&mut rng)) .map(|_| Scalar::random(&mut rng))
@ -2360,7 +2362,7 @@ mod test {
#[test] #[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))] #[cfg(all(feature = "alloc", feature = "rand_core"))]
fn vartime_precomputed_vs_nonprecomputed_multiscalar() { fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
let static_scalars = (0..128) let static_scalars = (0..128)
.map(|_| Scalar::random(&mut rng)) .map(|_| Scalar::random(&mut rng))

View file

@ -220,7 +220,8 @@ impl RistrettoPoint {
mod test { mod test {
use super::*; use super::*;
use crate::{edwards::EdwardsPoint, ristretto::CompressedRistretto}; use crate::{edwards::EdwardsPoint, ristretto::CompressedRistretto};
use rand_core::RngCore; use getrandom::{SysRng, rand_core::UnwrapErr};
use rand_core::Rng;
use sha2::Sha256; use sha2::Sha256;
/// Return the coset self + E\[4\] /// Return the coset self + E\[4\]
@ -281,7 +282,7 @@ mod test {
// Tests that lizard_decode of a random point is None // Tests that lizard_decode of a random point is None
#[test] #[test]
fn lizard_invalid() { fn lizard_invalid() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
for _ in 0..100 { for _ in 0..100 {
let pt = RistrettoPoint::random(&mut rng); let pt = RistrettoPoint::random(&mut rng);
assert!( assert!(
@ -297,7 +298,7 @@ mod test {
// is the identity // is the identity
#[test] #[test]
fn elligator_inv() { fn elligator_inv() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
for i in 0..100 { for i in 0..100 {
let mut fe_bytes = [0u8; 32]; let mut fe_bytes = [0u8; 32];
@ -342,7 +343,7 @@ mod test {
// Tests that map_to_curve ○ map_to_curve_inverse is the identity // Tests that map_to_curve ○ map_to_curve_inverse is the identity
#[test] #[test]
fn map_to_curve_inverse() { fn map_to_curve_inverse() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
for _ in 0..100 { for _ in 0..100 {
let mut input = [0u8; 32]; let mut input = [0u8; 32];
@ -365,7 +366,7 @@ mod test {
// return value in the first 8 elements // return value in the first 8 elements
#[test] #[test]
fn map_pos_felem_to_curve_inverse() { fn map_pos_felem_to_curve_inverse() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
for _ in 0..100 { for _ in 0..100 {
let mut input = [0u8; 32]; let mut input = [0u8; 32];

View file

@ -514,10 +514,13 @@ impl Mul<&MontgomeryPoint> for &Scalar {
mod test { mod test {
use super::*; use super::*;
use crate::constants; use crate::constants;
use getrandom::{
SysRng,
rand_core::{Rng, TryRng, UnwrapErr},
};
#[cfg(feature = "rand_core")] #[cfg(feature = "rand_core")]
use rand::CryptoRng; use rand_core::CryptoRng;
use rand::{RngCore, TryRngCore};
#[test] #[test]
fn identity_in_different_coordinates() { fn identity_in_different_coordinates() {
@ -622,7 +625,7 @@ mod test {
#[cfg(feature = "rand_core")] #[cfg(feature = "rand_core")]
#[test] #[test]
fn montgomery_ladder_matches_edwards_scalarmult() { fn montgomery_ladder_matches_edwards_scalarmult() {
let mut csprng = rand::rngs::SysRng.unwrap_err(); let mut csprng = UnwrapErr(SysRng);
for _ in 0..100 { for _ in 0..100 {
let p_edwards = rand_prime_order_point(&mut csprng); let p_edwards = rand_prime_order_point(&mut csprng);
@ -641,7 +644,7 @@ mod test {
#[cfg(feature = "rand_core")] #[cfg(feature = "rand_core")]
#[test] #[test]
fn montgomery_mul_bits_be() { fn montgomery_mul_bits_be() {
let mut csprng = rand::rngs::SysRng.unwrap_err(); let mut csprng = UnwrapErr(SysRng);
for _ in 0..100 { for _ in 0..100 {
// Make a random prime-order point P // Make a random prime-order point P
@ -666,7 +669,7 @@ mod test {
// integers b₁, b₂ and random (curve or twist) point P. // integers b₁, b₂ and random (curve or twist) point P.
#[test] #[test]
fn montgomery_mul_bits_be_twist() { fn montgomery_mul_bits_be_twist() {
let mut csprng = rand::rngs::SysRng.unwrap_err(); let mut csprng = UnwrapErr(SysRng);
for _ in 0..100 { for _ in 0..100 {
// Make a random point P on the curve or its twist // Make a random point P on the curve or its twist
@ -699,7 +702,7 @@ mod test {
/// Check that mul_base_clamped and mul_clamped agree /// Check that mul_base_clamped and mul_clamped agree
#[test] #[test]
fn mul_base_clamped() { fn mul_base_clamped() {
let mut csprng = rand::rngs::SysRng; let mut csprng = UnwrapErr(SysRng);
// Test agreement on a large integer. Even after clamping, this is not reduced mod l. // Test agreement on a large integer. Even after clamping, this is not reduced mod l.
let a_bytes = [0xff; 32]; let a_bytes = [0xff; 32];

View file

@ -180,7 +180,7 @@ use crate::field::FieldElement;
#[cfg(feature = "group")] #[cfg(feature = "group")]
use { use {
group::{GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup}, group::{GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup},
rand_core::TryRngCore, rand_core::TryRng,
subtle::CtOption, subtle::CtOption,
}; };
@ -543,12 +543,12 @@ impl RistrettoPoint {
#[cfg_attr(feature = "rand_core", doc = "```")] #[cfg_attr(feature = "rand_core", doc = "```")]
#[cfg_attr(not(feature = "rand_core"), doc = "```ignore")] #[cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
/// # use curve25519_dalek::ristretto::RistrettoPoint; /// # use curve25519_dalek::ristretto::RistrettoPoint;
/// use rand::{rngs::SysRng, TryRngCore}; /// use getrandom::{SysRng, rand_core::UnwrapErr};
/// ///
/// # // Need fn main() here in comment so the doctest compiles /// # // Need fn main() here in comment so the doctest compiles
/// # // See https://doc.rust-lang.org/book/documentation.html#documentation-as-tests /// # // See https://doc.rust-lang.org/book/documentation.html#documentation-as-tests
/// # fn main() { /// # fn main() {
/// let mut rng = SysRng.unwrap_err(); /// let mut rng = UnwrapErr(SysRng);
/// ///
/// let points: Vec<RistrettoPoint> = /// let points: Vec<RistrettoPoint> =
/// (0..32).map(|_| RistrettoPoint::random(&mut rng)).collect(); /// (0..32).map(|_| RistrettoPoint::random(&mut rng)).collect();
@ -1179,7 +1179,7 @@ impl Debug for RistrettoPoint {
impl group::Group for RistrettoPoint { impl group::Group for RistrettoPoint {
type Scalar = Scalar; type Scalar = Scalar;
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error> { fn try_from_rng<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
// NOTE: this is duplicated due to different `rng` bounds // NOTE: this is duplicated due to different `rng` bounds
let mut uniform_bytes = [0u8; 64]; let mut uniform_bytes = [0u8; 64];
rng.try_fill_bytes(&mut uniform_bytes)?; rng.try_fill_bytes(&mut uniform_bytes)?;
@ -1275,10 +1275,10 @@ impl Zeroize for RistrettoPoint {
mod test { mod test {
use super::*; use super::*;
use crate::edwards::CompressedEdwardsY; use crate::edwards::CompressedEdwardsY;
#[cfg(feature = "rand_core")]
use getrandom::{SysRng, rand_core::UnwrapErr};
#[cfg(feature = "group")] #[cfg(feature = "group")]
use proptest::prelude::*; use proptest::prelude::*;
#[cfg(feature = "rand_core")]
use rand::{TryRngCore, rngs::SysRng};
#[test] #[test]
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
@ -1472,7 +1472,7 @@ mod test {
#[cfg(feature = "rand_core")] #[cfg(feature = "rand_core")]
#[test] #[test]
fn four_torsion_random() { fn four_torsion_random() {
let mut rng = SysRng.unwrap_err(); let mut rng = UnwrapErr(SysRng);
let P = RistrettoPoint::mul_base(&Scalar::random(&mut rng)); let P = RistrettoPoint::mul_base(&Scalar::random(&mut rng));
let P_coset = P.coset4(); let P_coset = P.coset4();
for point in P_coset { for point in P_coset {
@ -1483,7 +1483,7 @@ mod test {
#[cfg(feature = "rand_core")] #[cfg(feature = "rand_core")]
#[test] #[test]
fn random_roundtrip() { fn random_roundtrip() {
let mut rng = SysRng.unwrap_err(); let mut rng = UnwrapErr(SysRng);
for _ in 0..100 { for _ in 0..100 {
let P = RistrettoPoint::mul_base(&Scalar::random(&mut rng)); let P = RistrettoPoint::mul_base(&Scalar::random(&mut rng));
let compressed_P = P.compress(); let compressed_P = P.compress();
@ -1546,7 +1546,7 @@ mod test {
#[test] #[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))] #[cfg(all(feature = "alloc", feature = "rand_core"))]
fn vartime_precomputed_vs_nonprecomputed_multiscalar() { fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
let static_scalars = (0..128) let static_scalars = (0..128)
.map(|_| Scalar::random(&mut rng)) .map(|_| Scalar::random(&mut rng))
@ -1597,7 +1597,7 @@ mod test {
#[test] #[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))] #[cfg(all(feature = "alloc", feature = "rand_core"))]
fn partial_precomputed_mixed_multiscalar_empty() { fn partial_precomputed_mixed_multiscalar_empty() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
let n_static = 16; let n_static = 16;
let n_dynamic = 8; let n_dynamic = 8;
@ -1640,7 +1640,7 @@ mod test {
#[test] #[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))] #[cfg(all(feature = "alloc", feature = "rand_core"))]
fn partial_precomputed_mixed_multiscalar() { fn partial_precomputed_mixed_multiscalar() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
let n_static = 16; let n_static = 16;
let n_dynamic = 8; let n_dynamic = 8;
@ -1685,7 +1685,7 @@ mod test {
#[test] #[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))] #[cfg(all(feature = "alloc", feature = "rand_core"))]
fn partial_precomputed_multiscalar() { fn partial_precomputed_multiscalar() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
let n_static = 16; let n_static = 16;
@ -1714,7 +1714,7 @@ mod test {
#[test] #[test]
#[cfg(all(feature = "alloc", feature = "rand_core"))] #[cfg(all(feature = "alloc", feature = "rand_core"))]
fn partial_precomputed_multiscalar_empty() { fn partial_precomputed_multiscalar_empty() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
let n_static = 16; let n_static = 16;

View file

@ -128,7 +128,7 @@ use group::ff::{Field, FromUniformBytes, PrimeField};
use group::ff::{FieldBits, PrimeFieldBits}; use group::ff::{FieldBits, PrimeFieldBits};
#[cfg(feature = "group")] #[cfg(feature = "group")]
use rand_core::TryRngCore; use rand_core::TryRng;
#[cfg(feature = "rand_core")] #[cfg(feature = "rand_core")]
use rand_core::CryptoRng; use rand_core::CryptoRng;
@ -582,10 +582,9 @@ impl Scalar {
/// ``` /// ```
/// # fn main() { /// # fn main() {
/// use curve25519_dalek::scalar::Scalar; /// use curve25519_dalek::scalar::Scalar;
/// use getrandom::{SysRng, rand_core::UnwrapErr};
/// ///
/// use rand::{rngs::SysRng, TryRngCore}; /// let mut csprng = UnwrapErr(SysRng);
///
/// let mut csprng = SysRng.unwrap_err();
/// let a: Scalar = Scalar::random(&mut csprng); /// let a: Scalar = Scalar::random(&mut csprng);
/// # } /// # }
#[cfg(feature = "rand_core")] #[cfg(feature = "rand_core")]
@ -1250,7 +1249,7 @@ impl Field for Scalar {
const ZERO: Self = Self::ZERO; const ZERO: Self = Self::ZERO;
const ONE: Self = Self::ONE; const ONE: Self = Self::ONE;
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error> { fn try_from_rng<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
// NOTE: this is duplicated due to different `rng` bounds // NOTE: this is duplicated due to different `rng` bounds
let mut scalar_bytes = [0u8; 64]; let mut scalar_bytes = [0u8; 64];
rng.try_fill_bytes(&mut scalar_bytes)?; rng.try_fill_bytes(&mut scalar_bytes)?;
@ -1430,7 +1429,10 @@ pub const fn clamp_integer(mut bytes: [u8; 32]) -> [u8; 32] {
#[cfg(test)] #[cfg(test)]
pub(crate) mod test { pub(crate) mod test {
use super::*; use super::*;
use rand::RngCore; use getrandom::{
SysRng,
rand_core::{Rng, UnwrapErr},
};
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use alloc::vec::Vec; use alloc::vec::Vec;
@ -1592,7 +1594,7 @@ pub(crate) mod test {
#[cfg(feature = "rand_core")] #[cfg(feature = "rand_core")]
#[test] #[test]
fn non_adjacent_form_random() { fn non_adjacent_form_random() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
for _ in 0..1_000 { for _ in 0..1_000 {
let x = Scalar::random(&mut rng); let x = Scalar::random(&mut rng);
for w in &[5, 6, 7, 8] { for w in &[5, 6, 7, 8] {
@ -2122,7 +2124,7 @@ pub(crate) mod test {
// was reduced and b was clamped and unreduced. This checks that was always well-defined. // was reduced and b was clamped and unreduced. This checks that was always well-defined.
#[test] #[test]
fn test_mul_reduction_invariance() { fn test_mul_reduction_invariance() {
let mut rng = rand::rng(); let mut rng = UnwrapErr(SysRng);
for _ in 0..10 { for _ in 0..10 {
// Also define c that's clamped. We'll make sure that clamping doesn't affect // Also define c that's clamped. We'll make sure that clamping doesn't affect

View file

@ -32,13 +32,13 @@ curve25519-dalek = { version = "=5.0.0-pre.4", default-features = false, feature
"digest", "digest",
] } ] }
ed25519 = { version = "3.0.0-rc.2", default-features = false } ed25519 = { version = "3.0.0-rc.2", default-features = false }
signature = { version = "3.0.0-rc.5", optional = true, default-features = false } signature = { version = "3.0.0-rc.9", optional = true, default-features = false }
sha2 = { version = "0.11.0-rc.3", default-features = false } sha2 = { version = "0.11.0-rc.4", default-features = false }
subtle = { version = "2.3.0", default-features = false } subtle = { version = "2.3.0", default-features = false }
# optional features # optional features
keccak = { version = "0.2.0-rc.0", default-features = false, optional = true } keccak = { version = "0.2.0-rc.1", default-features = false, optional = true }
rand_core = { version = "0.10.0-rc-5", default-features = false, optional = true } rand_core = { version = "0.10.0-rc-6", default-features = false, optional = true }
serde = { version = "1.0", default-features = false, optional = true } serde = { version = "1.0", default-features = false, optional = true }
zeroize = { version = "1.5", default-features = false, optional = true } zeroize = { version = "1.5", default-features = false, optional = true }
@ -50,14 +50,15 @@ curve25519-dalek = { version = "=5.0.0-pre.4", default-features = false, feature
x25519-dalek = { version = "=3.0.0-pre.4", default-features = false, features = [ x25519-dalek = { version = "=3.0.0-pre.4", default-features = false, features = [
"static_secrets", "static_secrets",
] } ] }
blake2 = "0.11.0-rc.3" blake2 = "0.11.0-rc.4"
sha3 = "0.11.0-rc.3" chacha20 = { version = "0.10.0-rc.9", default-features = false, features = ["rng"] }
sha3 = "0.11.0-rc.4"
getrandom = { version = "0.4.0-rc.1", features = ["sys_rng"] }
hex = "0.4" hex = "0.4"
bincode = "1.0" bincode = "1.0"
serde_json = "1.0" serde_json = "1.0"
criterion = { version = "0.5", features = ["html_reports"] } criterion = { version = "0.5", features = ["html_reports"] }
hex-literal = "1" hex-literal = "1"
rand = { version = "0.10.0-rc.7", features = ["chacha"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
strobe-rs = "0.5" strobe-rs = "0.5"
toml = { version = "0.9" } toml = { version = "0.9" }

View file

@ -14,8 +14,8 @@ mod ed25519_benches {
use ed25519_dalek::Signature; use ed25519_dalek::Signature;
use ed25519_dalek::Signer; use ed25519_dalek::Signer;
use ed25519_dalek::SigningKey; use ed25519_dalek::SigningKey;
use rand::prelude::ThreadRng; use rand_core::prelude::ThreadRng;
use rand::rng; use rand_core::rng;
fn sign(c: &mut Criterion) { fn sign(c: &mut Criterion) {
let mut csprng: ThreadRng = rng(); let mut csprng: ThreadRng = rng();

View file

@ -27,7 +27,7 @@ pub use curve25519_dalek::digest::Digest;
use transcript::Transcript; use transcript::Transcript;
use rand_core::RngCore; use rand_core::Rng;
use sha2::Sha512; use sha2::Sha512;
@ -44,12 +44,12 @@ use crate::signature::InternalSignature;
/// but implement the same 1.0 protocol. /// but implement the same 1.0 protocol.
const MERLIN_PROTOCOL_LABEL: &[u8] = b"Merlin v1.0"; const MERLIN_PROTOCOL_LABEL: &[u8] = b"Merlin v1.0";
/// An implementation of `rand_core::RngCore` which does nothing. This is necessary because merlin /// An implementation of `rand_core::Rng` which does nothing. This is necessary because merlin
/// demands an `Rng` as input to `TranscriptRngBuilder::finalize()`. Using this with `finalize()` /// demands an `Rng` as input to `TranscriptRngBuilder::finalize()`. Using this with `finalize()`
/// yields a PRG whose input is the hashed transcript. /// yields a PRG whose input is the hashed transcript.
struct ZeroRng; struct ZeroRng;
impl rand_core::TryRngCore for ZeroRng { impl rand_core::TryRng for ZeroRng {
type Error = Infallible; type Error = Infallible;
fn try_next_u32(&mut self) -> Result<u32, Self::Error> { fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
@ -77,7 +77,7 @@ impl rand_core::TryRngCore for ZeroRng {
impl rand_core::TryCryptoRng for ZeroRng {} impl rand_core::TryCryptoRng for ZeroRng {}
// We write our own gen() function so we don't need to pull in the rand crate // We write our own gen() function so we don't need to pull in the rand crate
fn gen_u128<R: RngCore>(rng: &mut R) -> u128 { fn gen_u128<R: Rng>(rng: &mut R) -> u128 {
let mut buf = [0u8; 16]; let mut buf = [0u8; 16];
rng.fill_bytes(&mut buf); rng.fill_bytes(&mut buf);
u128::from_le_bytes(buf) u128::from_le_bytes(buf)
@ -129,11 +129,10 @@ fn gen_u128<R: RngCore>(rng: &mut R) -> u128 {
/// use ed25519_dalek::{ /// use ed25519_dalek::{
/// verify_batch, SigningKey, VerifyingKey, Signer, Signature, /// verify_batch, SigningKey, VerifyingKey, Signer, Signature,
/// }; /// };
/// use rand::rngs::SysRng; /// use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
/// use rand_core::TryRngCore;
/// ///
/// # fn main() { /// # fn main() {
/// let mut csprng = SysRng.unwrap_err(); /// let mut csprng = UnwrapErr(SysRng);
/// let signing_keys: Vec<_> = (0..64).map(|_| SigningKey::generate(&mut csprng)).collect(); /// let signing_keys: Vec<_> = (0..64).map(|_| SigningKey::generate(&mut csprng)).collect();
/// let msg: &[u8] = b"They're good dogs Brant"; /// let msg: &[u8] = b"They're good dogs Brant";
/// let messages: Vec<_> = (0..64).map(|_| msg).collect(); /// let messages: Vec<_> = (0..64).map(|_| msg).collect();

View file

@ -156,7 +156,7 @@ impl TranscriptRngBuilder {
/// transcript data. /// transcript data.
pub fn finalize<R>(mut self, rng: &mut R) -> TranscriptRng pub fn finalize<R>(mut self, rng: &mut R) -> TranscriptRng
where where
R: rand_core::RngCore + rand_core::CryptoRng, R: rand_core::Rng + rand_core::CryptoRng,
{ {
let random_bytes = { let random_bytes = {
let mut bytes = [0u8; 32]; let mut bytes = [0u8; 32];
@ -186,7 +186,7 @@ pub struct TranscriptRng {
strobe: Strobe128, strobe: Strobe128,
} }
impl rand_core::TryRngCore for TranscriptRng { impl rand_core::TryRng for TranscriptRng {
type Error = Infallible; type Error = Infallible;
fn try_next_u32(&mut self) -> Result<u32, Self::Error> { fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
@ -309,8 +309,9 @@ mod tests {
#[test] #[test]
fn transcript_rng_is_bound_to_transcript_and_witnesses() { fn transcript_rng_is_bound_to_transcript_and_witnesses() {
use chacha20::ChaCha8Rng;
use curve25519_dalek::scalar::Scalar; use curve25519_dalek::scalar::Scalar;
use rand::{SeedableRng, rngs::ChaCha8Rng}; use rand_core::SeedableRng;
// Check that the TranscriptRng is bound to the transcript and // Check that the TranscriptRng is bound to the transcript and
// the witnesses. This is done by producing a sequence of // the witnesses. This is done by producing a sequence of

View file

@ -23,11 +23,10 @@ use crate::{InternalError, SignatureError};
/// # fn main() { /// # fn main() {
/// use ed25519_dalek::{Signature, SigningKey, VerifyingKey, Sha512}; /// use ed25519_dalek::{Signature, SigningKey, VerifyingKey, Sha512};
/// # use curve25519_dalek::digest::Digest; /// # use curve25519_dalek::digest::Digest;
/// # use rand::rngs::SysRng; /// # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
/// # use rand_core::TryRngCore;
/// use ed25519_dalek::{DigestSigner, DigestVerifier}; /// use ed25519_dalek::{DigestSigner, DigestVerifier};
/// ///
/// # let mut csprng = SysRng.unwrap_err(); /// # let mut csprng = UnwrapErr(SysRng);
/// # let signing_key = SigningKey::generate(&mut csprng); /// # let signing_key = SigningKey::generate(&mut csprng);
/// # let verifying_key = signing_key.verifying_key(); /// # let verifying_key = signing_key.verifying_key();
/// let context_str = b"Local Channel 3"; /// let context_str = b"Local Channel 3";
@ -91,13 +90,14 @@ mod test {
use crate::{Signature, SigningKey, VerifyingKey}; use crate::{Signature, SigningKey, VerifyingKey};
use curve25519_dalek::digest::Digest; use curve25519_dalek::digest::Digest;
use rand::{TryRngCore, rngs::SysRng}; use getrandom::SysRng;
use rand_core::UnwrapErr;
use sha2::Sha512; use sha2::Sha512;
use signature::{DigestSigner, DigestVerifier}; use signature::{DigestSigner, DigestVerifier};
#[test] #[test]
fn context_correctness() { fn context_correctness() {
let mut csprng = SysRng.unwrap_err(); let mut csprng = UnwrapErr(SysRng);
let signing_key: SigningKey = SigningKey::generate(&mut csprng); let signing_key: SigningKey = SigningKey::generate(&mut csprng);
let verifying_key: VerifyingKey = signing_key.verifying_key(); let verifying_key: VerifyingKey = signing_key.verifying_key();

View file

@ -258,7 +258,10 @@ mod test {
use super::*; use super::*;
use rand::{CryptoRng, TryRngCore, rngs::SysRng}; use getrandom::{
SysRng,
rand_core::{CryptoRng, UnwrapErr},
};
// Pick distinct, non-spec 512-bit hash functions for message and sig-context hashing // Pick distinct, non-spec 512-bit hash functions for message and sig-context hashing
type CtxDigest = blake2::Blake2b512; type CtxDigest = blake2::Blake2b512;
@ -278,7 +281,7 @@ mod test {
#[test] #[test]
fn sign_verify_nonspec() { fn sign_verify_nonspec() {
// Generate the keypair // Generate the keypair
let mut rng = SysRng.unwrap_err(); let mut rng = UnwrapErr(SysRng);
let esk = ExpandedSecretKey::random(&mut rng); let esk = ExpandedSecretKey::random(&mut rng);
let vk = VerifyingKey::from(&esk); let vk = VerifyingKey::from(&esk);
@ -297,7 +300,7 @@ mod test {
use curve25519_dalek::digest::Digest; use curve25519_dalek::digest::Digest;
// Generate the keypair // Generate the keypair
let mut rng = SysRng.unwrap_err(); let mut rng = UnwrapErr(SysRng);
let esk = ExpandedSecretKey::random(&mut rng); let esk = ExpandedSecretKey::random(&mut rng);
let vk = VerifyingKey::from(&esk); let vk = VerifyingKey::from(&esk);
@ -317,7 +320,7 @@ mod test {
#[test] #[test]
fn sign_byupdate() { fn sign_byupdate() {
// Generate the keypair // Generate the keypair
let mut rng = SysRng.unwrap_err(); let mut rng = UnwrapErr(SysRng);
let esk = ExpandedSecretKey::random(&mut rng); let esk = ExpandedSecretKey::random(&mut rng);
let vk = VerifyingKey::from(&esk); let vk = VerifyingKey::from(&esk);

View file

@ -22,12 +22,12 @@
#![cfg_attr(not(feature = "rand_core"), doc = "```ignore")] #![cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
//! # fn main() { //! # fn main() {
//! // $ cargo add ed25519_dalek --features rand_core //! // $ cargo add ed25519_dalek --features rand_core
//! use rand::rngs::SysRng; //! use getrandom::{SysRng, rand_core::UnwrapErr};
//! use rand_core::TryRngCore; //! use rand_core::TryRng;
//! use ed25519_dalek::SigningKey; //! use ed25519_dalek::SigningKey;
//! use ed25519_dalek::Signature; //! use ed25519_dalek::Signature;
//! //!
//! let mut csprng = SysRng.unwrap_err(); //! let mut csprng = UnwrapErr(SysRng);
//! let signing_key: SigningKey = SigningKey::generate(&mut csprng); //! let signing_key: SigningKey = SigningKey::generate(&mut csprng);
//! # } //! # }
//! ``` //! ```
@ -37,10 +37,9 @@
#![cfg_attr(feature = "rand_core", doc = "```")] #![cfg_attr(feature = "rand_core", doc = "```")]
#![cfg_attr(not(feature = "rand_core"), doc = "```ignore")] #![cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
//! # fn main() { //! # fn main() {
//! # use rand::rngs::SysRng; //! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
//! # use rand_core::TryRngCore;
//! # use ed25519_dalek::SigningKey; //! # use ed25519_dalek::SigningKey;
//! # let mut csprng = SysRng.unwrap_err(); //! # let mut csprng = UnwrapErr(SysRng);
//! # let signing_key: SigningKey = SigningKey::generate(&mut csprng); //! # let signing_key: SigningKey = SigningKey::generate(&mut csprng);
//! use ed25519_dalek::{Signature, Signer}; //! use ed25519_dalek::{Signature, Signer};
//! let message: &[u8] = b"This is a test of the tsunami alert system."; //! let message: &[u8] = b"This is a test of the tsunami alert system.";
@ -54,10 +53,9 @@
#![cfg_attr(feature = "rand_core", doc = "```")] #![cfg_attr(feature = "rand_core", doc = "```")]
#![cfg_attr(not(feature = "rand_core"), doc = "```ignore")] #![cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
//! # fn main() { //! # fn main() {
//! # use rand::rngs::SysRng; //! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
//! # use rand_core::TryRngCore;
//! # use ed25519_dalek::{SigningKey, Signature, Signer}; //! # use ed25519_dalek::{SigningKey, Signature, Signer};
//! # let mut csprng = SysRng.unwrap_err(); //! # let mut csprng = UnwrapErr(SysRng);
//! # let signing_key: SigningKey = SigningKey::generate(&mut csprng); //! # let signing_key: SigningKey = SigningKey::generate(&mut csprng);
//! # let message: &[u8] = b"This is a test of the tsunami alert system."; //! # let message: &[u8] = b"This is a test of the tsunami alert system.";
//! # let signature: Signature = signing_key.sign(message); //! # let signature: Signature = signing_key.sign(message);
@ -72,13 +70,12 @@
#![cfg_attr(feature = "rand_core", doc = "```")] #![cfg_attr(feature = "rand_core", doc = "```")]
#![cfg_attr(not(feature = "rand_core"), doc = "```ignore")] #![cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
//! # fn main() { //! # fn main() {
//! # use rand::rngs::SysRng; //! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
//! # use rand_core::TryRngCore;
//! # use ed25519_dalek::SigningKey; //! # use ed25519_dalek::SigningKey;
//! # use ed25519_dalek::Signature; //! # use ed25519_dalek::Signature;
//! # use ed25519_dalek::Signer; //! # use ed25519_dalek::Signer;
//! use ed25519_dalek::{VerifyingKey, Verifier}; //! use ed25519_dalek::{VerifyingKey, Verifier};
//! # let mut csprng = SysRng.unwrap_err(); //! # let mut csprng = UnwrapErr(SysRng);
//! # let signing_key: SigningKey = SigningKey::generate(&mut csprng); //! # let signing_key: SigningKey = SigningKey::generate(&mut csprng);
//! # let message: &[u8] = b"This is a test of the tsunami alert system."; //! # let message: &[u8] = b"This is a test of the tsunami alert system.";
//! # let signature: Signature = signing_key.sign(message); //! # let signature: Signature = signing_key.sign(message);
@ -99,11 +96,10 @@
#![cfg_attr(feature = "rand_core", doc = "```")] #![cfg_attr(feature = "rand_core", doc = "```")]
#![cfg_attr(not(feature = "rand_core"), doc = "```ignore")] #![cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
//! # fn main() { //! # fn main() {
//! # use rand::rngs::SysRng; //! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
//! # use rand_core::TryRngCore;
//! # use ed25519_dalek::{SigningKey, Signature, Signer, VerifyingKey}; //! # use ed25519_dalek::{SigningKey, Signature, Signer, VerifyingKey};
//! use ed25519_dalek::{PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH, KEYPAIR_LENGTH, SIGNATURE_LENGTH}; //! use ed25519_dalek::{PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH, KEYPAIR_LENGTH, SIGNATURE_LENGTH};
//! # let mut csprng = SysRng.unwrap_err(); //! # let mut csprng = UnwrapErr(SysRng);
//! # let signing_key: SigningKey = SigningKey::generate(&mut csprng); //! # let signing_key: SigningKey = SigningKey::generate(&mut csprng);
//! # let message: &[u8] = b"This is a test of the tsunami alert system."; //! # let message: &[u8] = b"This is a test of the tsunami alert system.";
//! # let signature: Signature = signing_key.sign(message); //! # let signature: Signature = signing_key.sign(message);
@ -120,12 +116,11 @@
#![cfg_attr(feature = "rand_core", doc = "```")] #![cfg_attr(feature = "rand_core", doc = "```")]
#![cfg_attr(not(feature = "rand_core"), doc = "```ignore")] #![cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
//! # use core::convert::{TryFrom, TryInto}; //! # use core::convert::{TryFrom, TryInto};
//! # use rand::rngs::SysRng; //! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
//! # use rand_core::TryRngCore;
//! # use ed25519_dalek::{SigningKey, Signature, Signer, VerifyingKey, SecretKey, SignatureError}; //! # use ed25519_dalek::{SigningKey, Signature, Signer, VerifyingKey, SecretKey, SignatureError};
//! # use ed25519_dalek::{PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH, KEYPAIR_LENGTH, SIGNATURE_LENGTH}; //! # use ed25519_dalek::{PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH, KEYPAIR_LENGTH, SIGNATURE_LENGTH};
//! # fn do_test() -> Result<(SigningKey, VerifyingKey, Signature), SignatureError> { //! # fn do_test() -> Result<(SigningKey, VerifyingKey, Signature), SignatureError> {
//! # let mut csprng = SysRng.unwrap_err(); //! # let mut csprng = UnwrapErr(SysRng);
//! # let signing_key_orig: SigningKey = SigningKey::generate(&mut csprng); //! # let signing_key_orig: SigningKey = SigningKey::generate(&mut csprng);
//! # let message: &[u8] = b"This is a test of the tsunami alert system."; //! # let message: &[u8] = b"This is a test of the tsunami alert system.";
//! # let signature_orig: Signature = signing_key_orig.sign(message); //! # let signature_orig: Signature = signing_key_orig.sign(message);
@ -198,11 +193,10 @@
#![cfg_attr(all(feature = "rand_core", feature = "serde"), doc = "```")] #![cfg_attr(all(feature = "rand_core", feature = "serde"), doc = "```")]
#![cfg_attr(not(all(feature = "rand_core", feature = "serde")), doc = "```ignore")] #![cfg_attr(not(all(feature = "rand_core", feature = "serde")), doc = "```ignore")]
//! # fn main() { //! # fn main() {
//! # use rand::rngs::SysRng; //! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
//! # use rand_core::TryRngCore;
//! # use ed25519_dalek::{SigningKey, Signature, Signer, Verifier, VerifyingKey}; //! # use ed25519_dalek::{SigningKey, Signature, Signer, Verifier, VerifyingKey};
//! use bincode::serialize; //! use bincode::serialize;
//! # let mut csprng = SysRng.unwrap_err(); //! # let mut csprng = UnwrapErr(SysRng);
//! # let signing_key: SigningKey = SigningKey::generate(&mut csprng); //! # let signing_key: SigningKey = SigningKey::generate(&mut csprng);
//! # let message: &[u8] = b"This is a test of the tsunami alert system."; //! # let message: &[u8] = b"This is a test of the tsunami alert system.";
//! # let signature: Signature = signing_key.sign(message); //! # let signature: Signature = signing_key.sign(message);
@ -220,13 +214,12 @@
#![cfg_attr(all(feature = "rand_core", feature = "serde"), doc = "```")] #![cfg_attr(all(feature = "rand_core", feature = "serde"), doc = "```")]
#![cfg_attr(not(all(feature = "rand_core", feature = "serde")), doc = "```ignore")] #![cfg_attr(not(all(feature = "rand_core", feature = "serde")), doc = "```ignore")]
//! # fn main() { //! # fn main() {
//! # use rand::rngs::SysRng; //! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
//! # use rand_core::TryRngCore;
//! # use ed25519_dalek::{SigningKey, Signature, Signer, Verifier, VerifyingKey}; //! # use ed25519_dalek::{SigningKey, Signature, Signer, Verifier, VerifyingKey};
//! # use bincode::serialize; //! # use bincode::serialize;
//! use bincode::deserialize; //! use bincode::deserialize;
//! //!
//! # let mut csprng = SysRng.unwrap_err(); //! # let mut csprng = UnwrapErr(SysRng);
//! # let signing_key: SigningKey = SigningKey::generate(&mut csprng); //! # let signing_key: SigningKey = SigningKey::generate(&mut csprng);
//! let message: &[u8] = b"This is a test of the tsunami alert system."; //! let message: &[u8] = b"This is a test of the tsunami alert system.";
//! # let signature: Signature = signing_key.sign(message); //! # let signature: Signature = signing_key.sign(message);

View file

@ -189,11 +189,10 @@ impl SigningKey {
#[cfg_attr(feature = "rand_core", doc = "```")] #[cfg_attr(feature = "rand_core", doc = "```")]
#[cfg_attr(not(feature = "rand_core"), doc = "```ignore")] #[cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
/// # fn main() { /// # fn main() {
/// use rand::rngs::SysRng; /// use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
/// use rand_core::TryRngCore;
/// use ed25519_dalek::{Signature, SigningKey}; /// use ed25519_dalek::{Signature, SigningKey};
/// ///
/// let mut csprng = SysRng.unwrap_err(); /// let mut csprng = UnwrapErr(SysRng);
/// let signing_key: SigningKey = SigningKey::generate(&mut csprng); /// let signing_key: SigningKey = SigningKey::generate(&mut csprng);
/// # } /// # }
/// ``` /// ```
@ -242,11 +241,10 @@ impl SigningKey {
/// use ed25519_dalek::SigningKey; /// use ed25519_dalek::SigningKey;
/// use ed25519_dalek::Signature; /// use ed25519_dalek::Signature;
/// use sha2::Sha512; /// use sha2::Sha512;
/// use rand::rngs::SysRng; /// use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
/// use rand_core::TryRngCore;
/// ///
/// # fn main() { /// # fn main() {
/// let mut csprng = SysRng.unwrap_err(); /// let mut csprng = UnwrapErr(SysRng);
/// let signing_key: SigningKey = SigningKey::generate(&mut csprng); /// let signing_key: SigningKey = SigningKey::generate(&mut csprng);
/// let message: &[u8] = b"All I want is to pet all of the dogs."; /// let message: &[u8] = b"All I want is to pet all of the dogs.";
/// ///
@ -288,11 +286,10 @@ impl SigningKey {
/// # use ed25519_dalek::Signature; /// # use ed25519_dalek::Signature;
/// # use ed25519_dalek::SignatureError; /// # use ed25519_dalek::SignatureError;
/// # use sha2::Sha512; /// # use sha2::Sha512;
/// # use rand::rngs::SysRng; /// # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
/// # use rand_core::TryRngCore;
/// # /// #
/// # fn do_test() -> Result<Signature, SignatureError> { /// # fn do_test() -> Result<Signature, SignatureError> {
/// # let mut csprng = SysRng.unwrap_err(); /// # let mut csprng = UnwrapErr(SysRng);
/// # let signing_key: SigningKey = SigningKey::generate(&mut csprng); /// # let signing_key: SigningKey = SigningKey::generate(&mut csprng);
/// # let message: &[u8] = b"All I want is to pet all of the dogs."; /// # let message: &[u8] = b"All I want is to pet all of the dogs.";
/// # let mut prehashed: Sha512 = Sha512::new(); /// # let mut prehashed: Sha512 = Sha512::new();
@ -368,11 +365,10 @@ impl SigningKey {
/// use ed25519_dalek::Signature; /// use ed25519_dalek::Signature;
/// use ed25519_dalek::SignatureError; /// use ed25519_dalek::SignatureError;
/// use sha2::Sha512; /// use sha2::Sha512;
/// use rand::rngs::SysRng; /// use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
/// use rand_core::TryRngCore;
/// ///
/// # fn do_test() -> Result<(), SignatureError> { /// # fn do_test() -> Result<(), SignatureError> {
/// let mut csprng = SysRng.unwrap_err(); /// let mut csprng = UnwrapErr(SysRng);
/// let signing_key: SigningKey = SigningKey::generate(&mut csprng); /// let signing_key: SigningKey = SigningKey::generate(&mut csprng);
/// let message: &[u8] = b"All I want is to pet all of the dogs."; /// let message: &[u8] = b"All I want is to pet all of the dogs.";
/// ///
@ -790,7 +786,7 @@ impl<'d> Deserialize<'d> for SigningKey {
type Value = SigningKey; type Value = SigningKey;
fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(formatter, concat!("An ed25519 signing (private) key")) write!(formatter, "An ed25519 signing (private) key")
} }
fn visit_bytes<E: serde::de::Error>(self, bytes: &[u8]) -> Result<Self::Value, E> { fn visit_bytes<E: serde::de::Error>(self, bytes: &[u8]) -> Result<Self::Value, E> {

View file

@ -710,7 +710,7 @@ impl<'d> Deserialize<'d> for VerifyingKey {
type Value = VerifyingKey; type Value = VerifyingKey;
fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(formatter, concat!("An ed25519 verifying (public) key")) write!(formatter, "An ed25519 verifying (public) key")
} }
fn visit_bytes<E: serde::de::Error>(self, bytes: &[u8]) -> Result<Self::Value, E> { fn visit_bytes<E: serde::de::Error>(self, bytes: &[u8]) -> Result<Self::Value, E> {

View file

@ -20,6 +20,7 @@ use hex_literal::hex;
#[cfg(test)] #[cfg(test)]
mod vectors { mod vectors {
use super::*; use super::*;
use getrandom::{SysRng, rand_core::UnwrapErr};
use curve25519_dalek::{ use curve25519_dalek::{
constants::ED25519_BASEPOINT_POINT, constants::ED25519_BASEPOINT_POINT,
@ -27,7 +28,6 @@ mod vectors {
scalar::Scalar, scalar::Scalar,
traits::IsIdentity, traits::IsIdentity,
}; };
use rand::TryRngCore;
#[cfg(not(feature = "digest"))] #[cfg(not(feature = "digest"))]
use sha2::{Sha512, digest::Digest}; use sha2::{Sha512, digest::Digest};
@ -183,7 +183,7 @@ mod vectors {
// Pick a random Scalar // Pick a random Scalar
fn non_null_scalar() -> Scalar { fn non_null_scalar() -> Scalar {
let mut rng = rand::rngs::SysRng.unwrap_err(); let mut rng = UnwrapErr(SysRng);
let mut s_candidate = Scalar::random(&mut rng); let mut s_candidate = Scalar::random(&mut rng);
while s_candidate == Scalar::ZERO { while s_candidate == Scalar::ZERO {
s_candidate = Scalar::random(&mut rng); s_candidate = Scalar::random(&mut rng);
@ -295,7 +295,7 @@ mod vectors {
#[cfg(feature = "rand_core")] #[cfg(feature = "rand_core")]
mod integrations { mod integrations {
use super::*; use super::*;
use rand::{TryRngCore, rngs::SysRng}; use getrandom::{SysRng, rand_core::UnwrapErr};
use std::collections::HashMap; use std::collections::HashMap;
#[test] #[test]
@ -305,7 +305,7 @@ mod integrations {
let good: &[u8] = "test message".as_bytes(); let good: &[u8] = "test message".as_bytes();
let bad: &[u8] = "wrong message".as_bytes(); let bad: &[u8] = "wrong message".as_bytes();
let mut csprng = SysRng.unwrap_err(); let mut csprng = UnwrapErr(SysRng);
let signing_key: SigningKey = SigningKey::generate(&mut csprng); let signing_key: SigningKey = SigningKey::generate(&mut csprng);
let verifying_key = signing_key.verifying_key(); let verifying_key = signing_key.verifying_key();
@ -346,7 +346,7 @@ mod integrations {
fn sign_verify_digest_equivalence() { fn sign_verify_digest_equivalence() {
// TestSignVerify // TestSignVerify
let mut csprng = SysRng.unwrap_err(); let mut csprng = UnwrapErr(SysRng);
let good: &[u8] = "test message".as_bytes(); let good: &[u8] = "test message".as_bytes();
let bad: &[u8] = "wrong message".as_bytes(); let bad: &[u8] = "wrong message".as_bytes();
@ -391,7 +391,7 @@ mod integrations {
let good: &[u8] = b"test message"; let good: &[u8] = b"test message";
let bad: &[u8] = b"wrong message"; let bad: &[u8] = b"wrong message";
let mut csprng = SysRng.unwrap_err(); let mut csprng = UnwrapErr(SysRng);
// ugh… there's no `impl Copy for Sha512`… i hope we can all agree these are the same hashes // ugh… there's no `impl Copy for Sha512`… i hope we can all agree these are the same hashes
let mut prehashed_good1: Sha512 = Sha512::default(); let mut prehashed_good1: Sha512 = Sha512::default();
@ -466,7 +466,7 @@ mod integrations {
b"Fuck dumbin' it down, spit ice, skip jewellery: Molotov cocktails on me like accessories.", b"Fuck dumbin' it down, spit ice, skip jewellery: Molotov cocktails on me like accessories.",
b"Hey, I never cared about your bucks, so if I run up with a mask on, probably got a gas can too.", b"Hey, I never cared about your bucks, so if I run up with a mask on, probably got a gas can too.",
b"And I'm not here to fill 'er up. Nope, we came to riot, here to incite, we don't want any of your stuff.", ]; b"And I'm not here to fill 'er up. Nope, we came to riot, here to incite, we don't want any of your stuff.", ];
let mut csprng = SysRng.unwrap_err(); let mut csprng = UnwrapErr(SysRng);
let mut signing_keys: Vec<SigningKey> = Vec::new(); let mut signing_keys: Vec<SigningKey> = Vec::new();
let mut signatures: Vec<Signature> = Vec::new(); let mut signatures: Vec<Signature> = Vec::new();
@ -485,7 +485,7 @@ mod integrations {
#[test] #[test]
fn public_key_hash_trait_check() { fn public_key_hash_trait_check() {
let mut csprng = SysRng.unwrap_err(); let mut csprng = UnwrapErr(SysRng);
let secret: SigningKey = SigningKey::generate(&mut csprng); let secret: SigningKey = SigningKey::generate(&mut csprng);
let public_from_secret: VerifyingKey = (&secret).into(); let public_from_secret: VerifyingKey = (&secret).into();
@ -512,7 +512,7 @@ mod integrations {
#[test] #[test]
fn montgomery_and_edwards_conversion() { fn montgomery_and_edwards_conversion() {
let mut rng = rand::rngs::SysRng.unwrap_err(); let mut rng = UnwrapErr(SysRng);
let signing_key = SigningKey::generate(&mut rng); let signing_key = SigningKey::generate(&mut rng);
let verifying_key = signing_key.verifying_key(); let verifying_key = signing_key.verifying_key();

View file

@ -43,17 +43,17 @@ all-features = true
[dependencies] [dependencies]
curve25519-dalek = { version = "=5.0.0-pre.4", default-features = false } curve25519-dalek = { version = "=5.0.0-pre.4", default-features = false }
rand_core = { version = "0.10.0-rc-5", default-features = false } rand_core = { version = "0.10.0-rc-6", default-features = false }
# optional dependencies # optional dependencies
getrandom = { version = "0.4.0-rc.0", optional = true } getrandom = { version = "0.4.0-rc.1", optional = true }
serde = { version = "1", default-features = false, optional = true, features = ["derive"] } serde = { version = "1", default-features = false, optional = true, features = ["derive"] }
zeroize = { version = "1", default-features = false, optional = true } zeroize = { version = "1", default-features = false, optional = true }
[dev-dependencies] [dev-dependencies]
bincode = "1" bincode = "1"
criterion = "0.5" criterion = "0.5"
rand = "0.10.0-rc.7" getrandom = { version = "0.4.0-rc.1", features = ["sys_rng"] }
[[bench]] [[bench]]
name = "x25519" name = "x25519"

View file

@ -51,9 +51,9 @@ loudly meows `bob_public` back to Alice. Alice now computes her
shared secret with Bob by doing: shared secret with Bob by doing:
```rust ```rust
# use rand::{rngs::SysRng, TryRngCore}; # use getrandom::{SysRng, rand_core::UnwrapErr};
# use x25519_dalek::{EphemeralSecret, PublicKey}; # use x25519_dalek::{EphemeralSecret, PublicKey};
# let mut rng = SysRng.unwrap_err(); # let mut rng = UnwrapErr(SysRng);
# let alice_secret = EphemeralSecret::random_from_rng(&mut rng); # let alice_secret = EphemeralSecret::random_from_rng(&mut rng);
# let alice_public = PublicKey::from(&alice_secret); # let alice_public = PublicKey::from(&alice_secret);
# let bob_secret = EphemeralSecret::random_from_rng(&mut rng); # let bob_secret = EphemeralSecret::random_from_rng(&mut rng);
@ -64,9 +64,9 @@ let alice_shared_secret = alice_secret.diffie_hellman(&bob_public);
Similarly, Bob computes a shared secret by doing: Similarly, Bob computes a shared secret by doing:
```rust ```rust
# use rand::{rngs::SysRng, TryRngCore}; # use getrandom::{SysRng, rand_core::UnwrapErr};
# use x25519_dalek::{EphemeralSecret, PublicKey}; # use x25519_dalek::{EphemeralSecret, PublicKey};
# let mut rng = SysRng.unwrap_err(); # let mut rng = UnwrapErr(SysRng);
# let alice_secret = EphemeralSecret::random_from_rng(&mut rng); # let alice_secret = EphemeralSecret::random_from_rng(&mut rng);
# let alice_public = PublicKey::from(&alice_secret); # let alice_public = PublicKey::from(&alice_secret);
# let bob_secret = EphemeralSecret::random_from_rng(&mut rng); # let bob_secret = EphemeralSecret::random_from_rng(&mut rng);
@ -77,9 +77,9 @@ let bob_shared_secret = bob_secret.diffie_hellman(&alice_public);
These secrets are the same: These secrets are the same:
```rust ```rust
# use rand::{rngs::SysRng, TryRngCore}; # use getrandom::{SysRng, rand_core::UnwrapErr};
# use x25519_dalek::{EphemeralSecret, PublicKey}; # use x25519_dalek::{EphemeralSecret, PublicKey};
# let mut rng = SysRng.unwrap_err(); # let mut rng = UnwrapErr(SysRng);
# let alice_secret = EphemeralSecret::random_from_rng(&mut rng); # let alice_secret = EphemeralSecret::random_from_rng(&mut rng);
# let alice_public = PublicKey::from(&alice_secret); # let alice_public = PublicKey::from(&alice_secret);
# let bob_secret = EphemeralSecret::random_from_rng(&mut rng); # let bob_secret = EphemeralSecret::random_from_rng(&mut rng);

View file

@ -13,25 +13,25 @@
use criterion::{Criterion, criterion_group, criterion_main}; use criterion::{Criterion, criterion_group, criterion_main};
use rand::{TryRngCore, rngs::SysRng}; use getrandom::{SysRng, rand_core::UnwrapErr};
use x25519_dalek::EphemeralSecret; use x25519_dalek::EphemeralSecret;
use x25519_dalek::PublicKey; use x25519_dalek::PublicKey;
fn bench_diffie_hellman(c: &mut Criterion) { fn bench_diffie_hellman(c: &mut Criterion) {
let bob_secret = EphemeralSecret::random_from_rng(&mut SysRng.unwrap_err()); let bob_secret = EphemeralSecret::random_from_rng(&mut UnwrapErr(SysRng));
let bob_public = PublicKey::from(&bob_secret); let bob_public = PublicKey::from(&bob_secret);
c.bench_function("diffie_hellman", move |b| { c.bench_function("diffie_hellman", move |b| {
b.iter_with_setup( b.iter_with_setup(
|| EphemeralSecret::random_from_rng(&mut SysRng.unwrap_err()), || EphemeralSecret::random_from_rng(&mut UnwrapErr(SysRng)),
|alice_secret| alice_secret.diffie_hellman(&bob_public), |alice_secret| alice_secret.diffie_hellman(&bob_public),
) )
}); });
} }
fn bench_pubkey_constructor(c: &mut Criterion) { fn bench_pubkey_constructor(c: &mut Criterion) {
let bob_secret = EphemeralSecret::random_from_rng(&mut SysRng.unwrap_err()); let bob_secret = EphemeralSecret::random_from_rng(&mut UnwrapErr(SysRng));
c.bench_function("PublicKey::from", move |b| { c.bench_function("PublicKey::from", move |b| {
b.iter(|| PublicKey::from(&bob_secret)) b.iter(|| PublicKey::from(&bob_secret))

View file

@ -363,13 +363,13 @@ impl ZeroizeOnDrop for SharedSecret {}
/// # Example /// # Example
#[cfg_attr(feature = "static_secrets", doc = "```")] #[cfg_attr(feature = "static_secrets", doc = "```")]
#[cfg_attr(not(feature = "static_secrets"), doc = "```ignore")] #[cfg_attr(not(feature = "static_secrets"), doc = "```ignore")]
/// use rand::{rngs::SysRng, RngCore, TryRngCore}; /// use getrandom::{SysRng, rand_core::UnwrapErr};
/// ///
/// use x25519_dalek::x25519; /// use x25519_dalek::x25519;
/// use x25519_dalek::StaticSecret; /// use x25519_dalek::StaticSecret;
/// use x25519_dalek::PublicKey; /// use x25519_dalek::PublicKey;
/// ///
/// let mut rng = SysRng.unwrap_err(); /// let mut rng = UnwrapErr(SysRng);
/// ///
/// // Generate Alice's key pair. /// // Generate Alice's key pair.
/// let alice_secret = StaticSecret::random_from_rng(&mut rng); /// let alice_secret = StaticSecret::random_from_rng(&mut rng);

View file

@ -239,26 +239,26 @@ fn rfc7748_ladder_test2() {
); );
} }
mod os_rng { mod sys_rng {
use super::*; use super::*;
use rand::{TryRngCore, rngs::SysRng}; use ::getrandom::{SysRng, rand_core::UnwrapErr};
#[test] #[test]
fn ephemeral_from_rng() { fn ephemeral_from_rng() {
EphemeralSecret::random_from_rng(&mut SysRng.unwrap_err()); EphemeralSecret::random_from_rng(&mut UnwrapErr(SysRng));
} }
#[test] #[test]
#[cfg(feature = "reusable_secrets")] #[cfg(feature = "reusable_secrets")]
fn reusable_from_rng() { fn reusable_from_rng() {
ReusableSecret::random_from_rng(&mut SysRng.unwrap_err()); ReusableSecret::random_from_rng(&mut UnwrapErr(SysRng));
} }
#[test] #[test]
#[cfg(feature = "static_secrets")] #[cfg(feature = "static_secrets")]
fn static_from_rng() { fn static_from_rng() {
StaticSecret::random_from_rng(&mut SysRng.unwrap_err()); StaticSecret::random_from_rng(&mut UnwrapErr(SysRng));
} }
} }