Skip to content

Commit 4383dc9

Browse files
committed
fuzz: fix key size in crypter target
Set a max length for some previous `ConsumeRandomLengthByteVector` usage.
1 parent d2c8d16 commit 4383dc9

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/wallet/test/fuzz/crypter.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,36 @@ FUZZ_TARGET(crypter, .init = initialize_crypter)
2727
// These values are regularly updated within `CallOneOf`
2828
std::vector<unsigned char> cipher_text_ed;
2929
CKeyingMaterial plain_text_ed;
30-
const std::vector<unsigned char> random_key = ConsumeRandomLengthByteVector(fuzzed_data_provider);
30+
const std::vector<unsigned char> random_key = ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_KEY_SIZE);
3131

3232
LIMITED_WHILE(good_data && fuzzed_data_provider.ConsumeBool(), 10000)
3333
{
3434
CallOneOf(
3535
fuzzed_data_provider,
3636
[&] {
37-
const std::string random_string = fuzzed_data_provider.ConsumeRandomLengthString();
37+
const std::string random_string = fuzzed_data_provider.ConsumeRandomLengthString(100);
3838
SecureString secure_string(random_string.begin(), random_string.end());
3939

4040
const unsigned int derivation_method = fuzzed_data_provider.ConsumeBool() ? 0 : fuzzed_data_provider.ConsumeIntegral<unsigned int>();
4141

4242
// Limiting the value of nRounds since it is otherwise uselessly expensive and causes a timeout when fuzzing.
4343
crypt.SetKeyFromPassphrase(/*strKeyData=*/secure_string,
44-
/*chSalt=*/ConsumeRandomLengthByteVector(fuzzed_data_provider),
44+
/*chSalt=*/ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_SALT_SIZE),
4545
/*nRounds=*/fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 25000),
4646
/*nDerivationMethod=*/derivation_method);
4747
},
4848
[&] {
49-
const std::vector<unsigned char> random_vector = ConsumeFixedLengthByteVector(fuzzed_data_provider, 32);
49+
const std::vector<unsigned char> random_vector = ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_KEY_SIZE);
5050
const CKeyingMaterial new_key(random_vector.begin(), random_vector.end());
51-
const std::vector<unsigned char>& new_IV = ConsumeFixedLengthByteVector(fuzzed_data_provider, 16);
51+
const std::vector<unsigned char>& new_IV = ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_IV_SIZE);
5252
crypt.SetKey(new_key, new_IV);
5353
},
5454
[&] {
55-
const std::vector<unsigned char> random_vector = ConsumeRandomLengthByteVector(fuzzed_data_provider);
55+
const std::vector<unsigned char> random_vector = ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_KEY_SIZE);
5656
plain_text_ed = CKeyingMaterial(random_vector.begin(), random_vector.end());
5757
},
5858
[&] {
59-
cipher_text_ed = ConsumeRandomLengthByteVector(fuzzed_data_provider);
59+
cipher_text_ed = ConsumeRandomLengthByteVector(fuzzed_data_provider, 64);
6060
},
6161
[&] {
6262
(void)crypt.Encrypt(plain_text_ed, cipher_text_ed);
@@ -82,7 +82,7 @@ FUZZ_TARGET(crypter, .init = initialize_crypter)
8282
}
8383
const CPubKey pub_key = *random_pub_key;
8484
const CKeyingMaterial master_key(random_key.begin(), random_key.end());
85-
const std::vector<unsigned char> crypted_secret = ConsumeRandomLengthByteVector(fuzzed_data_provider);
85+
const std::vector<unsigned char> crypted_secret = ConsumeRandomLengthByteVector(fuzzed_data_provider, 64);
8686
CKey key;
8787
DecryptKey(master_key, crypted_secret, pub_key, key);
8888
});

0 commit comments

Comments
 (0)