Merge branch 'release/1.0.0-pre.2'

This commit is contained in:
Isis Lovecruft 2019-10-04 02:40:38 +00:00
commit 5870607aa7
No known key found for this signature in database
GPG key ID: AB41313533E8E812
8 changed files with 134 additions and 107 deletions

View file

@ -6,23 +6,26 @@ rust:
- nightly - nightly
env: env:
- TEST_COMMAND=test FEATURES='' - TEST_COMMAND=test EXTRA_FLAGS='' FEATURES=''
matrix: matrix:
include: include:
# We use the 64-bit optimised curve backend by default, so also test with # We use the 64-bit optimised curve backend by default, so also test with
# the 32-bit backend (this also exercises testing with `no_std`): # the 32-bit backend (this also exercises testing with `no_std`):
- rust: nightly - rust: nightly
env: TEST_COMMAND=build FEATURES='--no-default-features --features=u32_backend' env: TEST_COMMAND=build EXTRA_FLAGS='--no-default-features' FEATURES='u32_backend alloc'
# Also test the batch feature:
- rust: nightly
env: TEST_COMMAND=build EXTRA_FLAGS='--no-default-features' FEATURES='u64_backend alloc batch'
# Test any nightly gated features on nightly: # Test any nightly gated features on nightly:
- rust: nightly - rust: nightly
env: TEST_COMMAND=test FEATURES='--features=nightly' env: TEST_COMMAND=test EXTRA_FLAGS='' FEATURES='nightly'
# Test serde support on stable, assuming that if it works there it'll work everywhere: # Test serde support on stable, assuming that if it works there it'll work everywhere:
- rust: stable - rust: stable
env: TEST_COMMAND=test FEATURE='--features=serde' env: TEST_COMMAND=test EXTRA_FLAGS='' FEATURES='serde'
script: script:
- cargo $TEST_COMMAND $FEATURES - cargo $TEST_COMMAND --features="$FEATURES" $EXTRA_FLAGS
notifications: notifications:
slack: slack:

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ed25519-dalek" name = "ed25519-dalek"
version = "1.0.0-pre.1" version = "1.0.0-pre.2"
authors = ["isis lovecruft <isis@patternsinthevoid.net>"] authors = ["isis lovecruft <isis@patternsinthevoid.net>"]
readme = "README.md" readme = "README.md"
license = "BSD-3-Clause" license = "BSD-3-Clause"
@ -19,9 +19,19 @@ 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
optional = true
[dependencies.rand_os]
version = "0.1"
optional = true
[dependencies.serde] [dependencies.serde]
version = "^1.0" version = "^1.0"
@ -42,16 +52,22 @@ version = "0.2"
hex = "^0.3" hex = "^0.3"
bincode = "^0.9" bincode = "^0.9"
criterion = "0.2" criterion = "0.2"
rand = "0.6"
rand_os = "0.1"
[[bench]] [[bench]]
name = "ed25519_benchmarks" name = "ed25519_benchmarks"
harness = false harness = false
# This doesn't seem to work with criterion, cf. https://github.com/bheisler/criterion.rs/issues/344
# For now, we have to bench by doing `cargo bench --features="batch"`.
# required-features = ["batch"]
[features] [features]
default = ["std", "u64_backend"] default = ["std", "u64_backend"]
std = ["curve25519-dalek/std", "rand/std", "sha2/std"] std = ["curve25519-dalek/std", "rand_os", "sha2/std"]
alloc = ["curve25519-dalek/alloc"] alloc = ["curve25519-dalek/alloc", "rand_os"]
nightly = ["curve25519-dalek/nightly", "rand/nightly", "clear_on_drop/nightly"] nightly = ["curve25519-dalek/nightly", "clear_on_drop/nightly"]
batch = ["rand"]
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

