mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-07 20:50:39 +00:00
Merge branch 'release/0.8.1'
This commit is contained in:
commit
5e156e5a7a
3 changed files with 42 additions and 16 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ed25519-dalek"
|
name = "ed25519-dalek"
|
||||||
version = "0.8.0"
|
version = "0.8.1"
|
||||||
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"
|
||||||
|
|
@ -16,7 +16,7 @@ exclude = [ ".gitignore", "TESTVECTORS", "res/*" ]
|
||||||
travis-ci = { repository = "dalek-cryptography/ed25519-dalek", branch = "master"}
|
travis-ci = { repository = "dalek-cryptography/ed25519-dalek", branch = "master"}
|
||||||
|
|
||||||
[dependencies.curve25519-dalek]
|
[dependencies.curve25519-dalek]
|
||||||
version = "0.19"
|
version = "0.20"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[dependencies.rand]
|
[dependencies.rand]
|
||||||
|
|
|
||||||
|
|
@ -777,22 +777,36 @@ impl PublicKey {
|
||||||
/// Derive this public key from its corresponding `SecretKey`.
|
/// Derive this public key from its corresponding `SecretKey`.
|
||||||
#[allow(unused_assignments)]
|
#[allow(unused_assignments)]
|
||||||
pub fn from_secret<D>(secret_key: &SecretKey) -> PublicKey
|
pub fn from_secret<D>(secret_key: &SecretKey) -> PublicKey
|
||||||
where D: Digest<OutputSize = U64> + Default {
|
where D: Digest<OutputSize = U64> + Default
|
||||||
|
{
|
||||||
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];
|
||||||
let mut digest: [u8; 32] = [0u8; 32];
|
let mut digest: [u8; 32] = [0u8; 32];
|
||||||
let pk: [u8; 32];
|
|
||||||
|
|
||||||
h.input(secret_key.as_bytes());
|
h.input(secret_key.as_bytes());
|
||||||
hash.copy_from_slice(h.fixed_result().as_slice());
|
hash.copy_from_slice(h.fixed_result().as_slice());
|
||||||
|
|
||||||
digest.copy_from_slice(&hash[..32]);
|
digest.copy_from_slice(&hash[..32]);
|
||||||
digest[0] &= 248;
|
|
||||||
digest[31] &= 127;
|
|
||||||
digest[31] |= 64;
|
|
||||||
|
|
||||||
pk = (&Scalar::from_bits(digest) * &constants::ED25519_BASEPOINT_TABLE).compress().to_bytes();
|
PublicKey::mangle_scalar_bits_and_multiply_by_basepoint_to_produce_public_key(&mut digest)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Derive this public key from its corresponding `ExpandedSecretKey`.
|
||||||
|
pub fn from_expanded_secret(expanded_secret_key: &ExpandedSecretKey) -> PublicKey {
|
||||||
|
let mut bits: [u8; 32] = expanded_secret_key.key.to_bytes();
|
||||||
|
|
||||||
|
PublicKey::mangle_scalar_bits_and_multiply_by_basepoint_to_produce_public_key(&mut bits)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Internal utility function for mangling the bits of a (formerly
|
||||||
|
/// mathematically well-defined) "scalar" and multiplying it to produce a
|
||||||
|
/// public key.
|
||||||
|
fn mangle_scalar_bits_and_multiply_by_basepoint_to_produce_public_key(bits: &mut [u8; 32]) -> PublicKey {
|
||||||
|
bits[0] &= 248;
|
||||||
|
bits[31] &= 127;
|
||||||
|
bits[31] |= 64;
|
||||||
|
|
||||||
|
let pk = (&Scalar::from_bits(*bits) * &constants::ED25519_BASEPOINT_TABLE).compress().to_bytes();
|
||||||
|
|
||||||
PublicKey(CompressedEdwardsY(pk))
|
PublicKey(CompressedEdwardsY(pk))
|
||||||
}
|
}
|
||||||
|
|
@ -885,6 +899,12 @@ impl PublicKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ExpandedSecretKey> for PublicKey {
|
||||||
|
fn from(source: ExpandedSecretKey) -> PublicKey {
|
||||||
|
PublicKey::from_expanded_secret(&source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Verify a batch of `signatures` on `messages` with their respective `public_keys`.
|
/// Verify a batch of `signatures` on `messages` with their respective `public_keys`.
|
||||||
///
|
///
|
||||||
/// # Inputs
|
/// # Inputs
|
||||||
|
|
@ -1221,7 +1241,7 @@ impl Keypair {
|
||||||
/// # let prehashed: Sha512 = Sha512::default();
|
/// # let prehashed: Sha512 = Sha512::default();
|
||||||
/// # prehashed.input(message);
|
/// # prehashed.input(message);
|
||||||
/// #
|
/// #
|
||||||
/// let context: &[u8] = "Ed25519DalekSignPrehashedDoctest";
|
/// let context: &[u8] = b"Ed25519DalekSignPrehashedDoctest";
|
||||||
///
|
///
|
||||||
/// let sig: Signature = keypair.sign_prehashed(prehashed, Some(context));
|
/// let sig: Signature = keypair.sign_prehashed(prehashed, Some(context));
|
||||||
/// # }
|
/// # }
|
||||||
|
|
@ -1285,7 +1305,7 @@ impl Keypair {
|
||||||
/// let prehashed: Sha512 = Sha512::default();
|
/// let prehashed: Sha512 = Sha512::default();
|
||||||
/// prehashed.input(message);
|
/// prehashed.input(message);
|
||||||
///
|
///
|
||||||
/// let context: &[u8] = "Ed25519DalekSignPrehashedDoctest";
|
/// let context: &[u8] = b"Ed25519DalekSignPrehashedDoctest";
|
||||||
///
|
///
|
||||||
/// let sig: Signature = keypair.sign_prehashed(prehashed, Some(context));
|
/// let sig: Signature = keypair.sign_prehashed(prehashed, Some(context));
|
||||||
///
|
///
|
||||||
|
|
@ -1595,6 +1615,17 @@ mod test {
|
||||||
assert!(!as_bytes(&keypair).contains(&0x15));
|
assert!(!as_bytes(&keypair).contains(&0x15));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pubkey_from_secret_and_expanded_secret() {
|
||||||
|
let mut csprng = thread_rng();
|
||||||
|
let secret: SecretKey = SecretKey::generate::<_>(&mut csprng);
|
||||||
|
let expanded_secret: ExpandedSecretKey = ExpandedSecretKey::from_secret_key::<Sha512>(&secret);
|
||||||
|
let public_from_secret: PublicKey = PublicKey::from_secret::<Sha512>(&secret);
|
||||||
|
let public_from_expanded_secret: PublicKey = PublicKey::from_expanded_secret(&expanded_secret);
|
||||||
|
|
||||||
|
assert!(public_from_secret == public_from_expanded_secret);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(test, feature = "serde"))]
|
#[cfg(all(test, feature = "serde"))]
|
||||||
use bincode::{serialize, deserialize, Infinite};
|
use bincode::{serialize, deserialize, Infinite};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -254,8 +254,6 @@
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![cfg_attr(feature = "nightly", feature(rand))]
|
|
||||||
#![cfg_attr(feature = "bench", feature(test))]
|
|
||||||
#![allow(unused_features)]
|
#![allow(unused_features)]
|
||||||
#![deny(missing_docs)] // refuse to compile if documentation is missing
|
#![deny(missing_docs)] // refuse to compile if documentation is missing
|
||||||
|
|
||||||
|
|
@ -276,9 +274,6 @@ extern crate sha2;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate hex;
|
extern crate hex;
|
||||||
|
|
||||||
#[cfg(all(test, feature = "bench"))]
|
|
||||||
extern crate test;
|
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue