|
4 | 4 |
|
5 | 5 | #include <chainparams.h>
|
6 | 6 | #include <chainparamsbase.h>
|
| 7 | +#include <key.h> |
7 | 8 | #include <net.h>
|
8 | 9 | #include <net_permissions.h>
|
9 | 10 | #include <netaddress.h>
|
@@ -87,3 +88,35 @@ FUZZ_TARGET_INIT(net, initialize_net)
|
87 | 88 | (void)node.HasPermission(net_permission_flags);
|
88 | 89 | (void)node.ConnectedThroughNetwork();
|
89 | 90 | }
|
| 91 | + |
| 92 | +void initialize_chainparams() |
| 93 | +{ |
| 94 | + SelectParams(CBaseChainParams::REGTEST); |
| 95 | +} |
| 96 | + |
| 97 | +FUZZ_TARGET_INIT(bip324, initialize_chainparams) |
| 98 | +{ |
| 99 | + FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; |
| 100 | + |
| 101 | + ECDHSecret ecdh_secret; |
| 102 | + ecdh_secret.resize(ECDH_SECRET_SIZE); |
| 103 | + auto ecdh_secret_bytes = fuzzed_data_provider.ConsumeBytes<uint8_t>(ECDH_SECRET_SIZE); |
| 104 | + ecdh_secret_bytes.resize(ECDH_SECRET_SIZE); |
| 105 | + |
| 106 | + memcpy(ecdh_secret.data(), ecdh_secret_bytes.data(), ECDH_SECRET_SIZE); |
| 107 | + |
| 108 | + auto initiator_hdata_len = fuzzed_data_provider.ConsumeIntegralInRange(0, 4096); |
| 109 | + auto initiator_hdata = fuzzed_data_provider.ConsumeBytes<uint8_t>(initiator_hdata_len); |
| 110 | + |
| 111 | + auto responder_hdata_len = fuzzed_data_provider.ConsumeIntegralInRange(0, 4096); |
| 112 | + auto responder_hdata = fuzzed_data_provider.ConsumeBytes<uint8_t>(responder_hdata_len); |
| 113 | + |
| 114 | + BIP324Keys keys; |
| 115 | + assert(DeriveBIP324Keys(std::move(ecdh_secret), initiator_hdata, responder_hdata, keys)); |
| 116 | + assert(keys.initiator_F.size() == BIP324_KEY_LEN); |
| 117 | + assert(keys.initiator_V.size() == BIP324_KEY_LEN); |
| 118 | + assert(keys.responder_F.size() == BIP324_KEY_LEN); |
| 119 | + assert(keys.responder_V.size() == BIP324_KEY_LEN); |
| 120 | + assert(keys.session_id.size() == BIP324_KEY_LEN); |
| 121 | + assert("0000000000000000000000000000000000000000000000000000000000000000" == HexStr(ecdh_secret)); |
| 122 | +} |
0 commit comments