Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ If you want to fuzz this library, or any library which depends on it, you will
probably want to disable the actual cryptography, since fuzzers are unable to
forge signatures and therefore won't test many interesting codepaths. To instead
use a trivially-broken but fuzzer-accessible signature scheme, compile with
`--cfg=fuzzing` in your `RUSTFLAGS` variable.
`--cfg=secp256k1_fuzz` in your `RUSTFLAGS` variable.

Note that `cargo hfuzz` sets this config flag automatically.
Note that `cargo hfuzz` does **not** set this config flag automatically. In 0.27.0
and earlier versions, we used the `--cfg=fuzzing` which honggfuzz does set, but we
changed this because there was no way to override it.

6 changes: 3 additions & 3 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
cargo test --all --no-default-features --features="std,$feature"
done
# Other combos
RUSTFLAGS='--cfg=fuzzing' RUSTDOCFLAGS='--cfg=fuzzing' cargo test --all
RUSTFLAGS='--cfg=fuzzing' RUSTDOCFLAGS='--cfg=fuzzing' cargo test --all --features="$FEATURES"
RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all
RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --features="$FEATURES"
cargo test --all --features="rand serde"

if [ "$NIGHTLY" = true ]; then
cargo test --all --all-features
RUSTFLAGS='--cfg=fuzzing' RUSTDOCFLAGS='--cfg=fuzzing' cargo test --all --all-features
RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --all-features
fi

# Examples
Expand Down
56 changes: 28 additions & 28 deletions secp256k1-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern crate core;
#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(fuzzing)]
#[cfg(secp256k1_fuzz)]
const THIS_UNUSED_CONSTANT_IS_YOUR_WARNING_THAT_ALL_THE_CRYPTO_IN_THIS_LIB_IS_DISABLED_FOR_FUZZING: usize = 0;

