From 6bd03e6ef63d8d3cd42d03ab20f7477242e4deb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=A8Jeff?= <¨burdges@gnunet.org¨> Date: Wed, 6 Sep 2023 10:30:28 +0200 Subject: [PATCH] Replaces rand_core::OsRng with rand::thread_rng() --- Cargo.toml | 7 ++++--- src/lib.rs | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5910214..1578607 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "schnorrkel" -version = "0.11.0" +version = "0.11.1" authors = ["Jeff Burdges "] readme = "README.md" license = "BSD-3-Clause" @@ -21,6 +21,7 @@ curve25519-dalek = { version = "4.1.0", default-features = false, features = ["d subtle = { version = "2.5.0", default-features = false } merlin = { version = "3.0.0", default-features = false } rand_core = { version = "0.6.2", default-features = false } +rand = { version = "0.8.5", default-features = false, features = ["std_rng"], optional = true } serde_crate = { version = "1.0.130", package = "serde", default-features = false, optional = true } serde_bytes = { version = "0.11.5", default-features = false, optional = true } cfg-if = { version = "1.0.0", optional = true } @@ -46,12 +47,12 @@ default = ["std", "getrandom"] preaudit_deprecated = [] nightly = [] alloc = ["curve25519-dalek/alloc", "rand_core/alloc", "serde_bytes/alloc"] -std = ["alloc", "getrandom", "serde_bytes/std"] +std = ["alloc", "getrandom", "serde_bytes/std", "rand"] asm = ["sha2/asm"] serde = ["serde_crate", "serde_bytes", "cfg-if"] # We cannot make getrandom a direct dependency because rand_core makes # getrandom a feature name, which requires forwarding. -getrandom = ["rand_core/getrandom"] +getrandom = ["rand_core/getrandom", "rand/std_rng"] # We thus cannot forward the wasm-bindgen feature of getrandom, # but our consumers could depend upon getrandom and activate its # wasm-bindgen feature themselve, which works due to cargo features diff --git a/src/lib.rs b/src/lib.rs index a0da3bf..b05b28c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -224,11 +224,16 @@ extern crate alloc; use rand_core::{RngCore,CryptoRng}; use curve25519_dalek::scalar::Scalar; -#[cfg(feature = "getrandom")] +#[cfg(all( feature = "getrandom", not(feature = "std") ))] fn rand_hack() -> impl RngCore+CryptoRng { rand_core::OsRng } +#[cfg(all( feature = "getrandom", feature = "std" ))] +fn rand_hack() -> impl RngCore+CryptoRng { + rand::thread_rng() +} + #[cfg(not(feature = "getrandom"))] fn rand_hack() -> impl RngCore+CryptoRng { const PRM: &'static str = "Attempted to use functionality that requires system randomness!!";