bitcoin core ipc fuzz coverage

Coverage Report

Created: 2026-08-26 16:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/home/enochazariah/dev/bitcoin-invariants/src/wallet/test/fuzz/crypter.cpp
Line
Count
Source
1
// Copyright (c) 2022-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 <test/fuzz/FuzzedDataProvider.h>
6
#include <test/fuzz/fuzz.h>
7
#include <test/fuzz/util.h>
8
#include <test/util/setup_common.h>
9
#include <wallet/crypter.h>
10
11
namespace wallet {
12
namespace {
13
14
void initialize_crypter()
15
0
{
16
0
    static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
17
0
}
18
19
FUZZ_TARGET(crypter, .init = initialize_crypter)
20
0
{
21
0
    SeedRandomStateForTest(SeedRand::ZEROS);
22
0
    FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
23
0
    bool good_data{true};
24
25
0
    CCrypter crypt;
26
    // These values are regularly updated within `CallOneOf`
27
0
    std::vector<unsigned char> cipher_text_ed;
28
0
    CKeyingMaterial plain_text_ed;
29
0
    const std::vector<unsigned char> random_key = ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_KEY_SIZE);
30
31
0
    if (fuzzed_data_provider.ConsumeBool()) {
32
0
        const std::string random_string = fuzzed_data_provider.ConsumeRandomLengthString(100);
33
0
        SecureString secure_string(random_string.begin(), random_string.end());
34
35
0
        const unsigned int derivation_method = fuzzed_data_provider.ConsumeBool() ? 0 : fuzzed_data_provider.ConsumeIntegral<unsigned int>();
36
37
        // Limiting the value of rounds since it is otherwise uselessly expensive and causes a timeout when fuzzing.
38
0
        crypt.SetKeyFromPassphrase(/*key_data=*/secure_string,
39
0
                                   /*salt=*/ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_SALT_SIZE),
40
0
                                   /*rounds=*/fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, CMasterKey::DEFAULT_DERIVE_ITERATIONS),
41
0
                                   /*derivation_method=*/derivation_method);
42
0
    }
43
44
0
    CKey random_ckey;
45
0
    random_ckey.Set(random_key.begin(), random_key.end(), /*fCompressedIn=*/fuzzed_data_provider.ConsumeBool());
46
0
    if (!random_ckey.IsValid()) return;
47
0
    CPubKey pubkey{random_ckey.GetPubKey()};
48
49
0
    LIMITED_WHILE (good_data && fuzzed_data_provider.ConsumeBool(), 100) {
Line
Count
Source
23
0
    for (unsigned _count{limit}; (condition) && _count; --_count)
50
0
        CallOneOf(
51
0
            fuzzed_data_provider,
52
0
            [&] {
53
0
                const std::vector<unsigned char> random_vector = ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_KEY_SIZE);
54
0
                plain_text_ed = CKeyingMaterial(random_vector.begin(), random_vector.end());
55
0
            },
56
0
            [&] {
57
0
                cipher_text_ed = ConsumeRandomLengthByteVector(fuzzed_data_provider, 64);
58
0
            },
59
0
            [&] {
60
0
                (void)crypt.Encrypt(plain_text_ed, cipher_text_ed);
61
0
            },
62
0
            [&] {
63
0
                (void)crypt.Decrypt(cipher_text_ed, plain_text_ed);
64
0
            },
65
0
            [&] {
66
0
                const CKeyingMaterial master_key(random_key.begin(), random_key.end());
67
0
                (void)EncryptSecret(master_key, plain_text_ed, pubkey.GetHash(), cipher_text_ed);
68
0
            },
69
0
            [&] {
70
0
                std::optional<CPubKey> random_pub_key{ConsumeDeserializable<CPubKey>(fuzzed_data_provider)};
71
0
                if (!random_pub_key) {
72
0
                    good_data = false;
73
0
                    return;
74
0
                }
75
0
                pubkey = *random_pub_key;
76
0
            },
77
0
            [&] {
78
0
                const CKeyingMaterial master_key(random_key.begin(), random_key.end());
79
0
                CKey key;
80
0
                (void)DecryptKey(master_key, cipher_text_ed, pubkey, key);
81
0
            });
82
0
    }
83
0
}
84
} // namespace
85
} // namespace wallet