mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
tests: Add fuzzing harness for SigHasLowR(...) and ecdsa_signature_parse_der_lax(...)
This commit is contained in:
parent
a2a250c7d0
commit
b667a90389
3 changed files with 41 additions and 1 deletions
|
@ -132,6 +132,7 @@ FUZZ_TARGETS = \
|
|||
test/fuzz/script_sigcache \
|
||||
test/fuzz/script_sign \
|
||||
test/fuzz/scriptnum_ops \
|
||||
test/fuzz/secp256k1_ecdsa_signature_parse_der_lax \
|
||||
test/fuzz/service_deserialize \
|
||||
test/fuzz/signature_checker \
|
||||
test/fuzz/snapshotmetadata_deserialize \
|
||||
|
@ -1094,6 +1095,12 @@ test_fuzz_scriptnum_ops_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
|||
test_fuzz_scriptnum_ops_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
test_fuzz_scriptnum_ops_SOURCES = test/fuzz/scriptnum_ops.cpp
|
||||
|
||||
test_fuzz_secp256k1_ecdsa_signature_parse_der_lax_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_secp256k1_ecdsa_signature_parse_der_lax_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_secp256k1_ecdsa_signature_parse_der_lax_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
test_fuzz_secp256k1_ecdsa_signature_parse_der_lax_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
test_fuzz_secp256k1_ecdsa_signature_parse_der_lax_SOURCES = test/fuzz/secp256k1_ecdsa_signature_parse_der_lax.cpp
|
||||
|
||||
test_fuzz_service_deserialize_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DSERVICE_DESERIALIZE=1
|
||||
test_fuzz_service_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_service_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
|
|
|
@ -24,7 +24,7 @@ secp256k1_context* secp256k1_context_verify = nullptr;
|
|||
* strict DER before being passed to this module, and we know it supports all
|
||||
* violations present in the blockchain before that point.
|
||||
*/
|
||||
static int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
|
||||
int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
|
||||
size_t rpos, rlen, spos, slen;
|
||||
size_t pos = 0;
|
||||
size_t lenbyte;
|
||||
|
|
33
src/test/fuzz/secp256k1_ecdsa_signature_parse_der_lax.cpp
Normal file
33
src/test/fuzz/secp256k1_ecdsa_signature_parse_der_lax.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <key.h>
|
||||
#include <secp256k1.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
bool SigHasLowR(const secp256k1_ecdsa_signature* sig);
|
||||
int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char* input, size_t inputlen);
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
const std::vector<uint8_t> signature_bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
if (signature_bytes.data() == nullptr) {
|
||||
return;
|
||||
}
|
||||
secp256k1_context* secp256k1_context_verify = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY);
|
||||
secp256k1_ecdsa_signature sig_der_lax;
|
||||
const bool parsed_der_lax = ecdsa_signature_parse_der_lax(secp256k1_context_verify, &sig_der_lax, signature_bytes.data(), signature_bytes.size()) == 1;
|
||||
if (parsed_der_lax) {
|
||||
ECC_Start();
|
||||
(void)SigHasLowR(&sig_der_lax);
|
||||
ECC_Stop();
|
||||
}
|
||||
secp256k1_context_destroy(secp256k1_context_verify);
|
||||
}
|
Loading…
Add table
Reference in a new issue