Bitcoin Core
31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
src
test
fuzz
key_io.cpp
Go to the documentation of this file.
1
// Copyright (c) 2020-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#include <chainparams.h>
6
#include <
key_io.h
>
7
#include <
test/fuzz/fuzz.h
>
8
#include <
util/chaintype.h
>
9
10
#include <cassert>
11
#include <cstdint>
12
#include <string>
13
#include <vector>
14
15
void
initialize_key_io
()
16
{
17
static
ECC_Context
ecc_context
{};
18
SelectParams
(
ChainType::MAIN
);
19
}
20
21
FUZZ_TARGET
(
key_io
, .
init
=
initialize_key_io
)
22
{
23
const
std::string
random_string
(buffer.begin(), buffer.end());
24
25
const
CKey
key =
DecodeSecret
(
random_string
);
26
if
(key.
IsValid
()) {
27
assert
(key ==
DecodeSecret
(
EncodeSecret
(key)));
28
}
29
30
const
CExtKey
ext_key
=
DecodeExtKey
(
random_string
);
31
if
(
ext_key
.key.size() == 32) {
32
assert
(
ext_key
==
DecodeExtKey
(
EncodeExtKey
(
ext_key
)));
33
}
34
35
const
CExtPubKey
ext_pub_key
=
DecodeExtPubKey
(
random_string
);
36
if
(
ext_pub_key
.pubkey.size() ==
CPubKey::COMPRESSED_SIZE
) {
37
assert
(
ext_pub_key
==
DecodeExtPubKey
(
EncodeExtPubKey
(
ext_pub_key
)));
38
}
39
}
ecc_context
ECC_Context ecc_context
Definition
bitcoin-wallet.cpp:126
SelectParams
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain type.
Definition
chainparams.cpp:140
chaintype.h
ChainType::MAIN
@ MAIN
CKey
An encapsulated private key.
Definition
key.h:36
CKey::IsValid
bool IsValid() const
Check whether this private key is valid.
Definition
key.h:124
CPubKey::COMPRESSED_SIZE
static constexpr unsigned int COMPRESSED_SIZE
Definition
pubkey.h:40
ECC_Context
RAII class initializing and deinitializing global state for elliptic curve support.
Definition
key.h:326
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
EncodeExtKey
std::string EncodeExtKey(const CExtKey &key)
Definition
key_io.cpp:283
DecodeExtPubKey
CExtPubKey DecodeExtPubKey(const std::string &str)
Definition
key_io.cpp:244
EncodeSecret
std::string EncodeSecret(const CKey &key)
Definition
key_io.cpp:231
DecodeSecret
CKey DecodeSecret(const std::string &str)
Definition
key_io.cpp:213
EncodeExtPubKey
std::string EncodeExtPubKey(const CExtPubKey &key)
Definition
key_io.cpp:257
DecodeExtKey
CExtKey DecodeExtKey(const std::string &str)
Definition
key_io.cpp:267
key_io.h
init
Definition
bitcoin-gui.cpp:17
CExtKey
Definition
key.h:231
CExtPubKey
Definition
pubkey.h:336
initialize_key_io
void initialize_key_io()
Definition
key_io.cpp:15
random_string
std::string random_string(uint32_t length)
Definition
test_kernel.cpp:29
Ticks
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition
time.h:73
assert
assert(!tx.IsCoinBase())
Generated on Thu Apr 16 2026 09:42:38 for Bitcoin Core by
1.10.0