Skip to content

Commit d900dcd

Browse files
authored
Merge pull request #177 from elichai/2019-10-csymbols
Add a feature to disable replacing C symbols with rust
2 parents 0db1646 + fe8ac1e commit d900dcd

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ path = "src/lib.rs"
2828
[features]
2929
unstable = []
3030
default = ["std"]
31-
fuzztarget = []
3231
std = ["rand/std"]
3332
recovery = []
3433
endomorphism = []
3534
lowmemory = []
3635

36+
# Do not use this feature! HAZMAT. (meant for Bitcoin Core only)
37+
dont_replace_c_symbols = []
38+
# Do not use this feature! HAZMAT. (meant for Fuzzing only. this is *BROKEN CRYPTOGRAPHY*)
39+
fuzztarget = []
40+
3741
[dev-dependencies]
3842
rand = "0.6"
3943
rand_core = "0.4"

build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ fn main() {
5151
.define("USE_NUM_NONE", Some("1"))
5252
.define("USE_FIELD_INV_BUILTIN", Some("1"))
5353
.define("USE_SCALAR_INV_BUILTIN", Some("1"))
54-
.define("ENABLE_MODULE_ECDH", Some("1"))
55-
.define("USE_EXTERNAL_DEFAULT_CALLBACKS", Some("1"));
54+
.define("ENABLE_MODULE_ECDH", Some("1"));
5655

5756
if cfg!(feature = "lowmemory") {
5857
base_config.define("ECMULT_WINDOW_SIZE", Some("4")); // A low-enough value to consume neglible memory
5958
} else {
6059
base_config.define("ECMULT_WINDOW_SIZE", Some("15")); // This is the default in the configure file (`auto`)
6160
}
61+
#[cfg(not(feature = "dont_replace_c_symbols"))]
62+
base_config.define("USE_EXTERNAL_DEFAULT_CALLBACKS", Some("1"));
6263
#[cfg(feature = "endomorphism")]
6364
base_config.define("USE_ENDOMORPHISM", Some("1"));
6465
#[cfg(feature = "recovery")]

src/ffi.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ extern "C" {
256256
}
257257

258258

259-
#[cfg(feature = "std")]
259+
#[cfg(all(feature = "std", not(feature = "dont_replace_c_symbols")))]
260260
#[no_mangle]
261261
/// A reimplementation of the C function `secp256k1_context_create` in rust.
262262
///
@@ -281,7 +281,7 @@ pub unsafe extern "C" fn secp256k1_context_create(flags: c_uint) -> *mut Context
281281
secp256k1_context_preallocated_create(ptr as *mut c_void, flags)
282282
}
283283

284-
#[cfg(feature = "std")]
284+
#[cfg(all(feature = "std", not(feature = "dont_replace_c_symbols")))]
285285
#[no_mangle]
286286
/// A reimplementation of the C function `secp256k1_context_destroy` in rust.
287287
///
@@ -300,6 +300,7 @@ pub unsafe extern "C" fn secp256k1_context_destroy(ctx: *mut Context) {
300300
}
301301

302302

303+
#[cfg(not(feature = "dont_replace_c_symbols"))]
303304
#[no_mangle]
304305
/// **This function is an override for the C function, this is the an edited version of the original description:**
305306
///
@@ -326,6 +327,7 @@ pub unsafe extern "C" fn secp256k1_default_illegal_callback_fn(message: *const c
326327
panic!("[libsecp256k1] illegal argument. {}", msg);
327328
}
328329

330+
#[cfg(not(feature = "dont_replace_c_symbols"))]
329331
#[no_mangle]
330332
/// **This function is an override for the C function, this is the an edited version of the original description:**
331333
///

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ mod tests {
723723

724724

725725
#[test]
726+
#[cfg(not(feature = "dont_replace_c_symbols"))]
726727
fn test_manual_create_destroy() {
727728
let ctx_full = unsafe { ffi::secp256k1_context_create(AllPreallocated::FLAGS) };
728729
let ctx_sign = unsafe { ffi::secp256k1_context_create(SignOnlyPreallocated::FLAGS) };

0 commit comments

Comments
 (0)