Skip to content

Commit c3ac9f5

Browse files
dhruvPieter Wuille
authored andcommitted
Fuzz test for CKey->EllSwift->CPubKey creation/decoding
Co-authored-by: Pieter Wuille <[email protected]>
1 parent aae432a commit c3ac9f5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/test/fuzz/key.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
#include <script/signingprovider.h>
1616
#include <script/standard.h>
1717
#include <streams.h>
18+
#include <test/fuzz/FuzzedDataProvider.h>
1819
#include <test/fuzz/fuzz.h>
1920
#include <util/chaintype.h>
2021
#include <util/strencodings.h>
2122

23+
#include <array>
2224
#include <cassert>
2325
#include <cstdint>
2426
#include <numeric>
@@ -303,3 +305,22 @@ FUZZ_TARGET_INIT(key, initialize_key)
303305
}
304306
}
305307
}
308+
309+
FUZZ_TARGET_INIT(ellswift_roundtrip, initialize_key)
310+
{
311+
FuzzedDataProvider fdp{buffer.data(), buffer.size()};
312+
313+
auto key_bytes = fdp.ConsumeBytes<uint8_t>(32);
314+
key_bytes.resize(32);
315+
CKey key;
316+
key.Set(key_bytes.begin(), key_bytes.end(), true);
317+
if (!key.IsValid()) return;
318+
319+
auto ent32 = fdp.ConsumeBytes<std::byte>(32);
320+
ent32.resize(32);
321+
322+
auto encoded_ellswift = key.EllSwiftCreate(ent32);
323+
auto decoded_pubkey = encoded_ellswift.Decode();
324+
325+
assert(key.VerifyPubKey(decoded_pubkey));
326+
}

0 commit comments

Comments
 (0)