Skip to content

Commit

Permalink
Fuzz test for BIP324 key derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv committed Nov 20, 2021
1 parent 8d09fb5 commit 8109854
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ test_fuzz_fuzz_SOURCES = \
test/fuzz/banman.cpp \
test/fuzz/base_encode_decode.cpp \
test/fuzz/bech32.cpp \
test/fuzz/bip324.cpp \
test/fuzz/block.cpp \
test/fuzz/block_header.cpp \
test/fuzz/blockfilter.cpp \
Expand Down
35 changes: 35 additions & 0 deletions src/test/fuzz/bip324.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2021 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 <chainparams.h>
#include <key.h>
#include <util/bip324.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/FuzzedDataProvider.h>

void initialize_chainparams()
{
SelectParams(CBaseChainParams::REGTEST);
}

FUZZ_TARGET_INIT(bip324, initialize_chainparams)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};

ECDHSecret ecdh_secret;
ecdh_secret.resize(ECDH_SECRET_SIZE);
auto ecdh_secret_bytes = fuzzed_data_provider.ConsumeBytes<uint8_t>(ECDH_SECRET_SIZE);
ecdh_secret_bytes.resize(ECDH_SECRET_SIZE);

memcpy(ecdh_secret.data(), ecdh_secret_bytes.data(), ECDH_SECRET_SIZE);

auto initiator_hdata_len = fuzzed_data_provider.ConsumeIntegralInRange(0, 4096);
auto initiator_hdata = fuzzed_data_provider.ConsumeBytes<uint8_t>(initiator_hdata_len);

auto responder_hdata_len = fuzzed_data_provider.ConsumeIntegralInRange(0, 4096);
auto responder_hdata = fuzzed_data_provider.ConsumeBytes<uint8_t>(responder_hdata_len);

BIP324Keys bip324_keys{std::move(ecdh_secret), initiator_hdata, responder_hdata};
}

0 comments on commit 8109854

Please sign in to comment.