Skip to content

Commit 67c9be3

Browse files
authored
Merge pull request #263 from apoelstra/2020-12--no-extsymb
Replace dangerous cargo features with rustc flags
2 parents b31bf2f + 29316ef commit 67c9be3

File tree

9 files changed

+88
-92
lines changed

9 files changed

+88
-92
lines changed

Cargo.toml

-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ endomorphism = ["secp256k1-sys/endomorphism"]
2626
lowmemory = ["secp256k1-sys/lowmemory"]
2727
global-context = ["std", "rand-std"]
2828

29-
# Use this feature to not compile the bundled libsecp256k1 C symbols,
30-
# but use external ones. Use this only if you know what you are doing!
31-
external-symbols = ["secp256k1-sys/external-symbols"]
32-
33-
# Do not use this feature! HAZMAT. (meant for Fuzzing only. this is *BROKEN CRYPTOGRAPHY*)
34-
fuzztarget = ["secp256k1-sys/fuzztarget"]
35-
3629
[dependencies]
3730
secp256k1-sys = { version = "0.3.1", default-features = false, path = "./secp256k1-sys" }
3831
bitcoin_hashes = { version = "0.9", optional = true }

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,12 @@ before_script:
3535
cargo generate-lockfile --verbose && cargo update -p cc --precise "1.0.41" --verbose;
3636
fi
3737
```
38+
39+
## Fuzzing
40+
41+
If you want to fuzz this library, or any library which depends on it, you will
42+
probably want to disable the actual cryptography, since fuzzers are unable to
43+
forge signatures and therefore won't test many interesting codepaths. To instead
44+
use a trivially-broken but fuzzer-accessible signature scheme, compile with
45+
`--cfg=rust_secp_fuzz` in your `RUSTFLAGS` variable.
46+

contrib/test.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
3131
done
3232

3333
# Other combos
34-
cargo test --no-run --verbose --features="fuzztarget"
35-
cargo test --no-run --verbose --features="fuzztarget recovery"
34+
RUSTFLAGS='--cfg=rust_secp_fuzz' cargo test --no-run --verbose
35+
RUSTFLAGS='--cfg=rust_secp_fuzz' cargo test --no-run --verbose --features="recovery"
3636
cargo test --verbose --features="rand rand-std"
3737
cargo test --verbose --features="rand serde"
3838

secp256k1-sys/Cargo.toml

-6
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,3 @@ endomorphism = []
3131
lowmemory = []
3232
std = []
3333

34-
# Use this feature to not compile the bundled libsecp256k1 C symbols,
35-
# but use external ones. Use this only if you know what you are doing!
36-
external-symbols = []
37-
38-
# Do not use this feature! HAZMAT. (meant for Fuzzing only. this is *BROKEN CRYPTOGRAPHY*)
39-
fuzztarget = []

secp256k1-sys/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ $ ./vendor-libsecp.sh depend <version-code> <rev>
2929

3030
## Linking to external symbols
3131

32-
For the more exotic use cases, this crate can be used with existing libsecp256k1
33-
symbols by using the `external-symbols` feature. How to setup rustc to link
34-
against those existing symbols is left as an exercise to the reader.
32+
If you want to compile this library without using the bundled symbols (which may
33+
be required for integration into other build systems), you can do so by adding
34+
`--cfg=rust_secp_no_symbol_renaming'` to your `RUSTFLAGS` variable.
35+

secp256k1-sys/build.rs

-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ extern crate cc;
2626
use std::env;
2727

2828
fn main() {
29-
if cfg!(feature = "external-symbols") {
30-
println!("cargo:rustc-link-lib=static=secp256k1");
31-
return;
32-
}
33-
3429
// Actual build
3530
let mut base_config = cc::Build::new();
3631
base_config.include("depend/secp256k1/")

secp256k1-sys/src/lib.rs

+63-59
Large diffs are not rendered by default.

secp256k1-sys/src/recovery.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//! # FFI of the recovery module
1717
1818
use ::types::*;
19-
#[cfg(not(feature = "fuzztarget"))]
19+
#[cfg(not(rust_secp_fuzz))]
2020
use ::{Context, Signature, NonceFn, PublicKey};
2121

2222
/// Library-internal representation of a Secp256k1 signature + recovery ID
@@ -36,23 +36,23 @@ impl Default for RecoverableSignature {
3636
}
3737
}
3838

39-
#[cfg(not(feature = "fuzztarget"))]
39+
#[cfg(not(rust_secp_fuzz))]
4040
extern "C" {
41-
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_ecdsa_recoverable_signature_parse_compact")]
41+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_3_1_ecdsa_recoverable_signature_parse_compact")]
4242
pub fn secp256k1_ecdsa_recoverable_signature_parse_compact(cx: *const Context, sig: *mut RecoverableSignature,
4343
input64: *const c_uchar, recid: c_int)
4444
-> c_int;
4545

46-
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_ecdsa_recoverable_signature_serialize_compact")]
46+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_3_1_ecdsa_recoverable_signature_serialize_compact")]
4747
pub fn secp256k1_ecdsa_recoverable_signature_serialize_compact(cx: *const Context, output64: *mut c_uchar,
4848
recid: *mut c_int, sig: *const RecoverableSignature)
4949
-> c_int;
5050

51-
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_ecdsa_recoverable_signature_convert")]
51+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_3_1_ecdsa_recoverable_signature_convert")]
5252
pub fn secp256k1_ecdsa_recoverable_signature_convert(cx: *const Context, sig: *mut Signature,
5353
input: *const RecoverableSignature)
5454
-> c_int;
55-
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_ecdsa_sign_recoverable")]
55+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_3_1_ecdsa_sign_recoverable")]
5656
pub fn secp256k1_ecdsa_sign_recoverable(cx: *const Context,
5757
sig: *mut RecoverableSignature,
5858
msg32: *const c_uchar,
@@ -61,7 +61,7 @@ extern "C" {
6161
noncedata: *const c_void)
6262
-> c_int;
6363

64-
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_ecdsa_recover")]
64+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_3_1_ecdsa_recover")]
6565
pub fn secp256k1_ecdsa_recover(cx: *const Context,
6666
pk: *mut PublicKey,
6767
sig: *const RecoverableSignature,
@@ -70,7 +70,7 @@ extern "C" {
7070
}
7171

7272

73-
#[cfg(feature = "fuzztarget")]
73+
#[cfg(rust_secp_fuzz)]
7474
mod fuzz_dummy {
7575
extern crate std;
7676
use self::std::ptr;
@@ -126,6 +126,6 @@ mod fuzz_dummy {
126126
unimplemented!();
127127
}
128128
}
129-
#[cfg(feature = "fuzztarget")]
129+
#[cfg(rust_secp_fuzz)]
130130
pub use self::fuzz_dummy::*;
131131

secp256k1-sys/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl AlignedType {
4040
}
4141
}
4242

43-
#[cfg(all(feature = "std", not(feature = "external-symbols")))]
43+
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
4444
pub(crate) const ALIGN_TO: usize = mem::align_of::<AlignedType>();
4545

4646

0 commit comments

Comments
 (0)