From<[u8; 32]> for Ephemeral Public, fix to benches

This commit is contained in:
DebugSteven 2018-12-07 17:51:08 -05:00
parent 8730bfbba6
commit ff0e1f286b
2 changed files with 8 additions and 1 deletions

View file

@ -30,7 +30,6 @@ fn bench_diffie_hellman(c: &mut Criterion) {
let bob_public: EphemeralPublic = EphemeralPublic::from(&bob_secret);
c.bench_function("diffie_hellman", move |b| {
let alice_secret: EphemeralSecret = EphemeralSecret::new(&mut csprng);
b.iter_with_setup(
|| EphemeralSecret::new(&mut csprng),
|alice_secret| EphemeralSecret::diffie_hellman(alice_secret, &bob_public),

View file

@ -25,6 +25,14 @@ use rand_core::CryptoRng;
#[repr(C)]
pub struct EphemeralPublic(pub (crate) MontgomeryPoint);
impl From<[u8; 32]> for EphemeralPublic {
/// Given a byte array, construct an x25519 `EphemeralPublic` key
fn from(bytes: [u8; 32]) -> EphemeralPublic {
EphemeralPublic(MontgomeryPoint(bytes))
}
}
/// A DH ephemeral secret key.
#[repr(C)]
#[derive(Default)] // we derive Default in order to use the clear() method in Drop