From 226f5c7019acce3c36feca928c1fdaaf540cb9d8 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Wed, 14 Dec 2016 05:02:36 +0000 Subject: [PATCH 1/3] Update version to 0.2.0 in Cargo.toml. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1973fcd..014cce1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "curve25519-dalek" -version = "0.1.3" +version = "0.2.0" authors = ["Isis Lovecruft ", "Henry de Valence "] readme = "README.md" From a339da82e7ebbf62204eb80f1fa6ceb67ae84615 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Wed, 14 Dec 2016 05:02:55 +0000 Subject: [PATCH 2/3] Update the minor version number in the README. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2192cbf..2c0b3ef 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Extensive documentation is available [here](https://docs.rs/curve25519-dalek). To install, add the following to the dependencies section of your project's `Cargo.toml`: - curve25519-dalek = "^0.1" + curve25519-dalek = "^0.2" Then, in your library or executable source, add: From c9b0e45afbb11d4465cc2556286213573e241609 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Wed, 14 Dec 2016 05:38:06 +0000 Subject: [PATCH 3/3] Specify the RNG for Scalar::random. --- src/scalar.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/scalar.rs b/src/scalar.rs index 8a575fd..294f127 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -29,7 +29,6 @@ use std::clone::Clone; use std::ops::{Index, IndexMut}; -use rand::OsRng; use rand::Rng; use field::{load3, load4}; @@ -65,12 +64,18 @@ impl IndexMut for Scalar { impl Scalar { /// Return a `Scalar` chosen uniformly at random using a CSPRNG. /// Panics if the operating system's CSPRNG is unavailable. - pub fn random() -> Self { - // XXX is there a more efficient way than building - // the rng every time here? - let mut rng = OsRng::new().unwrap(); + /// + /// # Inputs + /// + /// * `cspring`: any cryptographically secure PRNG which + /// implements the `rand::Rng` interface. + /// + /// # Returns + /// + /// A random scalar within ℤ/lℤ. + pub fn random(csprng: &mut T) -> Self { let mut scalar_bytes = [0u8; 64]; - rng.fill_bytes(&mut scalar_bytes); + csprng.fill_bytes(&mut scalar_bytes); Scalar::reduce(&scalar_bytes) } @@ -428,12 +433,16 @@ impl Scalar { #[cfg(test)] mod test { + use rand::Rng; + use rand::OsRng; use super::*; use test::Bencher; #[bench] fn bench_scalar_random(b: &mut Bencher) { - b.iter(|| Scalar::random()); + let mut csprng: OsRng = OsRng::new().unwrap(); + + b.iter(|| Scalar::random(&mut csprng)); } #[bench]