From d1638eac13ec1d5d05d84fa28d956a227c564380 Mon Sep 17 00:00:00 2001 From: dhruv <856960+dhruv@users.noreply.github.com> Date: Thu, 18 Nov 2021 15:28:52 -0800 Subject: [PATCH] Fuzz test for BIP324 key derivation --- src/test/fuzz/net.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/fuzz/net.cpp b/src/test/fuzz/net.cpp index 9f7c87dcd..17207bd96 100644 --- a/src/test/fuzz/net.cpp +++ b/src/test/fuzz/net.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include #include +#include #include #include #include @@ -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(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); +}