mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-08 21:00:40 +00:00
Merge branch 'release/0.3.2'
This commit is contained in:
commit
8ea81bec89
2 changed files with 31 additions and 32 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ed25519-dalek"
|
name = "ed25519-dalek"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
authors = ["Isis Lovecruft <isis@torproject.org>"]
|
authors = ["Isis Lovecruft <isis@torproject.org>"]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "CC0-1.0"
|
license = "CC0-1.0"
|
||||||
|
|
@ -19,7 +19,7 @@ travis-ci = { repository = "isislovecruft/ed25519-dalek", branch = "master"}
|
||||||
arrayref = "0.3.3"
|
arrayref = "0.3.3"
|
||||||
|
|
||||||
[dependencies.curve25519-dalek]
|
[dependencies.curve25519-dalek]
|
||||||
version = "^0.6"
|
version = "^0.7"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[dependencies.rand]
|
[dependencies.rand]
|
||||||
|
|
@ -27,7 +27,7 @@ optional = true
|
||||||
version = "^0.3"
|
version = "^0.3"
|
||||||
|
|
||||||
[dependencies.digest]
|
[dependencies.digest]
|
||||||
version = "0.4"
|
version = "^0.5"
|
||||||
|
|
||||||
[dependencies.generic-array]
|
[dependencies.generic-array]
|
||||||
# same version that digest depends on
|
# same version that digest depends on
|
||||||
|
|
@ -35,7 +35,7 @@ version = "^0.6"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rustc-serialize = "0.3"
|
rustc-serialize = "0.3"
|
||||||
sha2 = "^0.4"
|
sha2 = "^0.5"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,13 @@ use core::fmt::Debug;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use digest::Digest;
|
use digest::Input;
|
||||||
|
use digest::FixedOutput;
|
||||||
use generic_array::typenum::U64;
|
use generic_array::typenum::U64;
|
||||||
|
|
||||||
use curve25519_dalek::curve;
|
use curve25519_dalek::constants;
|
||||||
use curve25519_dalek::curve::BasepointMult;
|
|
||||||
use curve25519_dalek::curve::CompressedEdwardsY;
|
use curve25519_dalek::curve::CompressedEdwardsY;
|
||||||
use curve25519_dalek::curve::ExtendedPoint;
|
use curve25519_dalek::curve::ExtendedPoint;
|
||||||
use curve25519_dalek::curve::ProjectivePoint;
|
|
||||||
use curve25519_dalek::scalar::Scalar;
|
use curve25519_dalek::scalar::Scalar;
|
||||||
use curve25519_dalek::subtle::arrays_equal_ct;
|
use curve25519_dalek::subtle::arrays_equal_ct;
|
||||||
|
|
||||||
|
|
@ -137,7 +136,7 @@ impl SecretKey {
|
||||||
|
|
||||||
/// Sign a message with this keypair's secret key.
|
/// Sign a message with this keypair's secret key.
|
||||||
pub fn sign<D>(&self, message: &[u8]) -> Signature
|
pub fn sign<D>(&self, message: &[u8]) -> Signature
|
||||||
where D: Digest<OutputSize = U64> + Default {
|
where D: FixedOutput<OutputSize = U64> + Default + Input {
|
||||||
|
|
||||||
let mut h: D = D::default();
|
let mut h: D = D::default();
|
||||||
let mut hash: [u8; 64] = [0u8; 64];
|
let mut hash: [u8; 64] = [0u8; 64];
|
||||||
|
|
@ -152,8 +151,8 @@ impl SecretKey {
|
||||||
let secret_key: &[u8; 32] = array_ref!(&self.0, 0, 32);
|
let secret_key: &[u8; 32] = array_ref!(&self.0, 0, 32);
|
||||||
let public_key: &[u8; 32] = array_ref!(&self.0, 32, 32);
|
let public_key: &[u8; 32] = array_ref!(&self.0, 32, 32);
|
||||||
|
|
||||||
h.input(secret_key);
|
h.digest(secret_key);
|
||||||
hash.copy_from_slice(h.result().as_slice());
|
hash.copy_from_slice(h.fixed_result().as_slice());
|
||||||
|
|
||||||
expanded_key_secret = Scalar(*array_ref!(&hash, 0, 32));
|
expanded_key_secret = Scalar(*array_ref!(&hash, 0, 32));
|
||||||
expanded_key_secret[0] &= 248;
|
expanded_key_secret[0] &= 248;
|
||||||
|
|
@ -161,19 +160,19 @@ impl SecretKey {
|
||||||
expanded_key_secret[31] |= 64;
|
expanded_key_secret[31] |= 64;
|
||||||
|
|
||||||
h = D::default();
|
h = D::default();
|
||||||
h.input(&hash[32..]);
|
h.digest(&hash[32..]);
|
||||||
h.input(&message);
|
h.digest(&message);
|
||||||
hash.copy_from_slice(h.result().as_slice());
|
hash.copy_from_slice(h.fixed_result().as_slice());
|
||||||
|
|
||||||
mesg_digest = Scalar::reduce(&hash);
|
mesg_digest = Scalar::reduce(&hash);
|
||||||
|
|
||||||
r = ExtendedPoint::basepoint_mult(&mesg_digest);
|
r = &mesg_digest * &constants::ED25519_BASEPOINT;
|
||||||
|
|
||||||
h = D::default();
|
h = D::default();
|
||||||
h.input(&r.compress_edwards().to_bytes()[..]);
|
h.digest(&r.compress_edwards().to_bytes()[..]);
|
||||||
h.input(public_key);
|
h.digest(public_key);
|
||||||
h.input(&message);
|
h.digest(&message);
|
||||||
hash.copy_from_slice(h.result().as_slice());
|
hash.copy_from_slice(h.fixed_result().as_slice());
|
||||||
|
|
||||||
hram_digest = Scalar::reduce(&hash);
|
hram_digest = Scalar::reduce(&hash);
|
||||||
|
|
||||||
|
|
@ -245,12 +244,12 @@ impl PublicKey {
|
||||||
/// Returns true if the signature was successfully verified, and
|
/// Returns true if the signature was successfully verified, and
|
||||||
/// false otherwise.
|
/// false otherwise.
|
||||||
pub fn verify<D>(&self, message: &[u8], signature: &Signature) -> bool
|
pub fn verify<D>(&self, message: &[u8], signature: &Signature) -> bool
|
||||||
where D: Digest<OutputSize = U64> + Default {
|
where D: FixedOutput<OutputSize = U64> + Default + Input {
|
||||||
|
|
||||||
let mut h: D = D::default();
|
let mut h: D = D::default();
|
||||||
let mut a: ExtendedPoint;
|
let mut a: ExtendedPoint;
|
||||||
let ao: Option<ExtendedPoint>;
|
let ao: Option<ExtendedPoint>;
|
||||||
let r: ProjectivePoint;
|
let r: ExtendedPoint;
|
||||||
let digest: [u8; 64];
|
let digest: [u8; 64];
|
||||||
let digest_reduced: Scalar;
|
let digest_reduced: Scalar;
|
||||||
|
|
||||||
|
|
@ -269,14 +268,14 @@ impl PublicKey {
|
||||||
let top_half: &[u8; 32] = array_ref!(&signature.0, 32, 32);
|
let top_half: &[u8; 32] = array_ref!(&signature.0, 32, 32);
|
||||||
let bottom_half: &[u8; 32] = array_ref!(&signature.0, 0, 32);
|
let bottom_half: &[u8; 32] = array_ref!(&signature.0, 0, 32);
|
||||||
|
|
||||||
h.input(&bottom_half[..]);
|
h.digest(&bottom_half[..]);
|
||||||
h.input(&self.to_bytes());
|
h.digest(&self.to_bytes());
|
||||||
h.input(&message);
|
h.digest(&message);
|
||||||
|
|
||||||
let digest_bytes = h.result();
|
let digest_bytes = h.fixed_result();
|
||||||
digest = *array_ref!(digest_bytes, 0, 64);
|
digest = *array_ref!(digest_bytes, 0, 64);
|
||||||
digest_reduced = Scalar::reduce(&digest);
|
digest_reduced = Scalar::reduce(&digest);
|
||||||
r = curve::double_scalar_mult_vartime(&digest_reduced, &a, &Scalar(*top_half));
|
r = &(&digest_reduced * &a) + &(&Scalar(*top_half) * &constants::ED25519_BASEPOINT);
|
||||||
|
|
||||||
if arrays_equal_ct(bottom_half, &r.compress_edwards().to_bytes()) == 1 {
|
if arrays_equal_ct(bottom_half, &r.compress_edwards().to_bytes()) == 1 {
|
||||||
return true
|
return true
|
||||||
|
|
@ -334,7 +333,7 @@ impl Keypair {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[allow(unused_assignments)]
|
#[allow(unused_assignments)]
|
||||||
pub fn generate<D>(cspring: &mut Rng) -> Keypair
|
pub fn generate<D>(cspring: &mut Rng) -> Keypair
|
||||||
where D: Digest<OutputSize = U64> + Default {
|
where D: FixedOutput<OutputSize = U64> + Default + Input {
|
||||||
|
|
||||||
let mut h: D = D::default();
|
let mut h: D = D::default();
|
||||||
let mut hash: [u8; 64] = [0u8; 64];
|
let mut hash: [u8; 64] = [0u8; 64];
|
||||||
|
|
@ -345,15 +344,15 @@ impl Keypair {
|
||||||
|
|
||||||
cspring.fill_bytes(&mut t);
|
cspring.fill_bytes(&mut t);
|
||||||
|
|
||||||
h.input(&t);
|
h.digest(&t);
|
||||||
hash.copy_from_slice(h.result().as_slice());
|
hash.copy_from_slice(h.fixed_result().as_slice());
|
||||||
|
|
||||||
digest = array_mut_ref!(&mut hash, 0, 32);
|
digest = array_mut_ref!(&mut hash, 0, 32);
|
||||||
digest[0] &= 248;
|
digest[0] &= 248;
|
||||||
digest[31] &= 127;
|
digest[31] &= 127;
|
||||||
digest[31] |= 64;
|
digest[31] |= 64;
|
||||||
|
|
||||||
pk = ExtendedPoint::basepoint_mult(&Scalar(*digest)).compress_edwards().to_bytes();
|
pk = (&Scalar(*digest) * &constants::ED25519_BASEPOINT).compress_edwards().to_bytes();
|
||||||
|
|
||||||
for i in 0..32 {
|
for i in 0..32 {
|
||||||
sk[i] = t[i];
|
sk[i] = t[i];
|
||||||
|
|
@ -369,13 +368,13 @@ impl Keypair {
|
||||||
|
|
||||||
/// Sign a message with this keypair's secret key.
|
/// Sign a message with this keypair's secret key.
|
||||||
pub fn sign<D>(&self, message: &[u8]) -> Signature
|
pub fn sign<D>(&self, message: &[u8]) -> Signature
|
||||||
where D: Digest<OutputSize = U64> + Default {
|
where D: FixedOutput<OutputSize = U64> + Default + Input {
|
||||||
self.secret.sign::<D>(message)
|
self.secret.sign::<D>(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify a signature on a message with this keypair's public key.
|
/// Verify a signature on a message with this keypair's public key.
|
||||||
pub fn verify<D>(&self, message: &[u8], signature: &Signature) -> bool
|
pub fn verify<D>(&self, message: &[u8], signature: &Signature) -> bool
|
||||||
where D: Digest<OutputSize = U64> + Default {
|
where D: FixedOutput<OutputSize = U64> + Default + Input {
|
||||||
self.public.verify::<D>(message, signature)
|
self.public.verify::<D>(message, signature)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue