Skip to content

Commit

Permalink
Fuzz tests for CPubKey<->EllSwift
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv committed Jul 20, 2022
1 parent 5072b2c commit a58c16b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/fuzz/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#include <script/signingprovider.h>
#include <script/standard.h>
#include <streams.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <util/strencodings.h>

#include <array>
#include <cassert>
#include <cstdint>
#include <numeric>
Expand Down Expand Up @@ -306,3 +308,21 @@ FUZZ_TARGET_INIT(key, initialize_key)
}
}
}

FUZZ_TARGET_INIT(ellswift, initialize_key)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
auto pubkey_bytes = fuzzed_data_provider.ConsumeBytes<uint8_t>(CPubKey::COMPRESSED_SIZE);
pubkey_bytes.resize(CPubKey::COMPRESSED_SIZE);
CPubKey pubkey(pubkey_bytes.begin(), pubkey_bytes.end());

if (!pubkey.IsFullyValid()) {
return;
}

auto rnd32 = fuzzed_data_provider.ConsumeBytes<uint8_t>(32);
rnd32.resize(32);
std::array<uint8_t, 32> rnd32_array;
std::copy(rnd32.begin(), rnd32.end(), rnd32_array.begin());
(void)pubkey.EllSwiftEncode(rnd32_array);
}

0 comments on commit a58c16b

Please sign in to comment.