remove context object from ECDH

This commit is contained in:
Andrew Poelstra 2018-11-06 22:04:02 +00:00
parent 93abca5896
commit 223eb41fd0
1 changed files with 6 additions and 7 deletions

View File

@ -18,7 +18,6 @@
use std::{ops, ptr};
use super::Secp256k1;
use key::{SecretKey, PublicKey};
use ffi;
@ -29,11 +28,11 @@ pub struct SharedSecret(ffi::SharedSecret);
impl SharedSecret {
/// Creates a new shared secret from a pubkey and secret key
#[inline]
pub fn new<C>(secp: &Secp256k1<C>, point: &PublicKey, scalar: &SecretKey) -> SharedSecret {
pub fn new(point: &PublicKey, scalar: &SecretKey) -> SharedSecret {
unsafe {
let mut ss = ffi::SharedSecret::blank();
let res = ffi::secp256k1_ecdh(
secp.ctx,
ffi::secp256k1_context_no_precomp,
&mut ss,
point.as_ptr(),
scalar.as_ptr(),
@ -109,9 +108,9 @@ mod tests {
let (sk1, pk1) = s.generate_keypair(&mut thread_rng());
let (sk2, pk2) = s.generate_keypair(&mut thread_rng());
let sec1 = SharedSecret::new(&s, &pk1, &sk2);
let sec2 = SharedSecret::new(&s, &pk2, &sk1);
let sec_odd = SharedSecret::new(&s, &pk1, &sk1);
let sec1 = SharedSecret::new(&pk1, &sk2);
let sec2 = SharedSecret::new(&pk2, &sk1);
let sec_odd = SharedSecret::new(&pk1, &sk1);
assert_eq!(sec1, sec2);
assert!(sec_odd != sec2);
}
@ -132,7 +131,7 @@ mod benches {
let s = Secp256k1::new();
bh.iter( || {
let res = SharedSecret::new(&s, &pk, &sk);
let res = SharedSecret::new(&pk, &sk);
black_box(res);
});
}