diff --git a/src/test/fuzz/net.cpp b/src/test/fuzz/net.cpp index bd1bb79d0e..78a0647d02 100644 --- a/src/test/fuzz/net.cpp +++ b/src/test/fuzz/net.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -87,3 +88,35 @@ 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, 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(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(initiator_hdata_len); + + auto responder_hdata_len = fuzzed_data_provider.ConsumeIntegralInRange(0, 4096); + auto responder_hdata = fuzzed_data_provider.ConsumeBytes(responder_hdata_len); + + BIP324Keys keys; + assert(derive_bip324_keys(std::move(ecdh_secret), initiator_hdata, responder_hdata, keys)); + assert(keys.initiator_F.size() == BIP324_KEY_LEN); + assert(keys.initiator_V.size() == BIP324_KEY_LEN); + assert(keys.responder_F.size() == BIP324_KEY_LEN); + assert(keys.responder_V.size() == BIP324_KEY_LEN); + assert(keys.session_id.size() == BIP324_KEY_LEN); + assert("0000000000000000000000000000000000000000000000000000000000000000" == HexStr(ecdh_secret)); +}