mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-11-17 08:55:45 +00:00
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:
parent
56a6bc07b8
commit
b7531ca318
22 changed files with 157 additions and 155 deletions
|
|
@ -30,12 +30,12 @@ rustdoc-args = [
|
|||
all-features = true
|
||||
|
||||
[dev-dependencies]
|
||||
sha2 = { version = "0.11.0-rc.3", default-features = false }
|
||||
bincode = "1"
|
||||
criterion = { version = "0.5", features = ["html_reports"] }
|
||||
getrandom = { version = "0.4.0-rc.1", features = ["sys_rng"] }
|
||||
hex = "0.4.2"
|
||||
proptest = "1"
|
||||
rand = "0.10.0-rc.7"
|
||||
sha2 = { version = "0.11.0-rc.4", default-features = false }
|
||||
|
||||
[build-dependencies]
|
||||
rustc_version = "0.4.0"
|
||||
|
|
@ -47,10 +47,10 @@ required-features = ["alloc", "rand_core"]
|
|||
|
||||
[dependencies]
|
||||
cfg-if = "1"
|
||||
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-5", default-features = false, optional = true }
|
||||
digest = { version = "0.11.0-rc.4", default-features = false, optional = true, features = [
|
||||
ff = { version = "=0.14.0-pre.1", package = "rustcrypto-ff", 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-6", default-features = false, optional = true }
|
||||
digest = { version = "0.11.0-rc.8", default-features = false, optional = true, features = [
|
||||
"block-api",
|
||||
] }
|
||||
subtle = { version = "2.6.0", default-features = false, features = [
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use rand::{RngCore, TryRngCore, rng, rngs::SysRng};
|
||||
use getrandom::SysRng;
|
||||
use rand_core::{Rng, UnwrapErr};
|
||||
|
||||
use criterion::{
|
||||
BatchSize, BenchmarkGroup, BenchmarkId, Criterion, criterion_main, measurement::Measurement,
|
||||
|
|
@ -31,7 +32,7 @@ mod edwards_benches {
|
|||
BenchmarkId::new("Batch EdwardsPoint compression", batch_size),
|
||||
&batch_size,
|
||||
|b, &size| {
|
||||
let mut rng = SysRng.unwrap_err();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
let points: Vec<EdwardsPoint> =
|
||||
(0..size).map(|_| EdwardsPoint::random(&mut rng)).collect();
|
||||
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>) {
|
||||
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));
|
||||
bench.iter_batched(
|
||||
|| (Scalar::random(&mut rng), Scalar::random(&mut rng)),
|
||||
|
|
@ -76,7 +77,7 @@ mod edwards_benches {
|
|||
|
||||
#[cfg(feature = "digest")]
|
||||
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 domain_sep = [0u8; 32];
|
||||
|
|
@ -91,7 +92,7 @@ mod edwards_benches {
|
|||
|
||||
#[cfg(feature = "digest")]
|
||||
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 domain_sep = [0u8; 32];
|
||||
|
|
@ -130,12 +131,12 @@ mod multiscalar_benches {
|
|||
use curve25519_dalek::traits::VartimePrecomputedMultiscalarMul;
|
||||
|
||||
fn construct_scalars(n: usize) -> Vec<Scalar> {
|
||||
let mut rng = rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
(0..n).map(|_| Scalar::random(&mut rng)).collect()
|
||||
}
|
||||
|
||||
fn construct_points(n: usize) -> Vec<EdwardsPoint> {
|
||||
let mut rng = rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
(0..n)
|
||||
.map(|_| EdwardsPoint::mul_base(&Scalar::random(&mut rng)))
|
||||
.collect()
|
||||
|
|
@ -353,7 +354,7 @@ mod scalar_benches {
|
|||
use super::*;
|
||||
|
||||
fn scalar_arith<M: Measurement>(c: &mut BenchmarkGroup<M>) {
|
||||
let mut rng = rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
c.bench_function("Scalar inversion", |b| {
|
||||
let s = Scalar::from(897987897u64).invert();
|
||||
|
|
@ -388,7 +389,7 @@ mod scalar_benches {
|
|||
BenchmarkId::new("Batch scalar inversion", *batch_size),
|
||||
&batch_size,
|
||||
|b, &&size| {
|
||||
let mut rng = SysRng.unwrap_err();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
let scalars: Vec<Scalar> =
|
||||
(0..size).map(|_| Scalar::random(&mut rng)).collect();
|
||||
b.iter(|| {
|
||||
|
|
|
|||
|
|
@ -113,12 +113,12 @@ use digest::{
|
|||
#[cfg(feature = "group")]
|
||||
use {
|
||||
group::{GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup},
|
||||
rand_core::TryRngCore,
|
||||
rand_core::TryRng,
|
||||
subtle::CtOption,
|
||||
};
|
||||
|
||||
#[cfg(feature = "rand_core")]
|
||||
use rand_core::RngCore;
|
||||
use rand_core::Rng;
|
||||
|
||||
use subtle::Choice;
|
||||
use subtle::ConditionallyNegatable;
|
||||
|
|
@ -753,7 +753,7 @@ impl EdwardsPoint {
|
|||
///
|
||||
/// # Inputs
|
||||
///
|
||||
/// * `rng`: any RNG which implements `RngCore`
|
||||
/// * `rng`: any RNG which implements `Rng`
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
|
|
@ -764,7 +764,7 @@ impl EdwardsPoint {
|
|||
/// Uses rejection sampling, generating a random `CompressedEdwardsY` and then attempting point
|
||||
/// decompression, rejecting invalid points.
|
||||
#[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]);
|
||||
loop {
|
||||
rng.fill_bytes(&mut repr.0);
|
||||
|
|
@ -1461,7 +1461,7 @@ impl Debug for EdwardsPoint {
|
|||
impl group::Group for EdwardsPoint {
|
||||
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]);
|
||||
loop {
|
||||
rng.try_fill_bytes(&mut repr.0)?;
|
||||
|
|
@ -1713,7 +1713,7 @@ impl Zeroize for SubgroupPoint {
|
|||
impl group::Group for SubgroupPoint {
|
||||
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;
|
||||
|
||||
// This will almost never loop, but `Group::random` is documented as returning a
|
||||
|
|
@ -1790,8 +1790,10 @@ impl CofactorGroup for EdwardsPoint {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
use rand::TryRngCore;
|
||||
use getrandom::{
|
||||
SysRng,
|
||||
rand_core::{TryRng, UnwrapErr},
|
||||
};
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
use alloc::vec::Vec;
|
||||
|
|
@ -2080,7 +2082,7 @@ mod test {
|
|||
/// Check that mul_base_clamped and mul_clamped agree
|
||||
#[test]
|
||||
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.
|
||||
#[cfg(feature = "precomputed-tables")]
|
||||
|
|
@ -2201,7 +2203,7 @@ mod test {
|
|||
#[cfg(feature = "rand_core")]
|
||||
#[test]
|
||||
fn compress_batch() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
// TODO(tarcieri): proptests?
|
||||
|
||||
|
|
@ -2272,7 +2274,7 @@ mod test {
|
|||
// A single iteration of a consistency check for MSM.
|
||||
#[cfg(all(feature = "alloc", feature = "rand_core"))]
|
||||
fn multiscalar_consistency_iter(n: usize) {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
// Construct random coefficients x0, ..., x_{n-1},
|
||||
// followed by some extra hardcoded ones.
|
||||
|
|
@ -2335,7 +2337,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(all(feature = "alloc", feature = "rand_core"))]
|
||||
fn batch_to_montgomery() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
let scalars = (0..128)
|
||||
.map(|_| Scalar::random(&mut rng))
|
||||
|
|
@ -2360,7 +2362,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(all(feature = "alloc", feature = "rand_core"))]
|
||||
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
let static_scalars = (0..128)
|
||||
.map(|_| Scalar::random(&mut rng))
|
||||
|
|
|
|||
|
|
@ -220,7 +220,8 @@ impl RistrettoPoint {
|
|||
mod test {
|
||||
use super::*;
|
||||
use crate::{edwards::EdwardsPoint, ristretto::CompressedRistretto};
|
||||
use rand_core::RngCore;
|
||||
use getrandom::{SysRng, rand_core::UnwrapErr};
|
||||
use rand_core::Rng;
|
||||
use sha2::Sha256;
|
||||
|
||||
/// Return the coset self + E\[4\]
|
||||
|
|
@ -281,7 +282,7 @@ mod test {
|
|||
// Tests that lizard_decode of a random point is None
|
||||
#[test]
|
||||
fn lizard_invalid() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
for _ in 0..100 {
|
||||
let pt = RistrettoPoint::random(&mut rng);
|
||||
assert!(
|
||||
|
|
@ -297,7 +298,7 @@ mod test {
|
|||
// is the identity
|
||||
#[test]
|
||||
fn elligator_inv() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
for i in 0..100 {
|
||||
let mut fe_bytes = [0u8; 32];
|
||||
|
|
@ -342,7 +343,7 @@ mod test {
|
|||
// Tests that map_to_curve ○ map_to_curve_inverse is the identity
|
||||
#[test]
|
||||
fn map_to_curve_inverse() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
for _ in 0..100 {
|
||||
let mut input = [0u8; 32];
|
||||
|
|
@ -365,7 +366,7 @@ mod test {
|
|||
// return value in the first 8 elements
|
||||
#[test]
|
||||
fn map_pos_felem_to_curve_inverse() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
for _ in 0..100 {
|
||||
let mut input = [0u8; 32];
|
||||
|
|
|
|||
|
|
@ -514,10 +514,13 @@ impl Mul<&MontgomeryPoint> for &Scalar {
|
|||
mod test {
|
||||
use super::*;
|
||||
use crate::constants;
|
||||
use getrandom::{
|
||||
SysRng,
|
||||
rand_core::{Rng, TryRng, UnwrapErr},
|
||||
};
|
||||
|
||||
#[cfg(feature = "rand_core")]
|
||||
use rand::CryptoRng;
|
||||
use rand::{RngCore, TryRngCore};
|
||||
use rand_core::CryptoRng;
|
||||
|
||||
#[test]
|
||||
fn identity_in_different_coordinates() {
|
||||
|
|
@ -622,7 +625,7 @@ mod test {
|
|||
#[cfg(feature = "rand_core")]
|
||||
#[test]
|
||||
fn montgomery_ladder_matches_edwards_scalarmult() {
|
||||
let mut csprng = rand::rngs::SysRng.unwrap_err();
|
||||
let mut csprng = UnwrapErr(SysRng);
|
||||
|
||||
for _ in 0..100 {
|
||||
let p_edwards = rand_prime_order_point(&mut csprng);
|
||||
|
|
@ -641,7 +644,7 @@ mod test {
|
|||
#[cfg(feature = "rand_core")]
|
||||
#[test]
|
||||
fn montgomery_mul_bits_be() {
|
||||
let mut csprng = rand::rngs::SysRng.unwrap_err();
|
||||
let mut csprng = UnwrapErr(SysRng);
|
||||
|
||||
for _ in 0..100 {
|
||||
// Make a random prime-order point P
|
||||
|
|
@ -666,7 +669,7 @@ mod test {
|
|||
// integers b₁, b₂ and random (curve or twist) point P.
|
||||
#[test]
|
||||
fn montgomery_mul_bits_be_twist() {
|
||||
let mut csprng = rand::rngs::SysRng.unwrap_err();
|
||||
let mut csprng = UnwrapErr(SysRng);
|
||||
|
||||
for _ in 0..100 {
|
||||
// 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
|
||||
#[test]
|
||||
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.
|
||||
let a_bytes = [0xff; 32];
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ use crate::field::FieldElement;
|
|||
#[cfg(feature = "group")]
|
||||
use {
|
||||
group::{GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup},
|
||||
rand_core::TryRngCore,
|
||||
rand_core::TryRng,
|
||||
subtle::CtOption,
|
||||
};
|
||||
|
||||
|
|
@ -543,12 +543,12 @@ impl RistrettoPoint {
|
|||
#[cfg_attr(feature = "rand_core", doc = "```")]
|
||||
#[cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
|
||||
/// # 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
|
||||
/// # // See https://doc.rust-lang.org/book/documentation.html#documentation-as-tests
|
||||
/// # fn main() {
|
||||
/// let mut rng = SysRng.unwrap_err();
|
||||
/// let mut rng = UnwrapErr(SysRng);
|
||||
///
|
||||
/// let points: Vec<RistrettoPoint> =
|
||||
/// (0..32).map(|_| RistrettoPoint::random(&mut rng)).collect();
|
||||
|
|
@ -1179,7 +1179,7 @@ impl Debug for RistrettoPoint {
|
|||
impl group::Group for RistrettoPoint {
|
||||
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
|
||||
let mut uniform_bytes = [0u8; 64];
|
||||
rng.try_fill_bytes(&mut uniform_bytes)?;
|
||||
|
|
@ -1275,10 +1275,10 @@ impl Zeroize for RistrettoPoint {
|
|||
mod test {
|
||||
use super::*;
|
||||
use crate::edwards::CompressedEdwardsY;
|
||||
#[cfg(feature = "rand_core")]
|
||||
use getrandom::{SysRng, rand_core::UnwrapErr};
|
||||
#[cfg(feature = "group")]
|
||||
use proptest::prelude::*;
|
||||
#[cfg(feature = "rand_core")]
|
||||
use rand::{TryRngCore, rngs::SysRng};
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "serde")]
|
||||
|
|
@ -1472,7 +1472,7 @@ mod test {
|
|||
#[cfg(feature = "rand_core")]
|
||||
#[test]
|
||||
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_coset = P.coset4();
|
||||
for point in P_coset {
|
||||
|
|
@ -1483,7 +1483,7 @@ mod test {
|
|||
#[cfg(feature = "rand_core")]
|
||||
#[test]
|
||||
fn random_roundtrip() {
|
||||
let mut rng = SysRng.unwrap_err();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
for _ in 0..100 {
|
||||
let P = RistrettoPoint::mul_base(&Scalar::random(&mut rng));
|
||||
let compressed_P = P.compress();
|
||||
|
|
@ -1546,7 +1546,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(all(feature = "alloc", feature = "rand_core"))]
|
||||
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
let static_scalars = (0..128)
|
||||
.map(|_| Scalar::random(&mut rng))
|
||||
|
|
@ -1597,7 +1597,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(all(feature = "alloc", feature = "rand_core"))]
|
||||
fn partial_precomputed_mixed_multiscalar_empty() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
let n_static = 16;
|
||||
let n_dynamic = 8;
|
||||
|
|
@ -1640,7 +1640,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(all(feature = "alloc", feature = "rand_core"))]
|
||||
fn partial_precomputed_mixed_multiscalar() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
let n_static = 16;
|
||||
let n_dynamic = 8;
|
||||
|
|
@ -1685,7 +1685,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(all(feature = "alloc", feature = "rand_core"))]
|
||||
fn partial_precomputed_multiscalar() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
let n_static = 16;
|
||||
|
||||
|
|
@ -1714,7 +1714,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(all(feature = "alloc", feature = "rand_core"))]
|
||||
fn partial_precomputed_multiscalar_empty() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
let n_static = 16;
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ use group::ff::{Field, FromUniformBytes, PrimeField};
|
|||
use group::ff::{FieldBits, PrimeFieldBits};
|
||||
|
||||
#[cfg(feature = "group")]
|
||||
use rand_core::TryRngCore;
|
||||
use rand_core::TryRng;
|
||||
|
||||
#[cfg(feature = "rand_core")]
|
||||
use rand_core::CryptoRng;
|
||||
|
|
@ -582,10 +582,9 @@ impl Scalar {
|
|||
/// ```
|
||||
/// # fn main() {
|
||||
/// use curve25519_dalek::scalar::Scalar;
|
||||
/// use getrandom::{SysRng, rand_core::UnwrapErr};
|
||||
///
|
||||
/// use rand::{rngs::SysRng, TryRngCore};
|
||||
///
|
||||
/// let mut csprng = SysRng.unwrap_err();
|
||||
/// let mut csprng = UnwrapErr(SysRng);
|
||||
/// let a: Scalar = Scalar::random(&mut csprng);
|
||||
/// # }
|
||||
#[cfg(feature = "rand_core")]
|
||||
|
|
@ -1250,7 +1249,7 @@ impl Field for Scalar {
|
|||
const ZERO: Self = Self::ZERO;
|
||||
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
|
||||
let mut scalar_bytes = [0u8; 64];
|
||||
rng.try_fill_bytes(&mut scalar_bytes)?;
|
||||
|
|
@ -1430,7 +1429,10 @@ pub const fn clamp_integer(mut bytes: [u8; 32]) -> [u8; 32] {
|
|||
#[cfg(test)]
|
||||
pub(crate) mod test {
|
||||
use super::*;
|
||||
use rand::RngCore;
|
||||
use getrandom::{
|
||||
SysRng,
|
||||
rand_core::{Rng, UnwrapErr},
|
||||
};
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
use alloc::vec::Vec;
|
||||
|
|
@ -1592,7 +1594,7 @@ pub(crate) mod test {
|
|||
#[cfg(feature = "rand_core")]
|
||||
#[test]
|
||||
fn non_adjacent_form_random() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
for _ in 0..1_000 {
|
||||
let x = Scalar::random(&mut rng);
|
||||
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.
|
||||
#[test]
|
||||
fn test_mul_reduction_invariance() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
|
||||
for _ in 0..10 {
|
||||
// Also define c that's clamped. We'll make sure that clamping doesn't affect
|
||||
|
|
|
|||
|
|
@ -32,13 +32,13 @@ curve25519-dalek = { version = "=5.0.0-pre.4", default-features = false, feature
|
|||
"digest",
|
||||
] }
|
||||
ed25519 = { version = "3.0.0-rc.2", default-features = false }
|
||||
signature = { version = "3.0.0-rc.5", optional = true, default-features = false }
|
||||
sha2 = { version = "0.11.0-rc.3", default-features = false }
|
||||
signature = { version = "3.0.0-rc.9", optional = true, default-features = false }
|
||||
sha2 = { version = "0.11.0-rc.4", default-features = false }
|
||||
subtle = { version = "2.3.0", default-features = false }
|
||||
|
||||
# optional features
|
||||
keccak = { version = "0.2.0-rc.0", default-features = false, optional = true }
|
||||
rand_core = { version = "0.10.0-rc-5", default-features = false, optional = true }
|
||||
keccak = { version = "0.2.0-rc.1", 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 }
|
||||
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 = [
|
||||
"static_secrets",
|
||||
] }
|
||||
blake2 = "0.11.0-rc.3"
|
||||
sha3 = "0.11.0-rc.3"
|
||||
blake2 = "0.11.0-rc.4"
|
||||
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"
|
||||
bincode = "1.0"
|
||||
serde_json = "1.0"
|
||||
criterion = { version = "0.5", features = ["html_reports"] }
|
||||
hex-literal = "1"
|
||||
rand = { version = "0.10.0-rc.7", features = ["chacha"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
strobe-rs = "0.5"
|
||||
toml = { version = "0.9" }
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ mod ed25519_benches {
|
|||
use ed25519_dalek::Signature;
|
||||
use ed25519_dalek::Signer;
|
||||
use ed25519_dalek::SigningKey;
|
||||
use rand::prelude::ThreadRng;
|
||||
use rand::rng;
|
||||
use rand_core::prelude::ThreadRng;
|
||||
use rand_core::rng;
|
||||
|
||||
fn sign(c: &mut Criterion) {
|
||||
let mut csprng: ThreadRng = rng();
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ pub use curve25519_dalek::digest::Digest;
|
|||
|
||||
use transcript::Transcript;
|
||||
|
||||
use rand_core::RngCore;
|
||||
use rand_core::Rng;
|
||||
|
||||
use sha2::Sha512;
|
||||
|
||||
|
|
@ -44,12 +44,12 @@ use crate::signature::InternalSignature;
|
|||
/// but implement the same 1.0 protocol.
|
||||
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()`
|
||||
/// yields a PRG whose input is the hashed transcript.
|
||||
struct ZeroRng;
|
||||
|
||||
impl rand_core::TryRngCore for ZeroRng {
|
||||
impl rand_core::TryRng for ZeroRng {
|
||||
type Error = Infallible;
|
||||
|
||||
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 {}
|
||||
|
||||
// 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];
|
||||
rng.fill_bytes(&mut buf);
|
||||
u128::from_le_bytes(buf)
|
||||
|
|
@ -129,11 +129,10 @@ fn gen_u128<R: RngCore>(rng: &mut R) -> u128 {
|
|||
/// use ed25519_dalek::{
|
||||
/// verify_batch, SigningKey, VerifyingKey, Signer, Signature,
|
||||
/// };
|
||||
/// use rand::rngs::SysRng;
|
||||
/// use rand_core::TryRngCore;
|
||||
/// use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
///
|
||||
/// # 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 msg: &[u8] = b"They're good dogs Brant";
|
||||
/// let messages: Vec<_> = (0..64).map(|_| msg).collect();
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ impl TranscriptRngBuilder {
|
|||
/// transcript data.
|
||||
pub fn finalize<R>(mut self, rng: &mut R) -> TranscriptRng
|
||||
where
|
||||
R: rand_core::RngCore + rand_core::CryptoRng,
|
||||
R: rand_core::Rng + rand_core::CryptoRng,
|
||||
{
|
||||
let random_bytes = {
|
||||
let mut bytes = [0u8; 32];
|
||||
|
|
@ -186,7 +186,7 @@ pub struct TranscriptRng {
|
|||
strobe: Strobe128,
|
||||
}
|
||||
|
||||
impl rand_core::TryRngCore for TranscriptRng {
|
||||
impl rand_core::TryRng for TranscriptRng {
|
||||
type Error = Infallible;
|
||||
|
||||
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
|
||||
|
|
@ -309,8 +309,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn transcript_rng_is_bound_to_transcript_and_witnesses() {
|
||||
use chacha20::ChaCha8Rng;
|
||||
use curve25519_dalek::scalar::Scalar;
|
||||
use rand::{SeedableRng, rngs::ChaCha8Rng};
|
||||
use rand_core::SeedableRng;
|
||||
|
||||
// Check that the TranscriptRng is bound to the transcript and
|
||||
// the witnesses. This is done by producing a sequence of
|
||||
|
|
|
|||
|
|
@ -23,11 +23,10 @@ use crate::{InternalError, SignatureError};
|
|||
/// # fn main() {
|
||||
/// use ed25519_dalek::{Signature, SigningKey, VerifyingKey, Sha512};
|
||||
/// # use curve25519_dalek::digest::Digest;
|
||||
/// # use rand::rngs::SysRng;
|
||||
/// # use rand_core::TryRngCore;
|
||||
/// # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
/// use ed25519_dalek::{DigestSigner, DigestVerifier};
|
||||
///
|
||||
/// # let mut csprng = SysRng.unwrap_err();
|
||||
/// # let mut csprng = UnwrapErr(SysRng);
|
||||
/// # let signing_key = SigningKey::generate(&mut csprng);
|
||||
/// # let verifying_key = signing_key.verifying_key();
|
||||
/// let context_str = b"Local Channel 3";
|
||||
|
|
@ -91,13 +90,14 @@ mod test {
|
|||
|
||||
use crate::{Signature, SigningKey, VerifyingKey};
|
||||
use curve25519_dalek::digest::Digest;
|
||||
use rand::{TryRngCore, rngs::SysRng};
|
||||
use getrandom::SysRng;
|
||||
use rand_core::UnwrapErr;
|
||||
use sha2::Sha512;
|
||||
use signature::{DigestSigner, DigestVerifier};
|
||||
|
||||
#[test]
|
||||
fn context_correctness() {
|
||||
let mut csprng = SysRng.unwrap_err();
|
||||
let mut csprng = UnwrapErr(SysRng);
|
||||
let signing_key: SigningKey = SigningKey::generate(&mut csprng);
|
||||
let verifying_key: VerifyingKey = signing_key.verifying_key();
|
||||
|
||||
|
|
|
|||
|
|
@ -258,7 +258,10 @@ mod test {
|
|||
|
||||
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
|
||||
type CtxDigest = blake2::Blake2b512;
|
||||
|
|
@ -278,7 +281,7 @@ mod test {
|
|||
#[test]
|
||||
fn sign_verify_nonspec() {
|
||||
// Generate the keypair
|
||||
let mut rng = SysRng.unwrap_err();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
let esk = ExpandedSecretKey::random(&mut rng);
|
||||
let vk = VerifyingKey::from(&esk);
|
||||
|
||||
|
|
@ -297,7 +300,7 @@ mod test {
|
|||
use curve25519_dalek::digest::Digest;
|
||||
|
||||
// Generate the keypair
|
||||
let mut rng = SysRng.unwrap_err();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
let esk = ExpandedSecretKey::random(&mut rng);
|
||||
let vk = VerifyingKey::from(&esk);
|
||||
|
||||
|
|
@ -317,7 +320,7 @@ mod test {
|
|||
#[test]
|
||||
fn sign_byupdate() {
|
||||
// Generate the keypair
|
||||
let mut rng = SysRng.unwrap_err();
|
||||
let mut rng = UnwrapErr(SysRng);
|
||||
let esk = ExpandedSecretKey::random(&mut rng);
|
||||
let vk = VerifyingKey::from(&esk);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@
|
|||
#![cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
|
||||
//! # fn main() {
|
||||
//! // $ cargo add ed25519_dalek --features rand_core
|
||||
//! use rand::rngs::SysRng;
|
||||
//! use rand_core::TryRngCore;
|
||||
//! use getrandom::{SysRng, rand_core::UnwrapErr};
|
||||
//! use rand_core::TryRng;
|
||||
//! use ed25519_dalek::SigningKey;
|
||||
//! use ed25519_dalek::Signature;
|
||||
//!
|
||||
//! let mut csprng = SysRng.unwrap_err();
|
||||
//! let mut csprng = UnwrapErr(SysRng);
|
||||
//! let signing_key: SigningKey = SigningKey::generate(&mut csprng);
|
||||
//! # }
|
||||
//! ```
|
||||
|
|
@ -37,10 +37,9 @@
|
|||
#![cfg_attr(feature = "rand_core", doc = "```")]
|
||||
#![cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
|
||||
//! # fn main() {
|
||||
//! # use rand::rngs::SysRng;
|
||||
//! # use rand_core::TryRngCore;
|
||||
//! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
//! # use ed25519_dalek::SigningKey;
|
||||
//! # let mut csprng = SysRng.unwrap_err();
|
||||
//! # let mut csprng = UnwrapErr(SysRng);
|
||||
//! # let signing_key: SigningKey = SigningKey::generate(&mut csprng);
|
||||
//! use ed25519_dalek::{Signature, Signer};
|
||||
//! 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(not(feature = "rand_core"), doc = "```ignore")]
|
||||
//! # fn main() {
|
||||
//! # use rand::rngs::SysRng;
|
||||
//! # use rand_core::TryRngCore;
|
||||
//! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
//! # 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 message: &[u8] = b"This is a test of the tsunami alert system.";
|
||||
//! # let signature: Signature = signing_key.sign(message);
|
||||
|
|
@ -72,13 +70,12 @@
|
|||
#![cfg_attr(feature = "rand_core", doc = "```")]
|
||||
#![cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
|
||||
//! # fn main() {
|
||||
//! # use rand::rngs::SysRng;
|
||||
//! # use rand_core::TryRngCore;
|
||||
//! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
//! # use ed25519_dalek::SigningKey;
|
||||
//! # use ed25519_dalek::Signature;
|
||||
//! # use ed25519_dalek::Signer;
|
||||
//! 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 message: &[u8] = b"This is a test of the tsunami alert system.";
|
||||
//! # let signature: Signature = signing_key.sign(message);
|
||||
|
|
@ -99,11 +96,10 @@
|
|||
#![cfg_attr(feature = "rand_core", doc = "```")]
|
||||
#![cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
|
||||
//! # fn main() {
|
||||
//! # use rand::rngs::SysRng;
|
||||
//! # use rand_core::TryRngCore;
|
||||
//! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
//! # use ed25519_dalek::{SigningKey, Signature, Signer, VerifyingKey};
|
||||
//! 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 message: &[u8] = b"This is a test of the tsunami alert system.";
|
||||
//! # let signature: Signature = signing_key.sign(message);
|
||||
|
|
@ -120,12 +116,11 @@
|
|||
#![cfg_attr(feature = "rand_core", doc = "```")]
|
||||
#![cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
|
||||
//! # use core::convert::{TryFrom, TryInto};
|
||||
//! # use rand::rngs::SysRng;
|
||||
//! # use rand_core::TryRngCore;
|
||||
//! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
//! # use ed25519_dalek::{SigningKey, Signature, Signer, VerifyingKey, SecretKey, SignatureError};
|
||||
//! # use ed25519_dalek::{PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH, KEYPAIR_LENGTH, SIGNATURE_LENGTH};
|
||||
//! # 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 message: &[u8] = b"This is a test of the tsunami alert system.";
|
||||
//! # let signature_orig: Signature = signing_key_orig.sign(message);
|
||||
|
|
@ -198,11 +193,10 @@
|
|||
#![cfg_attr(all(feature = "rand_core", feature = "serde"), doc = "```")]
|
||||
#![cfg_attr(not(all(feature = "rand_core", feature = "serde")), doc = "```ignore")]
|
||||
//! # fn main() {
|
||||
//! # use rand::rngs::SysRng;
|
||||
//! # use rand_core::TryRngCore;
|
||||
//! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
//! # use ed25519_dalek::{SigningKey, Signature, Signer, Verifier, VerifyingKey};
|
||||
//! use bincode::serialize;
|
||||
//! # let mut csprng = SysRng.unwrap_err();
|
||||
//! # let mut csprng = UnwrapErr(SysRng);
|
||||
//! # let signing_key: SigningKey = SigningKey::generate(&mut csprng);
|
||||
//! # let message: &[u8] = b"This is a test of the tsunami alert system.";
|
||||
//! # let signature: Signature = signing_key.sign(message);
|
||||
|
|
@ -220,13 +214,12 @@
|
|||
#![cfg_attr(all(feature = "rand_core", feature = "serde"), doc = "```")]
|
||||
#![cfg_attr(not(all(feature = "rand_core", feature = "serde")), doc = "```ignore")]
|
||||
//! # fn main() {
|
||||
//! # use rand::rngs::SysRng;
|
||||
//! # use rand_core::TryRngCore;
|
||||
//! # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
//! # use ed25519_dalek::{SigningKey, Signature, Signer, Verifier, VerifyingKey};
|
||||
//! # use bincode::serialize;
|
||||
//! use bincode::deserialize;
|
||||
//!
|
||||
//! # let mut csprng = SysRng.unwrap_err();
|
||||
//! # let mut csprng = UnwrapErr(SysRng);
|
||||
//! # let signing_key: SigningKey = SigningKey::generate(&mut csprng);
|
||||
//! let message: &[u8] = b"This is a test of the tsunami alert system.";
|
||||
//! # let signature: Signature = signing_key.sign(message);
|
||||
|
|
|
|||
|
|
@ -189,11 +189,10 @@ impl SigningKey {
|
|||
#[cfg_attr(feature = "rand_core", doc = "```")]
|
||||
#[cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
|
||||
/// # fn main() {
|
||||
/// use rand::rngs::SysRng;
|
||||
/// use rand_core::TryRngCore;
|
||||
/// use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
/// use ed25519_dalek::{Signature, SigningKey};
|
||||
///
|
||||
/// let mut csprng = SysRng.unwrap_err();
|
||||
/// let mut csprng = UnwrapErr(SysRng);
|
||||
/// let signing_key: SigningKey = SigningKey::generate(&mut csprng);
|
||||
/// # }
|
||||
/// ```
|
||||
|
|
@ -242,11 +241,10 @@ impl SigningKey {
|
|||
/// use ed25519_dalek::SigningKey;
|
||||
/// use ed25519_dalek::Signature;
|
||||
/// use sha2::Sha512;
|
||||
/// use rand::rngs::SysRng;
|
||||
/// use rand_core::TryRngCore;
|
||||
/// use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let mut csprng = SysRng.unwrap_err();
|
||||
/// let mut csprng = UnwrapErr(SysRng);
|
||||
/// let signing_key: SigningKey = SigningKey::generate(&mut csprng);
|
||||
/// 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::SignatureError;
|
||||
/// # use sha2::Sha512;
|
||||
/// # use rand::rngs::SysRng;
|
||||
/// # use rand_core::TryRngCore;
|
||||
/// # use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
/// #
|
||||
/// # 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 message: &[u8] = b"All I want is to pet all of the dogs.";
|
||||
/// # let mut prehashed: Sha512 = Sha512::new();
|
||||
|
|
@ -368,11 +365,10 @@ impl SigningKey {
|
|||
/// use ed25519_dalek::Signature;
|
||||
/// use ed25519_dalek::SignatureError;
|
||||
/// use sha2::Sha512;
|
||||
/// use rand::rngs::SysRng;
|
||||
/// use rand_core::TryRngCore;
|
||||
/// use getrandom::{SysRng, rand_core::{TryRng, UnwrapErr}};
|
||||
///
|
||||
/// # 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 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;
|
||||
|
||||
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> {
|
||||
|
|
|
|||
|
|
@ -710,7 +710,7 @@ impl<'d> Deserialize<'d> for VerifyingKey {
|
|||
type Value = VerifyingKey;
|
||||
|
||||
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> {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use hex_literal::hex;
|
|||
#[cfg(test)]
|
||||
mod vectors {
|
||||
use super::*;
|
||||
use getrandom::{SysRng, rand_core::UnwrapErr};
|
||||
|
||||
use curve25519_dalek::{
|
||||
constants::ED25519_BASEPOINT_POINT,
|
||||
|
|
@ -27,7 +28,6 @@ mod vectors {
|
|||
scalar::Scalar,
|
||||
traits::IsIdentity,
|
||||
};
|
||||
use rand::TryRngCore;
|
||||
|
||||
#[cfg(not(feature = "digest"))]
|
||||
use sha2::{Sha512, digest::Digest};
|
||||
|
|
@ -183,7 +183,7 @@ mod vectors {
|
|||
|
||||
// Pick a random 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);
|
||||
while s_candidate == Scalar::ZERO {
|
||||
s_candidate = Scalar::random(&mut rng);
|
||||
|
|
@ -295,7 +295,7 @@ mod vectors {
|
|||
#[cfg(feature = "rand_core")]
|
||||
mod integrations {
|
||||
use super::*;
|
||||
use rand::{TryRngCore, rngs::SysRng};
|
||||
use getrandom::{SysRng, rand_core::UnwrapErr};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[test]
|
||||
|
|
@ -305,7 +305,7 @@ mod integrations {
|
|||
let good: &[u8] = "test 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 verifying_key = signing_key.verifying_key();
|
||||
|
|
@ -346,7 +346,7 @@ mod integrations {
|
|||
fn sign_verify_digest_equivalence() {
|
||||
// TestSignVerify
|
||||
|
||||
let mut csprng = SysRng.unwrap_err();
|
||||
let mut csprng = UnwrapErr(SysRng);
|
||||
|
||||
let good: &[u8] = "test message".as_bytes();
|
||||
let bad: &[u8] = "wrong message".as_bytes();
|
||||
|
|
@ -391,7 +391,7 @@ mod integrations {
|
|||
let good: &[u8] = b"test 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
|
||||
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"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.", ];
|
||||
let mut csprng = SysRng.unwrap_err();
|
||||
let mut csprng = UnwrapErr(SysRng);
|
||||
let mut signing_keys: Vec<SigningKey> = Vec::new();
|
||||
let mut signatures: Vec<Signature> = Vec::new();
|
||||
|
||||
|
|
@ -485,7 +485,7 @@ mod integrations {
|
|||
|
||||
#[test]
|
||||
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 public_from_secret: VerifyingKey = (&secret).into();
|
||||
|
||||
|
|
@ -512,7 +512,7 @@ mod integrations {
|
|||
|
||||
#[test]
|
||||
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 verifying_key = signing_key.verifying_key();
|
||||
|
||||
|
|
|
|||
|
|
@ -43,17 +43,17 @@ all-features = true
|
|||
|
||||
[dependencies]
|
||||
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
|
||||
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"] }
|
||||
zeroize = { version = "1", default-features = false, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
bincode = "1"
|
||||
criterion = "0.5"
|
||||
rand = "0.10.0-rc.7"
|
||||
getrandom = { version = "0.4.0-rc.1", features = ["sys_rng"] }
|
||||
|
||||
[[bench]]
|
||||
name = "x25519"
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ loudly meows `bob_public` back to Alice. Alice now computes her
|
|||
shared secret with Bob by doing:
|
||||
|
||||
```rust
|
||||
# use rand::{rngs::SysRng, TryRngCore};
|
||||
# use getrandom::{SysRng, rand_core::UnwrapErr};
|
||||
# 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_public = PublicKey::from(&alice_secret);
|
||||
# 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:
|
||||
|
||||
```rust
|
||||
# use rand::{rngs::SysRng, TryRngCore};
|
||||
# use getrandom::{SysRng, rand_core::UnwrapErr};
|
||||
# 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_public = PublicKey::from(&alice_secret);
|
||||
# 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:
|
||||
|
||||
```rust
|
||||
# use rand::{rngs::SysRng, TryRngCore};
|
||||
# use getrandom::{SysRng, rand_core::UnwrapErr};
|
||||
# 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_public = PublicKey::from(&alice_secret);
|
||||
# let bob_secret = EphemeralSecret::random_from_rng(&mut rng);
|
||||
|
|
|
|||
|
|
@ -13,25 +13,25 @@
|
|||
|
||||
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::PublicKey;
|
||||
|
||||
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);
|
||||
|
||||
c.bench_function("diffie_hellman", move |b| {
|
||||
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),
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
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| {
|
||||
b.iter(|| PublicKey::from(&bob_secret))
|
||||
|
|
|
|||
|
|
@ -363,13 +363,13 @@ impl ZeroizeOnDrop for SharedSecret {}
|
|||
/// # Example
|
||||
#[cfg_attr(feature = "static_secrets", doc = "```")]
|
||||
#[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::StaticSecret;
|
||||
/// use x25519_dalek::PublicKey;
|
||||
///
|
||||
/// let mut rng = SysRng.unwrap_err();
|
||||
/// let mut rng = UnwrapErr(SysRng);
|
||||
///
|
||||
/// // Generate Alice's key pair.
|
||||
/// let alice_secret = StaticSecret::random_from_rng(&mut rng);
|
||||
|
|
|
|||
|
|
@ -239,26 +239,26 @@ fn rfc7748_ladder_test2() {
|
|||
);
|
||||
}
|
||||
|
||||
mod os_rng {
|
||||
mod sys_rng {
|
||||
|
||||
use super::*;
|
||||
use rand::{TryRngCore, rngs::SysRng};
|
||||
use ::getrandom::{SysRng, rand_core::UnwrapErr};
|
||||
|
||||
#[test]
|
||||
fn ephemeral_from_rng() {
|
||||
EphemeralSecret::random_from_rng(&mut SysRng.unwrap_err());
|
||||
EphemeralSecret::random_from_rng(&mut UnwrapErr(SysRng));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "reusable_secrets")]
|
||||
fn reusable_from_rng() {
|
||||
ReusableSecret::random_from_rng(&mut SysRng.unwrap_err());
|
||||
ReusableSecret::random_from_rng(&mut UnwrapErr(SysRng));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "static_secrets")]
|
||||
fn static_from_rng() {
|
||||
StaticSecret::random_from_rng(&mut SysRng.unwrap_err());
|
||||
StaticSecret::random_from_rng(&mut UnwrapErr(SysRng));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue