Skip to content

Commit 29f1d9b

Browse files
committed
Fuzz test for BIP324 key derivation
1 parent f9cb346 commit 29f1d9b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/test/fuzz/net.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <chainparams.h>
66
#include <chainparamsbase.h>
7+
#include <key.h>
78
#include <net.h>
89
#include <net_permissions.h>
910
#include <netaddress.h>
@@ -17,6 +18,7 @@
1718
#include <test/util/setup_common.h>
1819
#include <util/asmap.h>
1920

21+
#include <cstddef>
2022
#include <cstdint>
2123
#include <optional>
2224
#include <string>
@@ -77,3 +79,22 @@ FUZZ_TARGET_INIT(net, initialize_net)
7779
(void)node.HasPermission(net_permission_flags);
7880
(void)node.ConnectedThroughNetwork();
7981
}
82+
83+
void initialize_chainparams()
84+
{
85+
SelectParams(CBaseChainParams::REGTEST);
86+
}
87+
88+
FUZZ_TARGET_INIT(bip324_session_derivation, initialize_chainparams)
89+
{
90+
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
91+
92+
ECDHSecret ecdh_secret;
93+
auto ecdh_secret_bytes = fuzzed_data_provider.ConsumeBytes<std::byte>(ECDH_SECRET_SIZE);
94+
ecdh_secret_bytes.resize(ECDH_SECRET_SIZE);
95+
96+
memcpy(ecdh_secret.data(), ecdh_secret_bytes.data(), ECDH_SECRET_SIZE);
97+
98+
BIP324Session session;
99+
DeriveBIP324Session(std::move(ecdh_secret), session);
100+
}

0 commit comments

Comments
 (0)