@ -78,7 +78,7 @@ The numbers after the `/` in the test name refer to the size of the batch:
Ed25519 batch signature verification/256 time: [5.0124 ms 5.0290 ms 5.0491 ms] Ed25519 batch signature verification/256 time: [5.0124 ms 5.0290 ms 5.0491 ms]
As you can see, there's an optimal batch size for each machine, so you'll likely As you can see, there's an optimal batch size for each machine, so you'll likely
want to your the benchmarks on your target CPU to discover the best size. For want to test the benchmarks on your target CPU to discover the best size. For
this machine, around 100 signatures per batch is the optimum: this machine, around 100 signatures per batch is the optimum:
![](https://github.com/dalek-cryptography/ed25519-dalek/blob/master/res/batch-violin-benchmark.svg) ![](https://github.com/dalek-cryptography/ed25519-dalek/blob/master/res/batch-violin-benchmark.svg)

View file

@ -22,7 +22,7 @@ mod ed25519_benches {
use ed25519_dalek::Signature; use ed25519_dalek::Signature;
use ed25519_dalek::verify_batch; use ed25519_dalek::verify_batch;
use rand::thread_rng; use rand::thread_rng;
use rand::rngs::ThreadRng; use rand::prelude::ThreadRng;
fn sign(c: &mut Criterion) { fn sign(c: &mut Criterion) {
let mut csprng: ThreadRng = thread_rng(); let mut csprng: ThreadRng = thread_rng();

View file

@ -9,10 +9,10 @@
//! ed25519 keypairs and batch verification. //! ed25519 keypairs and batch verification.
#[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;
@ -28,8 +28,11 @@ pub use sha2::Sha512;
use curve25519_dalek::digest::generic_array::typenum::U64; use curve25519_dalek::digest::generic_array::typenum::U64;
pub use curve25519_dalek::digest::Digest; pub use curve25519_dalek::digest::Digest;
#[cfg(all(feature = "batch", any(feature = "alloc", feature = "std")))]
use curve25519_dalek::constants; use curve25519_dalek::constants;
#[cfg(all(feature = "batch", any(feature = "alloc", feature = "std")))]
use curve25519_dalek::edwards::EdwardsPoint; use curve25519_dalek::edwards::EdwardsPoint;
#[cfg(all(feature = "batch", any(feature = "alloc", feature = "std")))]
use curve25519_dalek::scalar::Scalar; use curve25519_dalek::scalar::Scalar;
pub use crate::constants::*; pub use crate::constants::*;
@ -45,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`.
/// `rand::rngs::ThreadRng`.
/// ///
/// # Panics /// # Panics
/// ///
@ -63,17 +65,16 @@ pub use crate::signature::*;
/// ///
/// ``` /// ```
/// extern crate ed25519_dalek; /// extern crate ed25519_dalek;
/// extern crate rand; /// extern crate rand_os;
/// ///
/// use ed25519_dalek::verify_batch; /// use ed25519_dalek::verify_batch;
/// use ed25519_dalek::Keypair; /// use ed25519_dalek::Keypair;
/// use ed25519_dalek::PublicKey; /// use ed25519_dalek::PublicKey;
/// use ed25519_dalek::Signature; /// use ed25519_dalek::Signature;
/// use rand::thread_rng; /// use rand_os::OsRng;
/// use rand::rngs::ThreadRng;
/// ///
/// # fn main() { /// # fn main() {
/// let mut csprng: ThreadRng = thread_rng(); /// let mut csprng: OsRng = OsRng::new().unwrap();
/// let keypairs: Vec<Keypair> = (0..64).map(|_| Keypair::generate(&mut csprng)).collect(); /// let keypairs: Vec<Keypair> = (0..64).map(|_| Keypair::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<&[u8]> = (0..64).map(|_| msg).collect(); /// let messages: Vec<&[u8]> = (0..64).map(|_| msg).collect();
@ -84,7 +85,7 @@ pub use crate::signature::*;
/// assert!(result.is_ok()); /// assert!(result.is_ok());
/// # } /// # }
/// ``` /// ```
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(all(feature = "batch", any(feature = "alloc", feature = "std")))]
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn verify_batch( pub fn verify_batch(
messages: &[&[u8]], messages: &[&[u8]],
@ -92,7 +93,7 @@ pub fn verify_batch(
public_keys: &[PublicKey], public_keys: &[PublicKey],
) -> Result<(), SignatureError> ) -> Result<(), SignatureError>
{ {
const ASSERT_MESSAGE: &'static [u8] = b"The number of messages, signatures, and public keys must be equal."; const ASSERT_MESSAGE: &'static str = "The number of messages, signatures, and public keys must be equal.";
assert!(signatures.len() == messages.len(), ASSERT_MESSAGE); assert!(signatures.len() == messages.len(), ASSERT_MESSAGE);
assert!(signatures.len() == public_keys.len(), ASSERT_MESSAGE); assert!(signatures.len() == public_keys.len(), ASSERT_MESSAGE);
assert!(public_keys.len() == messages.len(), ASSERT_MESSAGE); assert!(public_keys.len() == messages.len(), ASSERT_MESSAGE);
@ -103,7 +104,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;
@ -215,14 +216,15 @@ impl Keypair {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// extern crate rand; /// extern crate rand_core;
/// 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_core::{CryptoRng, RngCore};
/// use rand::rngs::OsRng; /// use rand_os::OsRng;
/// use ed25519_dalek::Keypair; /// use ed25519_dalek::Keypair;
/// use ed25519_dalek::Signature; /// use ed25519_dalek::Signature;
/// ///
@ -237,7 +239,7 @@ impl Keypair {
/// ///
/// # Input /// # Input
/// ///
/// A CSPRNG with a `fill_bytes()` method, e.g. `rand_chacha::ChaChaRng`. /// A CSPRNG with a `fill_bytes()` method, e.g. `rand_os::OsRng`.
/// ///
/// The caller must also supply a hash function which implements the /// The caller must also supply a hash function which implements the
/// `Digest` and `Default` traits, and which returns 512 bits of output. /// `Digest` and `Default` traits, and which returns 512 bits of output.
@ -246,7 +248,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();
@ -281,17 +283,17 @@ impl Keypair {
/// ///
/// ``` /// ```
/// extern crate ed25519_dalek; /// extern crate ed25519_dalek;
/// extern crate rand; /// extern crate rand_os;
/// ///
/// use ed25519_dalek::Digest; /// use ed25519_dalek::Digest;
/// use ed25519_dalek::Keypair; /// use ed25519_dalek::Keypair;
/// use ed25519_dalek::Sha512; /// use ed25519_dalek::Sha512;
/// use ed25519_dalek::Signature; /// use ed25519_dalek::Signature;
/// use rand::thread_rng; /// use rand_os::OsRng;
/// ///
/// # #[cfg(feature = "std")] /// # #[cfg(feature = "std")]
/// # fn main() { /// # fn main() {
/// let mut csprng = thread_rng(); /// let mut csprng = OsRng::new().unwrap();
/// 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.";
/// ///
@ -328,17 +330,17 @@ impl Keypair {
/// ///
/// ``` /// ```
/// # extern crate ed25519_dalek; /// # extern crate ed25519_dalek;
/// # extern crate rand; /// # extern crate rand_os;
/// # /// #
/// # use ed25519_dalek::Digest; /// # use ed25519_dalek::Digest;
/// # use ed25519_dalek::Keypair; /// # use ed25519_dalek::Keypair;
/// # use ed25519_dalek::Signature; /// # use ed25519_dalek::Signature;
/// # use ed25519_dalek::Sha512; /// # use ed25519_dalek::Sha512;
/// # use rand::thread_rng; /// # use rand_os::OsRng;
/// # /// #
/// # #[cfg(feature = "std")] /// # #[cfg(feature = "std")]
/// # fn main() { /// # fn main() {
/// # let mut csprng = thread_rng(); /// # let mut csprng: OsRng = OsRng::new().unwrap();
/// # 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::new(); /// # let mut prehashed: Sha512 = Sha512::new();
@ -399,21 +401,21 @@ impl Keypair {
/// ///
/// ``` /// ```
/// extern crate ed25519_dalek; /// extern crate ed25519_dalek;
/// extern crate rand; /// extern crate rand_os;
/// ///
/// use ed25519_dalek::Digest; /// use ed25519_dalek::Digest;
/// use ed25519_dalek::Keypair; /// use ed25519_dalek::Keypair;
/// use ed25519_dalek::Signature; /// use ed25519_dalek::Signature;
/// use ed25519_dalek::Sha512; /// use ed25519_dalek::Sha512;
/// use rand::thread_rng; /// use rand_os::OsRng;
/// ///
/// # #[cfg(feature = "std")] /// # #[cfg(feature = "std")]
/// # fn main() { /// # fn main() {
/// let mut csprng = thread_rng(); /// let mut csprng: OsRng = OsRng::new().unwrap();
/// 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,14 @@
//! the operating system's builtin PRNG: //! the operating system's builtin PRNG:
//! //!
//! ``` //! ```
//! extern crate rand; //! extern crate rand_core;
//! 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_core::RngCore;
//! use rand::rngs::OsRng; //! use rand_os::OsRng;
//! use ed25519_dalek::Keypair; //! use ed25519_dalek::Keypair;
//! use ed25519_dalek::Signature; //! use ed25519_dalek::Signature;
//! //!
@ -40,14 +41,15 @@
//! We can now use this `keypair` to sign a message: //! We can now use this `keypair` to sign a message:
//! //!
//! ``` //! ```
//! # extern crate rand; //! # extern crate rand_core;
//! # extern crate rand_os;
//! # extern crate ed25519_dalek; //! # extern crate ed25519_dalek;
//! # fn main() { //! # fn main() {
//! # use rand::Rng; //! # use rand_core::RngCore;
//! # use rand::thread_rng; //! # use rand_os::OsRng;
//! # use ed25519_dalek::Keypair; //! # use ed25519_dalek::Keypair;
//! # use ed25519_dalek::Signature; //! # use ed25519_dalek::Signature;
//! # let mut csprng = thread_rng(); //! # let mut csprng = OsRng::new().unwrap();
//! # let keypair: Keypair = Keypair::generate(&mut csprng); //! # let keypair: Keypair = Keypair::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 = keypair.sign(message); //! let signature: Signature = keypair.sign(message);
@ -58,14 +60,15 @@
//! that `message`: //! that `message`:
//! //!
//! ``` //! ```
//! # extern crate rand; //! # extern crate rand_core;
//! # extern crate rand_os;
//! # extern crate ed25519_dalek; //! # extern crate ed25519_dalek;
//! # fn main() { //! # fn main() {
//! # use rand::Rng; //! # use rand_core::RngCore;
//! # use rand::thread_rng; //! # use rand_os::OsRng;
//! # use ed25519_dalek::Keypair; //! # use ed25519_dalek::Keypair;
//! # use ed25519_dalek::Signature; //! # use ed25519_dalek::Signature;
//! # let mut csprng = thread_rng(); //! # let mut csprng = OsRng::new().unwrap();
//! # let keypair: Keypair = Keypair::generate(&mut csprng); //! # let keypair: Keypair = Keypair::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 = keypair.sign(message); //! # let signature: Signature = keypair.sign(message);
@ -77,15 +80,16 @@
//! verify this signature: //! verify this signature:
//! //!
//! ``` //! ```
//! # extern crate rand; //! # extern crate rand_core;
//! # extern crate rand_os;
//! # extern crate ed25519_dalek; //! # extern crate ed25519_dalek;
//! # fn main() { //! # fn main() {
//! # use rand::Rng; //! # use rand_core::RngCore;
//! # use rand::thread_rng; //! # use rand_os::OsRng;
//! # use ed25519_dalek::Keypair; //! # use ed25519_dalek::Keypair;
//! # use ed25519_dalek::Signature; //! # use ed25519_dalek::Signature;
//! use ed25519_dalek::PublicKey; //! use ed25519_dalek::PublicKey;
//! # let mut csprng = thread_rng(); //! # let mut csprng = OsRng::new().unwrap();
//! # let keypair: Keypair = Keypair::generate(&mut csprng); //! # let keypair: Keypair = Keypair::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 = keypair.sign(message); //! # let signature: Signature = keypair.sign(message);
@ -104,14 +108,15 @@
//! verify your signatures!) //! verify your signatures!)
//! //!
//! ``` //! ```
//! # extern crate rand; //! # extern crate rand_core;
//! # extern crate rand_os;
//! # extern crate ed25519_dalek; //! # extern crate ed25519_dalek;
//! # fn main() { //! # fn main() {
//! # use rand::Rng; //! # use rand_core::RngCore;
//! # use rand::thread_rng; //! # use rand_os::OsRng;
//! # use ed25519_dalek::{Keypair, Signature, PublicKey}; //! # use ed25519_dalek::{Keypair, Signature, PublicKey};
//! 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 = thread_rng(); //! # let mut csprng = OsRng::new().unwrap();
//! # let keypair: Keypair = Keypair::generate(&mut csprng); //! # let keypair: Keypair = Keypair::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 = keypair.sign(message); //! # let signature: Signature = keypair.sign(message);
@ -127,14 +132,15 @@
//! And similarly, decoded from bytes with `::from_bytes()`: //! And similarly, decoded from bytes with `::from_bytes()`:
//! //!
//! ``` //! ```
//! # extern crate rand; //! # extern crate rand_core;
//! # extern crate rand_os;
//! # extern crate ed25519_dalek; //! # extern crate ed25519_dalek;
//! # use rand::Rng; //! # use rand_core::RngCore;
//! # use rand::thread_rng; //! # use rand_os::OsRng;
//! # use ed25519_dalek::{Keypair, Signature, PublicKey, SecretKey, SignatureError}; //! # use ed25519_dalek::{Keypair, Signature, PublicKey, 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<(SecretKey, PublicKey, Keypair, Signature), SignatureError> { //! # fn do_test() -> Result<(SecretKey, PublicKey, Keypair, Signature), SignatureError> {
//! # let mut csprng = thread_rng(); //! # let mut csprng = OsRng::new().unwrap();
//! # let keypair_orig: Keypair = Keypair::generate(&mut csprng); //! # let keypair_orig: Keypair = Keypair::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 = keypair_orig.sign(message); //! # let signature_orig: Signature = keypair_orig.sign(message);
@ -169,7 +175,8 @@
//! For example, using [bincode](https://github.com/TyOverby/bincode): //! For example, using [bincode](https://github.com/TyOverby/bincode):
//! //!
//! ``` //! ```
//! # extern crate rand; //! # extern crate rand_core;
//! # extern crate rand_os;
//! # extern crate ed25519_dalek; //! # extern crate ed25519_dalek;
//! # #[cfg(feature = "serde")] //! # #[cfg(feature = "serde")]
//! extern crate serde; //! extern crate serde;
@ -178,11 +185,11 @@
//! //!
//! # #[cfg(feature = "serde")] //! # #[cfg(feature = "serde")]
//! # fn main() { //! # fn main() {
//! # use rand::Rng; //! # use rand_core::RngCore;
//! # use rand::thread_rng; //! # use rand_os::OsRng;
//! # use ed25519_dalek::{Keypair, Signature, PublicKey}; //! # use ed25519_dalek::{Keypair, Signature, PublicKey};
//! use bincode::{serialize, Infinite}; //! use bincode::{serialize, Infinite};
//! # let mut csprng = thread_rng(); //! # let mut csprng = OsRng::new().unwrap();
//! # let keypair: Keypair = Keypair::generate(&mut csprng); //! # let keypair: Keypair = Keypair::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 = keypair.sign(message); //! # let signature: Signature = keypair.sign(message);
@ -200,7 +207,8 @@
//! recipient may deserialise them and verify: //! recipient may deserialise them and verify:
//! //!
//! ``` //! ```
//! # extern crate rand; //! # extern crate rand_core;
//! # extern crate rand_os;
//! # extern crate ed25519_dalek; //! # extern crate ed25519_dalek;
//! # #[cfg(feature = "serde")] //! # #[cfg(feature = "serde")]
//! # extern crate serde; //! # extern crate serde;
@ -209,13 +217,13 @@
//! # //! #
//! # #[cfg(feature = "serde")] //! # #[cfg(feature = "serde")]
//! # fn main() { //! # fn main() {
//! # use rand::Rng; //! # use rand_core::RngCore;
//! # use rand::thread_rng; //! # use rand_os::OsRng;
//! # use ed25519_dalek::{Keypair, Signature, PublicKey}; //! # use ed25519_dalek::{Keypair, Signature, PublicKey};
//! # use bincode::{serialize, Infinite}; //! # use bincode::{serialize, Infinite};
//! use bincode::{deserialize}; //! use bincode::{deserialize};
//! //!
//! # let mut csprng = thread_rng(); //! # let mut csprng = OsRng::new().unwrap();
//! # let keypair: Keypair = Keypair::generate(&mut csprng); //! # let keypair: Keypair = Keypair::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 = keypair.sign(message); //! # let signature: Signature = keypair.sign(message);
@ -247,10 +255,16 @@
#[macro_use] #[macro_use]
extern crate std; extern crate std;
#[cfg(all(feature = "alloc", not(feature = "std")))]
extern crate alloc;
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(all(feature = "batch", any(feature = "std", feature = "alloc", test)))]
extern crate rand; extern crate rand;
#[cfg(any(feature = "std", test))]
extern crate rand_os;
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,16 +125,13 @@ impl SecretKey {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// extern crate rand; /// extern crate rand_os;
/// 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 ed25519_dalek::PublicKey; /// use ed25519_dalek::PublicKey;
/// use ed25519_dalek::SecretKey; /// use ed25519_dalek::SecretKey;
/// use ed25519_dalek::Signature; /// use ed25519_dalek::Signature;
@ -151,18 +147,17 @@ impl SecretKey {
/// Afterwards, you can generate the corresponding public: /// Afterwards, you can generate the corresponding public:
/// ///
/// ``` /// ```
/// # extern crate rand; /// # extern crate rand_os;
/// # extern crate ed25519_dalek; /// # extern crate ed25519_dalek;
/// # /// #
/// # fn main() { /// # fn main() {
/// # /// #
/// # use rand::Rng; /// # use rand_os::OsRng;
/// # use rand::thread_rng;
/// # use ed25519_dalek::PublicKey; /// # use ed25519_dalek::PublicKey;
/// # use ed25519_dalek::SecretKey; /// # use ed25519_dalek::SecretKey;
/// # use ed25519_dalek::Signature; /// # use ed25519_dalek::Signature;
/// # /// #
/// # let mut csprng = thread_rng(); /// # let mut csprng = OsRng::new().unwrap();
/// # let secret_key: SecretKey = SecretKey::generate(&mut csprng); /// # let secret_key: SecretKey = SecretKey::generate(&mut csprng);
/// ///
/// let public_key: PublicKey = (&secret_key).into(); /// let public_key: PublicKey = (&secret_key).into();
@ -174,7 +169,7 @@ impl SecretKey {
/// A CSPRNG with a `fill_bytes()` method, e.g. `rand::OsRng` /// A CSPRNG with a `fill_bytes()` method, e.g. `rand::OsRng`
pub fn generate<T>(csprng: &mut T) -> SecretKey pub fn generate<T>(csprng: &mut T) -> SecretKey
where where
T: CryptoRng + Rng, T: CryptoRng + RngCore,
{ {
let mut sk: SecretKey = SecretKey([0u8; 32]); let mut sk: SecretKey = SecretKey([0u8; 32]);
@ -275,18 +270,18 @@ impl<'a> From<&'a SecretKey> for ExpandedSecretKey {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # extern crate rand; /// # extern crate rand_core;
/// # extern crate rand_os;
/// # extern crate sha2; /// # extern crate sha2;
/// # extern crate ed25519_dalek; /// # extern crate ed25519_dalek;
/// # /// #
/// # fn main() { /// # fn main() {
/// # /// #
/// use rand::Rng; /// use rand_core::RngCore;
/// use rand::thread_rng; /// use rand_os::OsRng;
/// use sha2::Sha512;
/// use ed25519_dalek::{SecretKey, ExpandedSecretKey}; /// use ed25519_dalek::{SecretKey, ExpandedSecretKey};
/// ///
/// let mut csprng = thread_rng(); /// let mut csprng = OsRng::new().unwrap();
/// let secret_key: SecretKey = SecretKey::generate(&mut csprng); /// let secret_key: SecretKey = SecretKey::generate(&mut csprng);
/// let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key); /// let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);
/// # } /// # }
@ -323,16 +318,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(feature = "std")]
/// # fn main() { /// # fn main() {
/// # /// #
/// use rand::Rng; /// use rand_os::OsRng;
/// use rand::rngs::OsRng;
/// use sha2::Sha512;
/// use ed25519_dalek::{SecretKey, ExpandedSecretKey}; /// use ed25519_dalek::{SecretKey, ExpandedSecretKey};
/// ///
/// let mut csprng: OsRng = OsRng::new().unwrap(); /// let mut csprng: OsRng = OsRng::new().unwrap();
@ -343,7 +336,7 @@ impl ExpandedSecretKey {
/// assert!(&expanded_secret_key_bytes[..] != &[0u8; 64][..]); /// assert!(&expanded_secret_key_bytes[..] != &[0u8; 64][..]);
/// # } /// # }
/// # /// #
/// # #[cfg(any(not(feature = "sha2"), not(feature = "std")))] /// # #[cfg(not(feature = "std"))]
/// # fn main() { } /// # fn main() { }
/// ``` /// ```
#[inline] #[inline]
@ -365,17 +358,16 @@ 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;
/// # /// #
/// # use ed25519_dalek::{ExpandedSecretKey, SignatureError}; /// # use ed25519_dalek::{ExpandedSecretKey, SignatureError};
/// # /// #
/// # #[cfg(all(feature = "sha2", feature = "std"))] /// # #[cfg(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;
/// ///
@ -388,13 +380,13 @@ impl ExpandedSecretKey {
/// # Ok(expanded_secret_key_again) /// # Ok(expanded_secret_key_again)
/// # } /// # }
/// # /// #
/// # #[cfg(all(feature = "sha2", feature = "std"))] /// # #[cfg(feature = "std")]
/// # fn main() { /// # fn main() {
/// # let result = do_test(); /// # let result = do_test();
/// # assert!(result.is_ok()); /// # assert!(result.is_ok());
/// # } /// # }
/// # /// #
/// # #[cfg(any(not(feature = "sha2"), not(feature = "std")))] /// # #[cfg(not(feature = "std"))]
/// # fn main() { } /// # fn main() { }
/// ``` /// ```
#[inline] #[inline]

View file

@ -13,15 +13,14 @@
extern crate bincode; extern crate bincode;
extern crate ed25519_dalek; extern crate ed25519_dalek;
extern crate hex; extern crate hex;
extern crate rand; extern crate rand_os;
extern crate sha2; extern crate sha2;
use ed25519_dalek::*; use ed25519_dalek::*;
use hex::FromHex; use hex::FromHex;
use rand::thread_rng; use rand_os::OsRng;
use rand::rngs::ThreadRng;
use sha2::Sha512; use sha2::Sha512;
@ -117,7 +116,6 @@ mod integrations {
#[test] #[test]
fn sign_verify() { // TestSignVerify fn sign_verify() { // TestSignVerify
let mut csprng: ThreadRng;
let keypair: Keypair; let keypair: Keypair;
let good_sig: Signature; let good_sig: Signature;
let bad_sig: Signature; let bad_sig: Signature;
@ -125,7 +123,8 @@ 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();
csprng = thread_rng(); let mut csprng: OsRng = OsRng::new().unwrap();
keypair = Keypair::generate(&mut csprng); keypair = Keypair::generate(&mut csprng);
good_sig = keypair.sign(&good); good_sig = keypair.sign(&good);
bad_sig = keypair.sign(&bad); bad_sig = keypair.sign(&bad);
@ -140,7 +139,6 @@ mod integrations {
#[test] #[test]
fn ed25519ph_sign_verify() { fn ed25519ph_sign_verify() {
let mut csprng: ThreadRng;
let keypair: Keypair; let keypair: Keypair;
let good_sig: Signature; let good_sig: Signature;
let bad_sig: Signature; let bad_sig: Signature;
@ -148,6 +146,8 @@ 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: OsRng = OsRng::new().unwrap();
// 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();
prehashed_good1.input(good); prehashed_good1.input(good);
@ -163,7 +163,6 @@ mod integrations {
let context: &[u8] = b"testing testing 1 2 3"; let context: &[u8] = b"testing testing 1 2 3";
csprng = thread_rng();
keypair = Keypair::generate(&mut csprng); keypair = Keypair::generate(&mut csprng);
good_sig = keypair.sign_prehashed(prehashed_good1, Some(context)); good_sig = keypair.sign_prehashed(prehashed_good1, Some(context));
bad_sig = keypair.sign_prehashed(prehashed_bad1, Some(context)); bad_sig = keypair.sign_prehashed(prehashed_bad1, Some(context));
@ -176,6 +175,7 @@ mod integrations {
"Verification of a signature on a different message passed!"); "Verification of a signature on a different message passed!");
} }
#[cfg(feature = "batch")]
#[test] #[test]
fn verify_batch_seven_signatures() { fn verify_batch_seven_signatures() {
let messages: [&[u8]; 7] = [ let messages: [&[u8]; 7] = [
@ -186,7 +186,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: ThreadRng = thread_rng(); let mut csprng: OsRng = OsRng::new().unwrap();
let mut keypairs: Vec<Keypair> = Vec::new(); let mut keypairs: Vec<Keypair> = Vec::new();
let mut signatures: Vec<Signature> = Vec::new(); let mut signatures: Vec<Signature> = Vec::new();
@ -204,7 +204,7 @@ mod integrations {
#[test] #[test]
fn pubkey_from_secret_and_expanded_secret() { fn pubkey_from_secret_and_expanded_secret() {
let mut csprng = thread_rng(); let mut csprng = OsRng::new().unwrap();
let secret: SecretKey = SecretKey::generate(&mut csprng); let secret: SecretKey = SecretKey::generate(&mut csprng);
let expanded_secret: ExpandedSecretKey = (&secret).into(); let expanded_secret: ExpandedSecretKey = (&secret).into();
let public_from_secret: PublicKey = (&secret).into(); // XXX eww let public_from_secret: PublicKey = (&secret).into(); // XXX eww