|
16 | 16 | #include <script/signingprovider.h>
|
17 | 17 | #include <script/standard.h>
|
18 | 18 | #include <streams.h>
|
| 19 | +#include <test/fuzz/FuzzedDataProvider.h> |
19 | 20 | #include <test/fuzz/fuzz.h>
|
20 | 21 | #include <util/strencodings.h>
|
21 | 22 |
|
| 23 | +#include <array> |
22 | 24 | #include <cassert>
|
23 | 25 | #include <cstdint>
|
24 | 26 | #include <numeric>
|
@@ -306,3 +308,34 @@ FUZZ_TARGET_INIT(key, initialize_key)
|
306 | 308 | }
|
307 | 309 | }
|
308 | 310 | }
|
| 311 | + |
| 312 | +FUZZ_TARGET_INIT(ellswift, initialize_key) |
| 313 | +{ |
| 314 | + FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; |
| 315 | + auto pubkey_bytes = fuzzed_data_provider.ConsumeBytes<uint8_t>(CPubKey::COMPRESSED_SIZE); |
| 316 | + pubkey_bytes.resize(CPubKey::COMPRESSED_SIZE); |
| 317 | + CPubKey pubkey(pubkey_bytes.begin(), pubkey_bytes.end()); |
| 318 | + |
| 319 | + if (!pubkey.IsFullyValid()) { |
| 320 | + return; |
| 321 | + } |
| 322 | + |
| 323 | + auto rnd32 = fuzzed_data_provider.ConsumeBytes<uint8_t>(32); |
| 324 | + rnd32.resize(32); |
| 325 | + std::array<uint8_t, 32> rnd32_array; |
| 326 | + std::copy(rnd32.begin(), rnd32.end(), rnd32_array.begin()); |
| 327 | + auto ellswift_pubkey = pubkey.EllSwiftEncode(rnd32_array); |
| 328 | + |
| 329 | + // only even pubkeys can be ellswift encoded |
| 330 | + assert(ellswift_pubkey.has_value() == (pubkey.data()[0] == 0x02)); |
| 331 | + |
| 332 | + if (!ellswift_pubkey.has_value()) { |
| 333 | + return; |
| 334 | + } |
| 335 | + assert(ellswift_pubkey->size() == ELLSWIFT_ENCODED_SIZE); |
| 336 | + |
| 337 | + CPubKey decoded_pubkey{ellswift_pubkey.value()}; |
| 338 | + assert(decoded_pubkey.IsFullyValid()); |
| 339 | + |
| 340 | + assert(pubkey == decoded_pubkey); |
| 341 | +} |
0 commit comments