Skip to content

Commit 23d0d2c

Browse files
authored
Bump rand_core from v0.9 to v0.10.0-rc-2 (#842)
Prior to a final stable release of the @RustCrypto dependencies used by the dalek crates, we are going to target `rand_core` v0.10. This updates the `rand` and `rand_core` dependencies as well as the aforementioned @RustCrypto dependencies to be compatible with `rand_core` v0.10, which incurred a few API changes: - `rand_core` no longer includes `OsRng`, so this replaces the `os_rng` features with `getrandom` features (same thing we did for @RustCrypto) which uses the `getrandom` crate directly - For `dev-dependencies` it just migrates straight to `rand`, replacing `rand_chacha` with the `chacha` feature of `rand` (which pulls in `chacha20`), and sourcing `OsRng` from `rand`, its new home (for now) This PR also switches to using the `rustcrypto-ff`/`rustcrypto-group` crates (hopefully temporary) which are forks of `ff` and `group` which have crate releases that have been updated to use `rand_core` v0.10.0 prereleases.
1 parent 9e04a58 commit 23d0d2c

File tree

16 files changed

+98
-87
lines changed

16 files changed

+98
-87
lines changed

.github/workflows/workspace.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
- name: no_std / no feat ${{ matrix.crate }}
7979
run: cargo build -p ${{ matrix.crate }} --target thumbv7em-none-eabi --release --no-default-features
8080
- name: no_std / cargo hack ${{ matrix.crate }}
81-
run: cargo hack build -p ${{ matrix.crate }} --target thumbv7em-none-eabi --release --each-feature --exclude-features default,std,os_rng
81+
run: cargo hack build -p ${{ matrix.crate }} --target thumbv7em-none-eabi --release --each-feature --exclude-features default,std,getrandom
8282

8383
clippy:
8484
name: Check that clippy is happy

curve25519-dalek/Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ features = [
3737
]
3838

3939
[dev-dependencies]
40-
sha2 = { version = "0.11.0-rc.2", default-features = false }
40+
sha2 = { version = "0.11.0-rc.3", default-features = false }
4141
bincode = "1"
4242
criterion = { version = "0.5", features = ["html_reports"] }
4343
hex = "0.4.2"
4444
proptest = "1"
45-
rand = "0.9"
46-
rand_core = { version = "0.9", default-features = false, features = ["os_rng"] }
45+
rand = "0.10.0-rc.5"
4746

4847
[build-dependencies]
4948
rustc_version = "0.4.0"
@@ -55,10 +54,10 @@ required-features = ["alloc", "rand_core"]
5554

5655
[dependencies]
5756
cfg-if = "1"
58-
ff = { version = "=0.14.0-pre.0", default-features = false, optional = true }
59-
group = { version = "=0.14.0-pre.0", default-features = false, optional = true }
60-
rand_core = { version = "0.9", default-features = false, optional = true }
61-
digest = { version = "0.11.0-rc.1", default-features = false, optional = true, features = [
57+
ff = { version = "=0.14.0-pre.0", package = "rustcrypto-ff", default-features = false, optional = true }
58+
group = { version = "=0.14.0-pre.0", package = "rustcrypto-group", default-features = false, optional = true }
59+
rand_core = { version = "0.10.0-rc-2", default-features = false, optional = true }
60+
digest = { version = "0.11.0-rc.4", default-features = false, optional = true, features = [
6261
"block-api",
6362
] }
6463
subtle = { version = "2.6.0", default-features = false, features = [

curve25519-dalek/src/edwards.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ use {
117117
subtle::CtOption,
118118
};
119119

120-
#[cfg(any(test, feature = "rand_core"))]
120+
#[cfg(feature = "rand_core")]
121121
use rand_core::RngCore;
122122

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

1782-
use rand_core::TryRngCore;
1782+
use rand::TryRngCore;
17831783

17841784
#[cfg(feature = "alloc")]
17851785
use alloc::vec::Vec;
@@ -2068,7 +2068,7 @@ mod test {
20682068
/// Check that mul_base_clamped and mul_clamped agree
20692069
#[test]
20702070
fn mul_base_clamped() {
2071-
let mut csprng = rand_core::OsRng;
2071+
let mut csprng = rand::rngs::OsRng;
20722072

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

2185-
#[cfg(feature = "alloc")]
2185+
#[cfg(all(feature = "alloc", feature = "rand_core"))]
21862186
#[test]
21872187
fn compress_batch() {
21882188
let mut rng = rand::rng();
@@ -2239,7 +2239,7 @@ mod test {
22392239
}
22402240

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

@@ -2266,7 +2266,7 @@ mod test {
22662266
// parameters.
22672267

22682268
#[test]
2269-
#[cfg(feature = "alloc")]
2269+
#[cfg(all(feature = "alloc", feature = "rand_core"))]
22702270
fn multiscalar_consistency_n_100() {
22712271
let iters = 50;
22722272
for _ in 0..iters {
@@ -2275,7 +2275,7 @@ mod test {
22752275
}
22762276

22772277
#[test]
2278-
#[cfg(feature = "alloc")]
2278+
#[cfg(all(feature = "alloc", feature = "rand_core"))]
22792279
fn multiscalar_consistency_n_250() {
22802280
let iters = 50;
22812281
for _ in 0..iters {
@@ -2284,7 +2284,7 @@ mod test {
22842284
}
22852285

22862286
#[test]
2287-
#[cfg(feature = "alloc")]
2287+
#[cfg(all(feature = "alloc", feature = "rand_core"))]
22882288
fn multiscalar_consistency_n_500() {
22892289
let iters = 50;
22902290
for _ in 0..iters {
@@ -2293,7 +2293,7 @@ mod test {
22932293
}
22942294

22952295
#[test]
2296-
#[cfg(feature = "alloc")]
2296+
#[cfg(all(feature = "alloc", feature = "rand_core"))]
22972297
fn multiscalar_consistency_n_1000() {
22982298
let iters = 50;
22992299
for _ in 0..iters {
@@ -2302,7 +2302,7 @@ mod test {
23022302
}
23032303

23042304
#[test]
2305-
#[cfg(feature = "alloc")]
2305+
#[cfg(all(feature = "alloc", feature = "rand_core"))]
23062306
fn batch_to_montgomery() {
23072307
let mut rng = rand::rng();
23082308

@@ -2327,7 +2327,7 @@ mod test {
23272327
}
23282328

23292329
#[test]
2330-
#[cfg(feature = "alloc")]
2330+
#[cfg(all(feature = "alloc", feature = "rand_core"))]
23312331
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
23322332
let mut rng = rand::rng();
23332333

curve25519-dalek/src/montgomery.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,9 @@ mod test {
515515
use super::*;
516516
use crate::constants;
517517

518-
use rand_core::{CryptoRng, RngCore, TryRngCore};
518+
#[cfg(feature = "rand_core")]
519+
use rand::CryptoRng;
520+
use rand::{RngCore, TryRngCore};
519521

520522
#[test]
521523
fn identity_in_different_coordinates() {
@@ -599,6 +601,7 @@ mod test {
599601
}
600602

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

622+
#[cfg(feature = "rand_core")]
619623
#[test]
620624
fn montgomery_ladder_matches_edwards_scalarmult() {
621-
let mut csprng = rand_core::OsRng.unwrap_err();
625+
let mut csprng = rand::rngs::OsRng.unwrap_err();
622626

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

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

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

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

699704
// Test agreement on a large integer. Even after clamping, this is not reduced mod l.
700705
let a_bytes = [0xff; 32];

curve25519-dalek/src/ristretto.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ use {
184184
subtle::CtOption,
185185
};
186186

187-
#[cfg(any(test, feature = "rand_core"))]
187+
#[cfg(feature = "rand_core")]
188188
use {
189189
core::convert::Infallible,
190190
rand_core::{CryptoRng, TryCryptoRng},
@@ -543,7 +543,7 @@ impl RistrettoPoint {
543543
#[cfg_attr(feature = "rand_core", doc = "```")]
544544
#[cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
545545
/// # use curve25519_dalek::ristretto::RistrettoPoint;
546-
/// use rand_core::{OsRng, TryRngCore};
546+
/// use rand::{rngs::OsRng, TryRngCore};
547547
///
548548
/// # // Need fn main() here in comment so the doctest compiles
549549
/// # // See https://doc.rust-lang.org/book/documentation.html#documentation-as-tests
@@ -656,7 +656,6 @@ impl RistrettoPoint {
656656
]
657657
}
658658

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

682-
#[cfg(any(test, feature = "rand_core"))]
683682
/// Return a `RistrettoPoint` chosen uniformly at random using a user-provided RNG.
684683
///
685684
/// # Inputs
@@ -696,6 +695,7 @@ impl RistrettoPoint {
696695
/// discrete log of the output point with respect to any other
697696
/// point should be unknown. The map is applied twice and the
698697
/// results are added, to ensure a uniform distribution.
698+
#[cfg(feature = "rand_core")]
699699
pub fn try_from_rng<R: TryCryptoRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
700700
let mut uniform_bytes = [0u8; 64];
701701
rng.try_fill_bytes(&mut uniform_bytes)?;
@@ -1277,8 +1277,8 @@ mod test {
12771277
use crate::edwards::CompressedEdwardsY;
12781278
#[cfg(feature = "group")]
12791279
use proptest::prelude::*;
1280-
1281-
use rand_core::{OsRng, TryRngCore};
1280+
#[cfg(feature = "rand_core")]
1281+
use rand::{TryRngCore, rngs::OsRng};
12821282

12831283
#[test]
12841284
#[cfg(feature = "serde")]
@@ -1469,6 +1469,7 @@ mod test {
14691469
}
14701470
}
14711471

1472+
#[cfg(feature = "rand_core")]
14721473
#[test]
14731474
fn four_torsion_random() {
14741475
let mut rng = OsRng.unwrap_err();
@@ -1479,6 +1480,7 @@ mod test {
14791480
}
14801481
}
14811482

1483+
#[cfg(feature = "rand_core")]
14821484
#[test]
14831485
fn random_roundtrip() {
14841486
let mut rng = OsRng.unwrap_err();
@@ -1542,7 +1544,7 @@ mod test {
15421544
}
15431545

15441546
#[test]
1545-
#[cfg(feature = "alloc")]
1547+
#[cfg(all(feature = "alloc", feature = "rand_core"))]
15461548
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
15471549
let mut rng = rand::rng();
15481550

@@ -1593,7 +1595,7 @@ mod test {
15931595
}
15941596

15951597
#[test]
1596-
#[cfg(feature = "alloc")]
1598+
#[cfg(all(feature = "alloc", feature = "rand_core"))]
15971599
fn partial_precomputed_mixed_multiscalar_empty() {
15981600
let mut rng = rand::rng();
15991601

@@ -1636,7 +1638,7 @@ mod test {
16361638
}
16371639

16381640
#[test]
1639-
#[cfg(feature = "alloc")]
1641+
#[cfg(all(feature = "alloc", feature = "rand_core"))]
16401642
fn partial_precomputed_mixed_multiscalar() {
16411643
let mut rng = rand::rng();
16421644

@@ -1681,7 +1683,7 @@ mod test {
16811683
}
16821684

16831685
#[test]
1684-
#[cfg(feature = "alloc")]
1686+
#[cfg(all(feature = "alloc", feature = "rand_core"))]
16851687
fn partial_precomputed_multiscalar() {
16861688
let mut rng = rand::rng();
16871689

@@ -1710,7 +1712,7 @@ mod test {
17101712
}
17111713

17121714
#[test]
1713-
#[cfg(feature = "alloc")]
1715+
#[cfg(all(feature = "alloc", feature = "rand_core"))]
17141716
fn partial_precomputed_multiscalar_empty() {
17151717
let mut rng = rand::rng();
17161718

curve25519-dalek/src/scalar.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ use group::ff::{FieldBits, PrimeFieldBits};
130130
#[cfg(feature = "group")]
131131
use rand_core::TryRngCore;
132132

133-
#[cfg(any(test, feature = "rand_core"))]
133+
#[cfg(feature = "rand_core")]
134134
use rand_core::CryptoRng;
135135

136136
#[cfg(feature = "digest")]
@@ -567,7 +567,6 @@ impl Scalar {
567567
],
568568
};
569569

570-
#[cfg(any(test, feature = "rand_core"))]
571570
/// Return a `Scalar` chosen uniformly at random using a user-provided RNG.
572571
///
573572
/// # Inputs
@@ -584,11 +583,12 @@ impl Scalar {
584583
/// # fn main() {
585584
/// use curve25519_dalek::scalar::Scalar;
586585
///
587-
/// use rand_core::{OsRng, TryRngCore};
586+
/// use rand::{rngs::OsRng, TryRngCore};
588587
///
589588
/// let mut csprng = OsRng.unwrap_err();
590589
/// let a: Scalar = Scalar::random(&mut csprng);
591590
/// # }
591+
#[cfg(feature = "rand_core")]
592592
pub fn random<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
593593
let mut scalar_bytes = [0u8; 64];
594594
rng.fill_bytes(&mut scalar_bytes);
@@ -1430,7 +1430,7 @@ pub const fn clamp_integer(mut bytes: [u8; 32]) -> [u8; 32] {
14301430
#[cfg(test)]
14311431
pub(crate) mod test {
14321432
use super::*;
1433-
use rand_core::RngCore;
1433+
use rand::RngCore;
14341434

14351435
#[cfg(feature = "alloc")]
14361436
use alloc::vec::Vec;
@@ -1570,6 +1570,7 @@ pub(crate) mod test {
15701570
}
15711571
}
15721572

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

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

1592+
#[cfg(feature = "rand_core")]
15911593
#[test]
15921594
fn non_adjacent_form_random() {
15931595
let mut rng = rand::rng();

0 commit comments

Comments
 (0)