Fix for secp256k1 ffi changes
All tests pass, compile now
This commit is contained in:
parent
d495d9ca06
commit
5a6c6c8d0a
21
src/ffi.rs
21
src/ffi.rs
|
@ -14,11 +14,14 @@
|
|||
//
|
||||
|
||||
//! FFI bindings
|
||||
use libc::{c_int, c_uchar};
|
||||
use libc::{c_int, c_uchar, c_uint};
|
||||
|
||||
pub const SECP256K1_START_VERIFY: c_uint = 0x1;
|
||||
pub const SECP256K1_START_SIGN: c_uint = 0x2;
|
||||
|
||||
#[link(name = "secp256k1")]
|
||||
extern "C" {
|
||||
pub fn secp256k1_start();
|
||||
pub fn secp256k1_start(flags: c_uint);
|
||||
|
||||
pub fn secp256k1_stop();
|
||||
|
||||
|
@ -27,7 +30,7 @@ extern "C" {
|
|||
pk: *const c_uchar, pk_len: c_int)
|
||||
-> c_int;
|
||||
|
||||
pub fn secp256k1_ecdsa_pubkey_create(pk: *mut c_uchar, pk_len : *mut c_int,
|
||||
pub fn secp256k1_ec_pubkey_create(pk: *mut c_uchar, pk_len: *mut c_int,
|
||||
sk: *const c_uchar, compressed: c_int)
|
||||
-> c_int;
|
||||
|
||||
|
@ -46,25 +49,25 @@ extern "C" {
|
|||
pk_len: *mut c_int, compressed: c_int,
|
||||
recid: c_int) -> c_int;
|
||||
|
||||
pub fn secp256k1_ecdsa_seckey_verify(sk: *const c_uchar) -> c_int;
|
||||
pub fn secp256k1_ec_seckey_verify(sk: *const c_uchar) -> c_int;
|
||||
|
||||
pub fn secp256k1_ecdsa_pubkey_verify(pk: *const c_uchar,
|
||||
pub fn secp256k1_ec_pubkey_verify(pk: *const c_uchar,
|
||||
pk_len: c_int) -> c_int;
|
||||
|
||||
pub fn secp256k1_ecdsa_privkey_tweak_add(sk: *mut c_uchar,
|
||||
pub fn secp256k1_ec_privkey_tweak_add(sk: *mut c_uchar,
|
||||
tweak: *const c_uchar)
|
||||
-> c_int;
|
||||
|
||||
pub fn secp256k1_ecdsa_pubkey_tweak_add(pk: *mut c_uchar,
|
||||
pub fn secp256k1_ec_pubkey_tweak_add(pk: *mut c_uchar,
|
||||
pk_len: c_int,
|
||||
tweak: *const c_uchar)
|
||||
-> c_int;
|
||||
|
||||
pub fn secp256k1_ecdsa_privkey_tweak_mul(sk: *mut c_uchar,
|
||||
pub fn secp256k1_ec_privkey_tweak_mul(sk: *mut c_uchar,
|
||||
tweak: *const c_uchar)
|
||||
-> c_int;
|
||||
|
||||
pub fn secp256k1_ecdsa_pubkey_tweak_mul(pk: *mut c_uchar,
|
||||
pub fn secp256k1_ec_pubkey_tweak_mul(pk: *mut c_uchar,
|
||||
pk_len: c_int,
|
||||
tweak: *const c_uchar)
|
||||
-> c_int;
|
||||
|
|
12
src/key.rs
12
src/key.rs
|
@ -164,7 +164,7 @@ impl SecretKey {
|
|||
init();
|
||||
let mut data = random_32_bytes(rng);
|
||||
unsafe {
|
||||
while ffi::secp256k1_ecdsa_seckey_verify(data.as_ptr()) == 0 {
|
||||
while ffi::secp256k1_ec_seckey_verify(data.as_ptr()) == 0 {
|
||||
data = random_32_bytes(rng);
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ impl SecretKey {
|
|||
constants::SECRET_KEY_SIZE => {
|
||||
let mut ret = [0; constants::SECRET_KEY_SIZE];
|
||||
unsafe {
|
||||
if ffi::secp256k1_ecdsa_seckey_verify(data.as_ptr()) == 0 {
|
||||
if ffi::secp256k1_ec_seckey_verify(data.as_ptr()) == 0 {
|
||||
return Err(InvalidSecretKey);
|
||||
}
|
||||
copy_nonoverlapping_memory(ret.as_mut_ptr(),
|
||||
|
@ -200,7 +200,7 @@ impl SecretKey {
|
|||
pub fn add_assign(&mut self, other: &SecretKey) -> Result<()> {
|
||||
init();
|
||||
unsafe {
|
||||
if ffi::secp256k1_ecdsa_privkey_tweak_add(self.as_mut_ptr(), other.as_ptr()) != 1 {
|
||||
if ffi::secp256k1_ec_privkey_tweak_add(self.as_mut_ptr(), other.as_ptr()) != 1 {
|
||||
Err(Unknown)
|
||||
} else {
|
||||
Ok(())
|
||||
|
@ -257,7 +257,7 @@ impl PublicKey {
|
|||
unsafe {
|
||||
// We can assume the return value because it's not possible to construct
|
||||
// an invalid `SecretKey` without transmute trickery or something
|
||||
assert_eq!(ffi::secp256k1_ecdsa_pubkey_create(
|
||||
assert_eq!(ffi::secp256k1_ec_pubkey_create(
|
||||
pk.as_mut_ptr(), &mut len,
|
||||
sk.as_ptr(), compressed), 1);
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ impl PublicKey {
|
|||
constants::COMPRESSED_PUBLIC_KEY_SIZE => {
|
||||
let mut ret = [0; constants::COMPRESSED_PUBLIC_KEY_SIZE];
|
||||
unsafe {
|
||||
if ffi::secp256k1_ecdsa_pubkey_verify(data.as_ptr(),
|
||||
if ffi::secp256k1_ec_pubkey_verify(data.as_ptr(),
|
||||
data.len() as ::libc::c_int) == 0 {
|
||||
return Err(InvalidPublicKey);
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ impl PublicKey {
|
|||
pub fn add_exp_assign(&mut self, other: &SecretKey) -> Result<()> {
|
||||
init();
|
||||
unsafe {
|
||||
if ffi::secp256k1_ecdsa_pubkey_tweak_add(self.as_mut_ptr(),
|
||||
if ffi::secp256k1_ec_pubkey_tweak_add(self.as_mut_ptr(),
|
||||
self.len() as ::libc::c_int,
|
||||
other.as_ptr()) != 1 {
|
||||
Err(Unknown)
|
||||
|
|
|
@ -150,7 +150,8 @@ pub struct Secp256k1 {
|
|||
pub fn init() {
|
||||
unsafe {
|
||||
Secp256k1_init.call_once(|| {
|
||||
ffi::secp256k1_start();
|
||||
ffi::secp256k1_start(ffi::SECP256K1_START_VERIFY |
|
||||
ffi::SECP256K1_START_SIGN);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue