Merge remote-tracking branch 'newpavlov/rand_core' into develop

This commit is contained in:
Isis Lovecruft 2019-03-12 22:04:19 +00:00
commit 1bec256418
No known key found for this signature in database
GPG key ID: AB41313533E8E812
4 changed files with 29 additions and 25 deletions

View file

@ -19,10 +19,15 @@ travis-ci = { repository = "dalek-cryptography/ed25519-dalek", branch = "master"
version = "1" version = "1"
default-features = false default-features = false
[dependencies.rand_core]
version = "0.3"
default-features = false
[dependencies.rand] [dependencies.rand]
version = "0.6" version = "0.6"
features = ["i128_support"] features = ["i128_support"]
default-features = false default-features = false
optional = true
[dependencies.serde] [dependencies.serde]
version = "^1.0" version = "^1.0"
@ -43,6 +48,8 @@ version = "0.2"
hex = "^0.3" hex = "^0.3"
bincode = "^0.9" bincode = "^0.9"
criterion = "0.2" criterion = "0.2"
rand_os = "0.1.0"
rand_chacha = "0.1.0"
[[bench]] [[bench]]
name = "ed25519_benchmarks" name = "ed25519_benchmarks"
@ -50,9 +57,9 @@ harness = false
[features] [features]
default = ["std", "u64_backend"] default = ["std", "u64_backend"]
std = ["curve25519-dalek/std", "rand/std", "sha2/std"] std = ["curve25519-dalek/std", "rand", "sha2/std"]
alloc = ["curve25519-dalek/alloc"] alloc = ["curve25519-dalek/alloc"]
nightly = ["curve25519-dalek/nightly", "rand/nightly", "clear_on_drop/nightly"] nightly = ["curve25519-dalek/nightly", "clear_on_drop/nightly"]
asm = ["sha2/asm"] asm = ["sha2/asm"]
yolocrypto = ["curve25519-dalek/yolocrypto"] yolocrypto = ["curve25519-dalek/yolocrypto"]
u64_backend = ["curve25519-dalek/u64_backend"] u64_backend = ["curve25519-dalek/u64_backend"]

View file

@ -12,8 +12,7 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use core::default::Default; use core::default::Default;
use rand::CryptoRng; use rand_core::{CryptoRng, RngCore};
use rand::Rng;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::de::Error as SerdeError; use serde::de::Error as SerdeError;
@ -49,8 +48,7 @@ pub use crate::signature::*;
/// * `messages` is a slice of byte slices, one per signed message. /// * `messages` is a slice of byte slices, one per signed message.
/// * `signatures` is a slice of `Signature`s. /// * `signatures` is a slice of `Signature`s.
/// * `public_keys` is a slice of `PublicKey`s. /// * `public_keys` is a slice of `PublicKey`s.
/// * `csprng` is an implementation of `Rng + CryptoRng`, such as /// * `csprng` is an implementation of `Rng + CryptoRng`, such as `rand::rngs::ThreadRng`.
/// `rand::rngs::ThreadRng`.
/// ///
/// # Panics /// # Panics
/// ///
@ -107,7 +105,7 @@ pub fn verify_batch(
use std::vec::Vec; use std::vec::Vec;
use core::iter::once; use core::iter::once;
use rand::thread_rng; use rand::{Rng, thread_rng};
use curve25519_dalek::traits::IsIdentity; use curve25519_dalek::traits::IsIdentity;
use curve25519_dalek::traits::VartimeMultiscalarMul; use curve25519_dalek::traits::VartimeMultiscalarMul;
@ -219,14 +217,13 @@ impl Keypair {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// extern crate rand; /// extern crate rand_os;
/// extern crate ed25519_dalek; /// extern crate ed25519_dalek;
/// ///
/// # #[cfg(feature = "std")] /// # #[cfg(feature = "std")]
/// # fn main() { /// # fn main() {
/// ///
/// use rand::Rng; /// use rand_os::OsRng;
/// use rand::rngs::OsRng;
/// use ed25519_dalek::Keypair; /// use ed25519_dalek::Keypair;
/// use ed25519_dalek::Signature; /// use ed25519_dalek::Signature;
/// ///
@ -250,7 +247,7 @@ impl Keypair {
/// Other suitable hash functions include Keccak-512 and Blake2b-512. /// Other suitable hash functions include Keccak-512 and Blake2b-512.
pub fn generate<R>(csprng: &mut R) -> Keypair pub fn generate<R>(csprng: &mut R) -> Keypair
where where
R: CryptoRng + Rng, R: CryptoRng + RngCore,
{ {
let sk: SecretKey = SecretKey::generate(csprng); let sk: SecretKey = SecretKey::generate(csprng);
let pk: PublicKey = (&sk).into(); let pk: PublicKey = (&sk).into();
@ -417,7 +414,7 @@ impl Keypair {
/// let keypair: Keypair = Keypair::generate(&mut csprng); /// let keypair: Keypair = Keypair::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::default(); /// let mut prehashed: Sha512 = Sha512::new();
/// prehashed.input(message); /// prehashed.input(message);
/// ///
/// let context: &[u8] = b"Ed25519DalekSignPrehashedDoctest"; /// let context: &[u8] = b"Ed25519DalekSignPrehashedDoctest";

View file

@ -19,13 +19,13 @@
//! the operating system's builtin PRNG: //! the operating system's builtin PRNG:
//! //!
//! ``` //! ```
//! extern crate rand; //! extern crate rand_os;
//! extern crate ed25519_dalek; //! extern crate ed25519_dalek;
//! //!
//! # #[cfg(feature = "std")] //! # #[cfg(feature = "std")]
//! # fn main() { //! # fn main() {
//! use rand::Rng; //! use rand::Rng;
//! use rand::rngs::OsRng; //! use rand_os::OsRng;
//! use ed25519_dalek::Keypair; //! use ed25519_dalek::Keypair;
//! use ed25519_dalek::Signature; //! use ed25519_dalek::Signature;
//! //!
@ -250,7 +250,11 @@ extern crate std;
extern crate clear_on_drop; extern crate clear_on_drop;
extern crate curve25519_dalek; extern crate curve25519_dalek;
extern crate failure; extern crate failure;
#[cfg(any(feature = "std", test))]
extern crate rand; extern crate rand;
#[cfg(test)]
extern crate rand_chacha;
extern crate rand_core;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
extern crate serde; extern crate serde;
extern crate sha2; extern crate sha2;

View file

@ -19,8 +19,7 @@ use curve25519_dalek::digest::Digest;
use curve25519_dalek::edwards::CompressedEdwardsY; use curve25519_dalek::edwards::CompressedEdwardsY;
use curve25519_dalek::scalar::Scalar; use curve25519_dalek::scalar::Scalar;
use rand::CryptoRng; use rand_core::{CryptoRng, RngCore};
use rand::Rng;
use sha2::Sha512; use sha2::Sha512;
@ -126,15 +125,14 @@ impl SecretKey {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// extern crate rand; /// extern crate rand_os;
/// extern crate sha2; /// extern crate sha2;
/// extern crate ed25519_dalek; /// extern crate ed25519_dalek;
/// ///
/// # #[cfg(feature = "std")] /// # #[cfg(feature = "std")]
/// # fn main() { /// # fn main() {
/// # /// #
/// use rand::Rng; /// use rand_os::OsRng;
/// use rand::rngs::OsRng;
/// use sha2::Sha512; /// use sha2::Sha512;
/// use ed25519_dalek::PublicKey; /// use ed25519_dalek::PublicKey;
/// use ed25519_dalek::SecretKey; /// use ed25519_dalek::SecretKey;
@ -323,15 +321,14 @@ impl ExpandedSecretKey {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # extern crate rand; /// # extern crate rand_os;
/// # extern crate sha2; /// # extern crate sha2;
/// # extern crate ed25519_dalek; /// # extern crate ed25519_dalek;
/// # /// #
/// # #[cfg(all(feature = "sha2", feature = "std"))] /// # #[cfg(all(feature = "sha2", feature = "std"))]
/// # fn main() { /// # fn main() {
/// # /// #
/// use rand::Rng; /// use rand_os::OsRng;
/// use rand::rngs::OsRng;
/// use sha2::Sha512; /// use sha2::Sha512;
/// use ed25519_dalek::{SecretKey, ExpandedSecretKey}; /// use ed25519_dalek::{SecretKey, ExpandedSecretKey};
/// ///
@ -365,7 +362,7 @@ impl ExpandedSecretKey {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # extern crate rand; /// # extern crate rand_os;
/// # extern crate sha2; /// # extern crate sha2;
/// # extern crate ed25519_dalek; /// # extern crate ed25519_dalek;
/// # /// #
@ -374,8 +371,7 @@ impl ExpandedSecretKey {
/// # #[cfg(all(feature = "sha2", feature = "std"))] /// # #[cfg(all(feature = "sha2", feature = "std"))]
/// # fn do_test() -> Result<ExpandedSecretKey, SignatureError> { /// # fn do_test() -> Result<ExpandedSecretKey, SignatureError> {
/// # /// #
/// use rand::Rng; /// use rand_os::OsRng;
/// use rand::rngs::OsRng;
/// use ed25519_dalek::{SecretKey, ExpandedSecretKey}; /// use ed25519_dalek::{SecretKey, ExpandedSecretKey};
/// use ed25519_dalek::SignatureError; /// use ed25519_dalek::SignatureError;
/// ///