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 Dec 7, 2022
1 parent 585af55 commit d1638ea
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/test/fuzz/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <chainparams.h>
#include <chainparamsbase.h>
#include <key.h>
#include <net.h>
#include <net_permissions.h>
#include <netaddress.h>
Expand All @@ -17,6 +18,7 @@
#include <test/util/setup_common.h>
#include <util/asmap.h>

#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
Expand Down Expand Up @@ -77,3 +79,22 @@ FUZZ_TARGET_INIT(net, initialize_net)
(void)node.HasPermission(net_permission_flags);
(void)node.ConnectedThroughNetwork();
}

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

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

ECDHSecret ecdh_secret;
auto ecdh_secret_bytes = fuzzed_data_provider.ConsumeBytes<std::byte>(ECDH_SECRET_SIZE);
ecdh_secret_bytes.resize(ECDH_SECRET_SIZE);

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

BIP324Session session;
DeriveBIP324Session(std::move(ecdh_secret), session);
}

0 comments on commit d1638ea

Please sign in to comment.