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