Skip to content

Commit 1605bde

Browse files
elichaiapoelstra
authored andcommitted
replace privkey functions with seckey functions, deprecate privkey functions
1 parent f19c6bb commit 1605bde

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

secp256k1-sys/src/lib.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,32 +243,51 @@ extern "C" {
243243
//TODO secp256k1_ec_privkey_export
244244
//TODO secp256k1_ec_privkey_import
245245

246+
#[deprecated(since = "0.2.0",note = "Please use the secp256k1_ec_seckey_tweak_add function instead")]
246247
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_2_0_ec_privkey_negate")]
247248
pub fn secp256k1_ec_privkey_negate(cx: *const Context,
248249
sk: *mut c_uchar) -> c_int;
249250

251+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_2_0_ec_privkey_negate")]
252+
pub fn secp256k1_ec_seckey_negate(cx: *const Context,
253+
sk: *mut c_uchar) -> c_int;
254+
250255
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_2_0_ec_pubkey_negate")]
251256
pub fn secp256k1_ec_pubkey_negate(cx: *const Context,
252257
pk: *mut PublicKey) -> c_int;
253258

259+
#[deprecated(since = "0.2.0",note = "Please use the secp256k1_ec_seckey_tweak_add function instead")]
254260
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_2_0_ec_privkey_tweak_add")]
255261
pub fn secp256k1_ec_privkey_tweak_add(cx: *const Context,
256262
sk: *mut c_uchar,
257263
tweak: *const c_uchar)
258264
-> c_int;
259265

266+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_2_0_ec_seckey_tweak_add")]
267+
pub fn secp256k1_ec_seckey_tweak_add(cx: *const Context,
268+
sk: *mut c_uchar,
269+
tweak: *const c_uchar)
270+
-> c_int;
271+
260272
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_2_0_ec_pubkey_tweak_add")]
261273
pub fn secp256k1_ec_pubkey_tweak_add(cx: *const Context,
262274
pk: *mut PublicKey,
263275
tweak: *const c_uchar)
264276
-> c_int;
265277

278+
#[deprecated(since = "0.2.0",note = "Please use the secp256k1_ec_seckey_tweak_mul function instead")]
266279
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_2_0_ec_privkey_tweak_mul")]
267280
pub fn secp256k1_ec_privkey_tweak_mul(cx: *const Context,
268281
sk: *mut c_uchar,
269282
tweak: *const c_uchar)
270283
-> c_int;
271284

285+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_2_0_ec_seckey_tweak_mul")]
286+
pub fn secp256k1_ec_seckey_tweak_mul(cx: *const Context,
287+
sk: *mut c_uchar,
288+
tweak: *const c_uchar)
289+
-> c_int;
290+
272291
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_2_0_ec_pubkey_tweak_mul")]
273292
pub fn secp256k1_ec_pubkey_tweak_mul(cx: *const Context,
274293
pk: *mut PublicKey,
@@ -287,7 +306,7 @@ extern "C" {
287306
cx: *const Context,
288307
output: *mut c_uchar,
289308
pubkey: *const PublicKey,
290-
privkey: *const c_uchar,
309+
seckey: *const c_uchar,
291310
hashfp: EcdhHashFn,
292311
data: *mut c_void,
293312
) -> c_int;
@@ -413,7 +432,7 @@ unsafe fn strlen(mut str_ptr: *const c_char) -> usize {
413432
/// A trait for producing pointers that will always be valid in C. (assuming NULL pointer is a valid no-op)
414433
/// Rust doesn't promise what pointers does it give to ZST (https://doc.rust-lang.org/nomicon/exotic-sizes.html#zero-sized-types-zsts)
415434
/// In case the type is empty this trait will give a NULL pointer, which should be handled in C.
416-
///
435+
///
417436
pub trait CPtr {
418437
type Target;
419438
fn as_c_ptr(&self) -> *const Self::Target;
@@ -702,8 +721,14 @@ mod fuzz_dummy {
702721
//TODO secp256k1_ec_privkey_export
703722
//TODO secp256k1_ec_privkey_import
704723

724+
#[deprecated(since = "0.2.0",note = "Please use the secp256k1_ec_seckey_negate function instead")]
705725
pub unsafe fn secp256k1_ec_privkey_negate(cx: *const Context,
706726
sk: *mut c_uchar) -> c_int {
727+
secp256k1_ec_seckey_negate(cx, sk)
728+
}
729+
730+
pub unsafe fn secp256k1_ec_seckey_negate(cx: *const Context,
731+
sk: *mut c_uchar) -> c_int {
707732
assert!(!cx.is_null() && (*cx).0 as u32 & !(SECP256K1_START_NONE | SECP256K1_START_VERIFY | SECP256K1_START_SIGN) == 0);
708733
if secp256k1_ec_seckey_verify(cx, sk) != 1 { return 0; }
709734
1
@@ -721,6 +746,13 @@ mod fuzz_dummy {
721746
sk: *mut c_uchar,
722747
tweak: *const c_uchar)
723748
-> c_int {
749+
secp256k1_ec_seckey_tweak_add(cx, sk, tweak)
750+
}
751+
752+
pub unsafe fn secp256k1_ec_seckey_tweak_add(cx: *const Context,
753+
sk: *mut c_uchar,
754+
tweak: *const c_uchar)
755+
-> c_int {
724756
assert!(!cx.is_null() && (*cx).0 as u32 & !(SECP256K1_START_NONE | SECP256K1_START_VERIFY | SECP256K1_START_SIGN) == 0);
725757
if secp256k1_ec_seckey_verify(cx, sk) != 1 { return 0; }
726758
ptr::copy(tweak.offset(16), sk.offset(16), 16);
@@ -747,6 +779,14 @@ mod fuzz_dummy {
747779
sk: *mut c_uchar,
748780
tweak: *const c_uchar)
749781
-> c_int {
782+
secp256k1_ec_seckey_tweak_mul(cx, sk, tweak)
783+
}
784+
785+
/// Copies the last 16 bytes of tweak into the last 16 bytes of sk
786+
pub unsafe fn secp256k1_ec_seckey_tweak_mul(cx: *const Context,
787+
sk: *mut c_uchar,
788+
tweak: *const c_uchar)
789+
-> c_int {
750790
assert!(!cx.is_null() && (*cx).0 as u32 & !(SECP256K1_START_NONE | SECP256K1_START_VERIFY | SECP256K1_START_SIGN) == 0);
751791
if secp256k1_ec_seckey_verify(cx, sk) != 1 { return 0; }
752792
ptr::copy(tweak.offset(16), sk.offset(16), 16);

0 commit comments

Comments
 (0)