Merge pull request #177 from elichai/2019-10-csymbols

Add a feature to disable replacing C symbols with rust
This commit is contained in:
Andrew Poelstra 2019-10-29 01:39:08 +00:00 committed by GitHub
commit d900dcd1c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 5 deletions

View File

@ -28,12 +28,16 @@ path = "src/lib.rs"
[features] [features]
unstable = [] unstable = []
default = ["std"] default = ["std"]
fuzztarget = []
std = ["rand/std"] std = ["rand/std"]
recovery = [] recovery = []
endomorphism = [] endomorphism = []
lowmemory = [] lowmemory = []
# Do not use this feature! HAZMAT. (meant for Bitcoin Core only)
dont_replace_c_symbols = []
# Do not use this feature! HAZMAT. (meant for Fuzzing only. this is *BROKEN CRYPTOGRAPHY*)
fuzztarget = []
[dev-dependencies] [dev-dependencies]
rand = "0.6" rand = "0.6"
rand_core = "0.4" rand_core = "0.4"

View File

@ -51,14 +51,15 @@ fn main() {
.define("USE_NUM_NONE", Some("1")) .define("USE_NUM_NONE", Some("1"))
.define("USE_FIELD_INV_BUILTIN", Some("1")) .define("USE_FIELD_INV_BUILTIN", Some("1"))
.define("USE_SCALAR_INV_BUILTIN", Some("1")) .define("USE_SCALAR_INV_BUILTIN", Some("1"))
.define("ENABLE_MODULE_ECDH", Some("1")) .define("ENABLE_MODULE_ECDH", Some("1"));
.define("USE_EXTERNAL_DEFAULT_CALLBACKS", Some("1"));
if cfg!(feature = "lowmemory") { if cfg!(feature = "lowmemory") {
base_config.define("ECMULT_WINDOW_SIZE", Some("4")); // A low-enough value to consume neglible memory base_config.define("ECMULT_WINDOW_SIZE", Some("4")); // A low-enough value to consume neglible memory
} else { } else {
base_config.define("ECMULT_WINDOW_SIZE", Some("15")); // This is the default in the configure file (`auto`) base_config.define("ECMULT_WINDOW_SIZE", Some("15")); // This is the default in the configure file (`auto`)
} }
#[cfg(not(feature = "dont_replace_c_symbols"))]
base_config.define("USE_EXTERNAL_DEFAULT_CALLBACKS", Some("1"));
#[cfg(feature = "endomorphism")] #[cfg(feature = "endomorphism")]
base_config.define("USE_ENDOMORPHISM", Some("1")); base_config.define("USE_ENDOMORPHISM", Some("1"));
#[cfg(feature = "recovery")] #[cfg(feature = "recovery")]

View File

@ -256,7 +256,7 @@ extern "C" {
} }
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(feature = "dont_replace_c_symbols")))]
#[no_mangle] #[no_mangle]
/// A reimplementation of the C function `secp256k1_context_create` in rust. /// A reimplementation of the C function `secp256k1_context_create` in rust.
/// ///
@ -281,7 +281,7 @@ pub unsafe extern "C" fn secp256k1_context_create(flags: c_uint) -> *mut Context
secp256k1_context_preallocated_create(ptr as *mut c_void, flags) secp256k1_context_preallocated_create(ptr as *mut c_void, flags)
} }
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(feature = "dont_replace_c_symbols")))]
#[no_mangle] #[no_mangle]
/// A reimplementation of the C function `secp256k1_context_destroy` in rust. /// A reimplementation of the C function `secp256k1_context_destroy` in rust.
/// ///
@ -300,6 +300,7 @@ pub unsafe extern "C" fn secp256k1_context_destroy(ctx: *mut Context) {
} }
#[cfg(not(feature = "dont_replace_c_symbols"))]
#[no_mangle] #[no_mangle]
/// **This function is an override for the C function, this is the an edited version of the original description:** /// **This function is an override for the C function, this is the an edited version of the original description:**
/// ///
@ -326,6 +327,7 @@ pub unsafe extern "C" fn secp256k1_default_illegal_callback_fn(message: *const c
panic!("[libsecp256k1] illegal argument. {}", msg); panic!("[libsecp256k1] illegal argument. {}", msg);
} }
#[cfg(not(feature = "dont_replace_c_symbols"))]
#[no_mangle] #[no_mangle]
/// **This function is an override for the C function, this is the an edited version of the original description:** /// **This function is an override for the C function, this is the an edited version of the original description:**
/// ///

View File

@ -723,6 +723,7 @@ mod tests {
#[test] #[test]
#[cfg(not(feature = "dont_replace_c_symbols"))]
fn test_manual_create_destroy() { fn test_manual_create_destroy() {
let ctx_full = unsafe { ffi::secp256k1_context_create(AllPreallocated::FLAGS) }; let ctx_full = unsafe { ffi::secp256k1_context_create(AllPreallocated::FLAGS) };
let ctx_sign = unsafe { ffi::secp256k1_context_create(SignOnlyPreallocated::FLAGS) }; let ctx_sign = unsafe { ffi::secp256k1_context_create(SignOnlyPreallocated::FLAGS) };