2021-12-30 19:36:57 +02:00
|
|
|
// Copyright (c) 2020-2021 The Bitcoin Core developers
|
2020-01-14 16:38:36 +00:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <chainparams.h>
|
|
|
|
#include <key_io.h>
|
|
|
|
#include <test/fuzz/fuzz.h>
|
2023-04-17 22:20:59 +02:00
|
|
|
#include <util/chaintype.h>
|
2020-01-14 16:38:36 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-12-03 16:42:49 +01:00
|
|
|
void initialize_key_io()
|
2020-01-14 16:38:36 +00:00
|
|
|
{
|
2024-05-07 08:54:19 -04:00
|
|
|
static ECC_Context ecc_context{};
|
2023-04-17 22:20:59 +02:00
|
|
|
SelectParams(ChainType::MAIN);
|
2020-01-14 16:38:36 +00:00
|
|
|
}
|
|
|
|
|
2023-07-11 14:33:31 +02:00
|
|
|
FUZZ_TARGET(key_io, .init = initialize_key_io)
|
2020-01-14 16:38:36 +00:00
|
|
|
{
|
|
|
|
const std::string random_string(buffer.begin(), buffer.end());
|
|
|
|
|
|
|
|
const CKey key = DecodeSecret(random_string);
|
|
|
|
if (key.IsValid()) {
|
|
|
|
assert(key == DecodeSecret(EncodeSecret(key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
const CExtKey ext_key = DecodeExtKey(random_string);
|
|
|
|
if (ext_key.key.size() == 32) {
|
|
|
|
assert(ext_key == DecodeExtKey(EncodeExtKey(ext_key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
const CExtPubKey ext_pub_key = DecodeExtPubKey(random_string);
|
|
|
|
if (ext_pub_key.pubkey.size() == CPubKey::COMPRESSED_SIZE) {
|
|
|
|
assert(ext_pub_key == DecodeExtPubKey(EncodeExtPubKey(ext_pub_key)));
|
|
|
|
}
|
|
|
|
}
|