mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-07 20:50:39 +00:00
Merge branch 'release/0.2.0'
This commit is contained in:
commit
42c2578f4c
3 changed files with 18 additions and 9 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "curve25519-dalek"
|
name = "curve25519-dalek"
|
||||||
version = "0.1.3"
|
version = "0.2.0"
|
||||||
authors = ["Isis Lovecruft <isis@patternsinthevoid.net>",
|
authors = ["Isis Lovecruft <isis@patternsinthevoid.net>",
|
||||||
"Henry de Valence <hdevalence@hdevalence.ca>"]
|
"Henry de Valence <hdevalence@hdevalence.ca>"]
|
||||||
readme = "README.md"
|
readme = "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
|
To install, add the following to the dependencies section of your project's
|
||||||
`Cargo.toml`:
|
`Cargo.toml`:
|
||||||
|
|
||||||
curve25519-dalek = "^0.1"
|
curve25519-dalek = "^0.2"
|
||||||
|
|
||||||
Then, in your library or executable source, add:
|
Then, in your library or executable source, add:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@
|
||||||
use std::clone::Clone;
|
use std::clone::Clone;
|
||||||
use std::ops::{Index, IndexMut};
|
use std::ops::{Index, IndexMut};
|
||||||
|
|
||||||
use rand::OsRng;
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use field::{load3, load4};
|
use field::{load3, load4};
|
||||||
|
|
@ -65,12 +64,18 @@ impl IndexMut<usize> for Scalar {
|
||||||
impl Scalar {
|
impl Scalar {
|
||||||
/// Return a `Scalar` chosen uniformly at random using a CSPRNG.
|
/// Return a `Scalar` chosen uniformly at random using a CSPRNG.
|
||||||
/// Panics if the operating system's CSPRNG is unavailable.
|
/// Panics if the operating system's CSPRNG is unavailable.
|
||||||
pub fn random() -> Self {
|
///
|
||||||
// XXX is there a more efficient way than building
|
/// # Inputs
|
||||||
// the rng every time here?
|
///
|
||||||
let mut rng = OsRng::new().unwrap();
|
/// * `cspring`: any cryptographically secure PRNG which
|
||||||
|
/// implements the `rand::Rng` interface.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A random scalar within ℤ/lℤ.
|
||||||
|
pub fn random<T: Rng>(csprng: &mut T) -> Self {
|
||||||
let mut scalar_bytes = [0u8; 64];
|
let mut scalar_bytes = [0u8; 64];
|
||||||
rng.fill_bytes(&mut scalar_bytes);
|
csprng.fill_bytes(&mut scalar_bytes);
|
||||||
Scalar::reduce(&scalar_bytes)
|
Scalar::reduce(&scalar_bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -428,12 +433,16 @@ impl Scalar {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use rand::Rng;
|
||||||
|
use rand::OsRng;
|
||||||
use super::*;
|
use super::*;
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_scalar_random(b: &mut Bencher) {
|
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]
|
#[bench]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue