bitcoin/src/test/fuzz/key_io.cpp
MarcoFalke fa5f297748
scripted-diff: [doc] Unify stale copyright headers
-BEGIN VERIFY SCRIPT-

 sed --in-place --regexp-extended \
   's;( 20[0-2][0-9])(-20[0-2][0-9])? The Bitcoin Core developers;\1-present The Bitcoin Core developers;g' \
   $( git grep -l 'The Bitcoin Core developers' -- ':(exclude)COPYING' ':(exclude)src/ipc/libmultiprocess' ':(exclude)src/minisketch' )

-END VERIFY SCRIPT-
2025-12-16 22:21:15 +01:00

40 lines
1.1 KiB
C++

// Copyright (c) 2020-present The Bitcoin Core developers
// 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>
#include <util/chaintype.h>
#include <cassert>
#include <cstdint>
#include <string>
#include <vector>
void initialize_key_io()
{
static ECC_Context ecc_context{};
SelectParams(ChainType::MAIN);
}
FUZZ_TARGET(key_io, .init = initialize_key_io)
{
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)));
}
}