Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a feature to disable replacing C symbols with rust #177

Merged
merged 2 commits into from
Oct 29, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ path = "src/lib.rs"
[features]
unstable = []
default = ["std"]
fuzztarget = []
std = ["rand/std"]
recovery = []
endomorphism = []
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]
rand = "0.6"
rand_core = "0.4"
Expand Down
5 changes: 3 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ fn main() {
.define("USE_NUM_NONE", Some("1"))
.define("USE_FIELD_INV_BUILTIN", Some("1"))
.define("USE_SCALAR_INV_BUILTIN", Some("1"))
.define("ENABLE_MODULE_ECDH", Some("1"))
.define("USE_EXTERNAL_DEFAULT_CALLBACKS", Some("1"));
.define("ENABLE_MODULE_ECDH", Some("1"));

if cfg!(feature = "lowmemory") {
base_config.define("ECMULT_WINDOW_SIZE", Some("4")); // A low-enough value to consume neglible memory
} else {
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")]
base_config.define("USE_ENDOMORPHISM", Some("1"));
#[cfg(feature = "recovery")]
Expand Down
6 changes: 4 additions & 2 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ extern "C" {
}


#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(feature = "dont_replace_c_symbols")))]
#[no_mangle]
/// A reimplementation of the C function `secp256k1_context_create` in rust.
///
Expand All @@ -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)
}

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


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

#[cfg(not(feature = "dont_replace_c_symbols"))]
#[no_mangle]
/// **This function is an override for the C function, this is the an edited version of the original description:**
///
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ mod tests {


#[test]
#[cfg(not(feature = "dont_replace_c_symbols"))]
fn test_manual_create_destroy() {
let ctx_full = unsafe { ffi::secp256k1_context_create(AllPreallocated::FLAGS) };
let ctx_sign = unsafe { ffi::secp256k1_context_create(SignOnlyPreallocated::FLAGS) };
Expand Down