mirror of
https://github.com/dalek-cryptography/ed25519-dalek.git
synced 2026-01-10 03:27:59 -05:00
Switch to using new digest v0.5 API.
This commit is contained in:
@@ -27,7 +27,7 @@ optional = true
|
||||
version = "^0.3"
|
||||
|
||||
[dependencies.digest]
|
||||
version = "0.4"
|
||||
version = "^0.5"
|
||||
|
||||
[dependencies.generic-array]
|
||||
# same version that digest depends on
|
||||
@@ -35,7 +35,7 @@ version = "^0.6"
|
||||
|
||||
[dev-dependencies]
|
||||
rustc-serialize = "0.3"
|
||||
sha2 = "^0.4"
|
||||
sha2 = "^0.5"
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
|
||||
@@ -15,7 +15,8 @@ use core::fmt::Debug;
|
||||
#[cfg(feature = "std")]
|
||||
use rand::Rng;
|
||||
|
||||
use digest::Digest;
|
||||
use digest::Input;
|
||||
use digest::FixedOutput;
|
||||
use generic_array::typenum::U64;
|
||||
|
||||
use curve25519_dalek::curve;
|
||||
@@ -137,7 +138,7 @@ impl SecretKey {
|
||||
|
||||
/// Sign a message with this keypair's secret key.
|
||||
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 hash: [u8; 64] = [0u8; 64];
|
||||
@@ -152,8 +153,8 @@ impl SecretKey {
|
||||
let secret_key: &[u8; 32] = array_ref!(&self.0, 0, 32);
|
||||
let public_key: &[u8; 32] = array_ref!(&self.0, 32, 32);
|
||||
|
||||
h.input(secret_key);
|
||||
hash.copy_from_slice(h.result().as_slice());
|
||||
h.digest(secret_key);
|
||||
hash.copy_from_slice(h.fixed_result().as_slice());
|
||||
|
||||
expanded_key_secret = Scalar(*array_ref!(&hash, 0, 32));
|
||||
expanded_key_secret[0] &= 248;
|
||||
@@ -161,19 +162,19 @@ impl SecretKey {
|
||||
expanded_key_secret[31] |= 64;
|
||||
|
||||
h = D::default();
|
||||
h.input(&hash[32..]);
|
||||
h.input(&message);
|
||||
hash.copy_from_slice(h.result().as_slice());
|
||||
h.digest(&hash[32..]);
|
||||
h.digest(&message);
|
||||
hash.copy_from_slice(h.fixed_result().as_slice());
|
||||
|
||||
mesg_digest = Scalar::reduce(&hash);
|
||||
|
||||
r = ExtendedPoint::basepoint_mult(&mesg_digest);
|
||||
|
||||
h = D::default();
|
||||
h.input(&r.compress_edwards().to_bytes()[..]);
|
||||
h.input(public_key);
|
||||
h.input(&message);
|
||||
hash.copy_from_slice(h.result().as_slice());
|
||||
h.digest(&r.compress_edwards().to_bytes()[..]);
|
||||
h.digest(public_key);
|
||||
h.digest(&message);
|
||||
hash.copy_from_slice(h.fixed_result().as_slice());
|
||||
|
||||
hram_digest = Scalar::reduce(&hash);
|
||||
|
||||
@@ -245,7 +246,7 @@ impl PublicKey {
|
||||
/// Returns true if the signature was successfully verified, and
|
||||
/// false otherwise.
|
||||
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 a: ExtendedPoint;
|
||||
@@ -269,11 +270,11 @@ impl PublicKey {
|
||||
let top_half: &[u8; 32] = array_ref!(&signature.0, 32, 32);
|
||||
let bottom_half: &[u8; 32] = array_ref!(&signature.0, 0, 32);
|
||||
|
||||
h.input(&bottom_half[..]);
|
||||
h.input(&self.to_bytes());
|
||||
h.input(&message);
|
||||
h.digest(&bottom_half[..]);
|
||||
h.digest(&self.to_bytes());
|
||||
h.digest(&message);
|
||||
|
||||
let digest_bytes = h.result();
|
||||
let digest_bytes = h.fixed_result();
|
||||
digest = *array_ref!(digest_bytes, 0, 64);
|
||||
digest_reduced = Scalar::reduce(&digest);
|
||||
r = curve::double_scalar_mult_vartime(&digest_reduced, &a, &Scalar(*top_half));
|
||||
@@ -334,7 +335,7 @@ impl Keypair {
|
||||
#[cfg(feature = "std")]
|
||||
#[allow(unused_assignments)]
|
||||
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 hash: [u8; 64] = [0u8; 64];
|
||||
@@ -345,8 +346,8 @@ impl Keypair {
|
||||
|
||||
cspring.fill_bytes(&mut t);
|
||||
|
||||
h.input(&t);
|
||||
hash.copy_from_slice(h.result().as_slice());
|
||||
h.digest(&t);
|
||||
hash.copy_from_slice(h.fixed_result().as_slice());
|
||||
|
||||
digest = array_mut_ref!(&mut hash, 0, 32);
|
||||
digest[0] &= 248;
|
||||
@@ -369,13 +370,13 @@ impl Keypair {
|
||||
|
||||
/// Sign a message with this keypair's secret key.
|
||||
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)
|
||||
}
|
||||
|
||||
/// Verify a signature on a message with this keypair's public key.
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user