Skip context randomization in fuzzing to improve performance

This commit is contained in:
Matt Corallo 2021-02-26 23:20:48 -05:00
parent c486ca10c7
commit 79119e8123
1 changed files with 12 additions and 4 deletions

View File

@ -278,10 +278,6 @@ extern "C" {
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_0_context_preallocated_destroy")] #[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_0_context_preallocated_destroy")]
pub fn secp256k1_context_preallocated_destroy(cx: *mut Context); pub fn secp256k1_context_preallocated_destroy(cx: *mut Context);
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_0_context_randomize")]
pub fn secp256k1_context_randomize(cx: *mut Context,
seed32: *const c_uchar)
-> c_int;
// Signatures // Signatures
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_0_ecdsa_signature_parse_der")] #[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_0_ecdsa_signature_parse_der")]
pub fn secp256k1_ecdsa_signature_parse_der(cx: *const Context, sig: *mut Signature, pub fn secp256k1_ecdsa_signature_parse_der(cx: *const Context, sig: *mut Signature,
@ -369,6 +365,10 @@ extern "C" {
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_0_context_preallocated_clone")] #[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_0_context_preallocated_clone")]
pub fn secp256k1_context_preallocated_clone(cx: *const Context, prealloc: *mut c_void) -> *mut Context; pub fn secp256k1_context_preallocated_clone(cx: *const Context, prealloc: *mut c_void) -> *mut Context;
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_0_context_randomize")]
pub fn secp256k1_context_randomize(cx: *mut Context,
seed32: *const c_uchar)
-> c_int;
// Pubkeys // Pubkeys
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_0_ec_pubkey_parse")] #[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_0_ec_pubkey_parse")]
pub fn secp256k1_ec_pubkey_parse(cx: *const Context, pk: *mut PublicKey, pub fn secp256k1_ec_pubkey_parse(cx: *const Context, pk: *mut PublicKey,
@ -738,6 +738,14 @@ mod fuzz_dummy {
rustsecp256k1_v0_4_0_context_preallocated_clone(cx, prealloc) rustsecp256k1_v0_4_0_context_preallocated_clone(cx, prealloc)
} }
pub unsafe fn secp256k1_context_randomize(cx: *mut Context,
_seed32: *const c_uchar)
-> c_int {
// This function is really slow, and unsuitable for fuzzing
check_context_flags(cx, 0);
1
}
unsafe fn check_context_flags(cx: *const Context, required_flags: c_uint) { unsafe fn check_context_flags(cx: *const Context, required_flags: c_uint) {
assert!(!cx.is_null()); assert!(!cx.is_null());
let cx_flags = if cx == secp256k1_context_no_precomp { let cx_flags = if cx == secp256k1_context_no_precomp {