mod macros;
Expand Down Expand Up @@ -133,7 +133,7 @@ impl SchnorrSigExtraParams {
/// Library-internal representation of a Secp256k1 public key
#[repr(C)]
#[derive(Copy, Clone)]
#[cfg_attr(fuzzing, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
#[cfg_attr(secp256k1_fuzz, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
pub struct PublicKey([c_uchar; 64]);
impl_array_newtype!(PublicKey, c_uchar, 64);
impl_raw_debug!(PublicKey);
Expand Down Expand Up @@ -190,14 +190,14 @@ impl PublicKey {
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl PartialOrd for PublicKey {
fn partial_cmp(&self, other: &PublicKey) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl Ord for PublicKey {
fn cmp(&self, other: &PublicKey) -> core::cmp::Ordering {
let ret = unsafe {
Expand All @@ -207,17 +207,17 @@ impl Ord for PublicKey {
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl PartialEq for PublicKey {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == core::cmp::Ordering::Equal
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl Eq for PublicKey {}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl core::hash::Hash for PublicKey {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
let ser = self.serialize();
Expand All @@ -228,7 +228,7 @@ impl core::hash::Hash for PublicKey {
/// Library-internal representation of a Secp256k1 signature
#[repr(C)]
#[derive(Copy, Clone)]
#[cfg_attr(fuzzing, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
#[cfg_attr(secp256k1_fuzz, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
pub struct Signature([c_uchar; 64]);
impl_array_newtype!(Signature, c_uchar, 64);
impl_raw_debug!(Signature);
Expand Down Expand Up @@ -281,14 +281,14 @@ impl Signature {
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl PartialOrd for Signature {
fn partial_cmp(&self, other: &Signature) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl Ord for Signature {
fn cmp(&self, other: &Signature) -> core::cmp::Ordering {
let this = self.serialize();
Expand All @@ -297,17 +297,17 @@ impl Ord for Signature {
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl PartialEq for Signature {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == core::cmp::Ordering::Equal
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl Eq for Signature {}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl core::hash::Hash for Signature {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
let ser = self.serialize();
Expand All @@ -317,7 +317,7 @@ impl core::hash::Hash for Signature {

#[repr(C)]
#[derive(Copy, Clone)]
#[cfg_attr(fuzzing, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
#[cfg_attr(secp256k1_fuzz, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
pub struct XOnlyPublicKey([c_uchar; 64]);
impl_array_newtype!(XOnlyPublicKey, c_uchar, 64);
impl_raw_debug!(XOnlyPublicKey);
Expand Down Expand Up @@ -370,14 +370,14 @@ impl XOnlyPublicKey {
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl PartialOrd for XOnlyPublicKey {
fn partial_cmp(&self, other: &XOnlyPublicKey) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl Ord for XOnlyPublicKey {
fn cmp(&self, other: &XOnlyPublicKey) -> core::cmp::Ordering {
let ret = unsafe {
Expand All @@ -387,17 +387,17 @@ impl Ord for XOnlyPublicKey {
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl PartialEq for XOnlyPublicKey {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == core::cmp::Ordering::Equal
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl Eq for XOnlyPublicKey {}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl core::hash::Hash for XOnlyPublicKey {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
let ser = self.serialize();
Expand All @@ -407,7 +407,7 @@ impl core::hash::Hash for XOnlyPublicKey {

#[repr(C)]
#[derive(Copy, Clone)]
#[cfg_attr(fuzzing, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
#[cfg_attr(secp256k1_fuzz, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
pub struct KeyPair([c_uchar; 96]);
impl_array_newtype!(KeyPair, c_uchar, 96);
impl_raw_debug!(KeyPair);
Expand Down Expand Up @@ -492,14 +492,14 @@ pub fn non_secure_erase_impl<T>(dst: &mut T, src: T) {
atomic::compiler_fence(atomic::Ordering::SeqCst);
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl PartialOrd for KeyPair {
fn partial_cmp(&self, other: &KeyPair) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl Ord for KeyPair {
fn cmp(&self, other: &KeyPair) -> core::cmp::Ordering {
let this = self.public_key();
Expand All @@ -508,17 +508,17 @@ impl Ord for KeyPair {
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl PartialEq for KeyPair {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == core::cmp::Ordering::Equal
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl Eq for KeyPair {}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl core::hash::Hash for KeyPair {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
// To hash the key pair we just hash the serialized public key. Since any change to the
Expand Down Expand Up @@ -615,7 +615,7 @@ extern "C" {
-> c_int;
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
extern "C" {
// Contexts
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_8_1_context_preallocated_size")]
Expand Down Expand Up @@ -996,7 +996,7 @@ impl<T> CPtr for [T] {
}
}

#[cfg(fuzzing)]
#[cfg(secp256k1_fuzz)]
mod fuzz_dummy {
use super::*;
use core::sync::atomic::{AtomicUsize, Ordering};
Expand Down Expand Up @@ -1482,7 +1482,7 @@ mod fuzz_dummy {
}
}

#[cfg(fuzzing)]
#[cfg(secp256k1_fuzz)]
pub use self::fuzz_dummy::*;

#[cfg(test)]
Expand Down
18 changes: 9 additions & 9 deletions secp256k1-sys/src/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use core::fmt;
/// Library-internal representation of a Secp256k1 signature + recovery ID
#[repr(C)]
#[derive(Copy, Clone)]
#[cfg_attr(fuzzing, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
#[cfg_attr(secp256k1_fuzz, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
pub struct RecoverableSignature([c_uchar; 65]);
impl_array_newtype!(RecoverableSignature, c_uchar, 65);

Expand Down Expand Up @@ -78,14 +78,14 @@ impl fmt::Debug for RecoverableSignature {
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl PartialOrd for RecoverableSignature {
fn partial_cmp(&self, other: &RecoverableSignature) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl Ord for RecoverableSignature {
fn cmp(&self, other: &RecoverableSignature) -> core::cmp::Ordering {
let this = self.serialize();
Expand All @@ -94,17 +94,17 @@ impl Ord for RecoverableSignature {
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl PartialEq for RecoverableSignature {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == core::cmp::Ordering::Equal
}
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl Eq for RecoverableSignature {}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
impl core::hash::Hash for RecoverableSignature {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
let ser = self.serialize();
Expand All @@ -129,7 +129,7 @@ extern "C" {
-> c_int;
}

#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
extern "C" {
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_8_1_ecdsa_sign_recoverable")]
pub fn secp256k1_ecdsa_sign_recoverable(cx: *const Context,
Expand All @@ -149,7 +149,7 @@ extern "C" {
}


#[cfg(fuzzing)]
#[cfg(secp256k1_fuzz)]
mod fuzz_dummy {
use core::slice;

Expand Down Expand Up @@ -221,5 +221,5 @@ mod fuzz_dummy {
}
}

#[cfg(fuzzing)]
#[cfg(secp256k1_fuzz)]
pub use self::fuzz_dummy::*;
2 changes: 1 addition & 1 deletion src/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ mod tests {
}

#[test]
#[cfg(not(fuzzing))]
#[cfg(not(secp256k1_fuzz))]
#[cfg(all(feature = "bitcoin-hashes-std", feature = "rand-std"))]
fn bitcoin_hashes_and_sys_generate_same_secret() {
use bitcoin_hashes::{sha256, Hash, HashEngine};
Expand Down
2 changes: 1 addition & 1 deletion src/ecdsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl<C: Signing> Secp256k1<C> {
entropy_p = extra_entropy.as_c_ptr().cast::<ffi::types::c_void>();

// When fuzzing, these checks will usually spinloop forever, so just short-circuit them.
#[cfg(fuzzing)]
#[cfg(secp256k1_fuzz)]
return Signature::from(ret);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ecdsa/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ mod tests {
}

#[test]
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(not(secp256k1_fuzz))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(feature = "rand-std")]
#[rustfmt::skip]
fn sign() {
Expand All @@ -289,7 +289,7 @@ mod tests {
}

#[test]
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(not(secp256k1_fuzz))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(feature = "rand-std")]
#[rustfmt::skip]
fn sign_with_noncedata() {
Expand Down
Loading