Make key comparison non-fuzzable
Feature guard the custom implementations of `Ord` and `PartialOrd` on `cfg(not(fuzzing))`. When fuzzing, auto-derive implementations. Co-authored-by: Tobin C. Harding <me@tobin.cc>
This commit is contained in:
parent
739660499b
commit
13af51926a
|
@ -379,12 +379,6 @@ extern "C" {
|
|||
tweak: *const c_uchar)
|
||||
-> c_int;
|
||||
|
||||
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_5_0_ec_pubkey_cmp")]
|
||||
pub fn secp256k1_ec_pubkey_cmp(cx: *const Context,
|
||||
pubkey1: *const PublicKey,
|
||||
pubkey2: *const PublicKey)
|
||||
-> c_int;
|
||||
|
||||
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_5_0_keypair_sec")]
|
||||
pub fn secp256k1_keypair_sec(cx: *const Context,
|
||||
output_seckey: *mut c_uchar,
|
||||
|
@ -396,12 +390,6 @@ extern "C" {
|
|||
output_pubkey: *mut PublicKey,
|
||||
keypair: *const KeyPair)
|
||||
-> c_int;
|
||||
|
||||
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_5_0_xonly_pubkey_cmp")]
|
||||
pub fn secp256k1_xonly_pubkey_cmp(cx: *const Context,
|
||||
pubkey1: *const XOnlyPublicKey,
|
||||
pubkey2: *const XOnlyPublicKey)
|
||||
-> c_int;
|
||||
}
|
||||
|
||||
#[cfg(not(fuzzing))]
|
||||
|
@ -446,6 +434,12 @@ extern "C" {
|
|||
pk: *mut PublicKey) -> c_int;
|
||||
|
||||
|
||||
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_5_0_ec_pubkey_cmp")]
|
||||
pub fn secp256k1_ec_pubkey_cmp(cx: *const Context,
|
||||
pubkey1: *const PublicKey,
|
||||
pubkey2: *const PublicKey)
|
||||
-> c_int;
|
||||
|
||||
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_5_0_ec_pubkey_tweak_add")]
|
||||
pub fn secp256k1_ec_pubkey_tweak_add(cx: *const Context,
|
||||
pk: *mut PublicKey,
|
||||
|
@ -552,6 +546,13 @@ extern "C" {
|
|||
pubkey: *const PublicKey,
|
||||
) -> c_int;
|
||||
|
||||
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_5_0_xonly_pubkey_cmp")]
|
||||
pub fn secp256k1_xonly_pubkey_cmp(
|
||||
cx: *const Context,
|
||||
pubkey1: *const XOnlyPublicKey,
|
||||
pubkey2: *const XOnlyPublicKey
|
||||
) -> c_int;
|
||||
|
||||
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_5_0_xonly_pubkey_tweak_add")]
|
||||
pub fn secp256k1_xonly_pubkey_tweak_add(
|
||||
cx: *const Context,
|
||||
|
|
|
@ -82,6 +82,7 @@ pub const ONE_KEY: SecretKey = SecretKey([0, 0, 0, 0, 0, 0, 0, 0,
|
|||
/// # }
|
||||
/// ```
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
|
||||
#[cfg_attr(feature = "fuzzing", derive(PartialOrd, Ord))]
|
||||
#[repr(transparent)]
|
||||
pub struct PublicKey(ffi::PublicKey);
|
||||
|
||||
|
@ -671,12 +672,14 @@ impl<'de> serde::Deserialize<'de> for PublicKey {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(fuzzing))]
|
||||
impl PartialOrd for PublicKey {
|
||||
fn partial_cmp(&self, other: &PublicKey) -> Option<core::cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(fuzzing))]
|
||||
impl Ord for PublicKey {
|
||||
fn cmp(&self, other: &PublicKey) -> core::cmp::Ordering {
|
||||
let ret = unsafe {
|
||||
|
@ -1899,6 +1902,7 @@ mod test {
|
|||
assert_eq!(Ok(sksum), sum1);
|
||||
}
|
||||
|
||||
#[cfg(not(fuzzing))]
|
||||
#[test]
|
||||
fn pubkey_equal() {
|
||||
let pk1 = PublicKey::from_slice(
|
||||
|
@ -1909,7 +1913,7 @@ mod test {
|
|||
&hex!("02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443"),
|
||||
).unwrap();
|
||||
|
||||
assert!(pk1 == pk2);
|
||||
assert_eq!(pk1, pk2);
|
||||
assert!(pk1 <= pk2);
|
||||
assert!(pk2 <= pk1);
|
||||
assert!(!(pk2 < pk1));
|
||||
|
|
Loading…
Reference in New Issue