diff options
Diffstat (limited to 'src/wallet/test/fuzz/crypter.cpp')
-rw-r--r-- | src/wallet/test/fuzz/crypter.cpp | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/src/wallet/test/fuzz/crypter.cpp b/src/wallet/test/fuzz/crypter.cpp index 62dd1bfde0..7869f5f39c 100644 --- a/src/wallet/test/fuzz/crypter.cpp +++ b/src/wallet/test/fuzz/crypter.cpp @@ -27,36 +27,31 @@ FUZZ_TARGET(crypter, .init = initialize_crypter) // These values are regularly updated within `CallOneOf` std::vector<unsigned char> cipher_text_ed; CKeyingMaterial plain_text_ed; - const std::vector<unsigned char> random_key = ConsumeRandomLengthByteVector(fuzzed_data_provider); + const std::vector<unsigned char> random_key = ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_KEY_SIZE); - LIMITED_WHILE(good_data && fuzzed_data_provider.ConsumeBool(), 10000) + if (fuzzed_data_provider.ConsumeBool()) { + const std::string random_string = fuzzed_data_provider.ConsumeRandomLengthString(100); + SecureString secure_string(random_string.begin(), random_string.end()); + + const unsigned int derivation_method = fuzzed_data_provider.ConsumeBool() ? 0 : fuzzed_data_provider.ConsumeIntegral<unsigned int>(); + + // Limiting the value of rounds since it is otherwise uselessly expensive and causes a timeout when fuzzing. + crypt.SetKeyFromPassphrase(/*key_data=*/secure_string, + /*salt=*/ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_SALT_SIZE), + /*rounds=*/fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 25000), + /*derivation_method=*/derivation_method); + } + + LIMITED_WHILE(good_data && fuzzed_data_provider.ConsumeBool(), 100) { CallOneOf( fuzzed_data_provider, [&] { - const std::string random_string = fuzzed_data_provider.ConsumeRandomLengthString(); - SecureString secure_string(random_string.begin(), random_string.end()); - - const unsigned int derivation_method = fuzzed_data_provider.ConsumeBool() ? 0 : fuzzed_data_provider.ConsumeIntegral<unsigned int>(); - - // Limiting the value of nRounds since it is otherwise uselessly expensive and causes a timeout when fuzzing. - crypt.SetKeyFromPassphrase(/*strKeyData=*/secure_string, - /*chSalt=*/ConsumeRandomLengthByteVector(fuzzed_data_provider), - /*nRounds=*/fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 25000), - /*nDerivationMethod=*/derivation_method); - }, - [&] { - const std::vector<unsigned char> random_vector = ConsumeFixedLengthByteVector(fuzzed_data_provider, 32); - const CKeyingMaterial new_key(random_vector.begin(), random_vector.end()); - const std::vector<unsigned char>& new_IV = ConsumeFixedLengthByteVector(fuzzed_data_provider, 16); - crypt.SetKey(new_key, new_IV); - }, - [&] { - const std::vector<unsigned char> random_vector = ConsumeRandomLengthByteVector(fuzzed_data_provider); + const std::vector<unsigned char> random_vector = ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_KEY_SIZE); plain_text_ed = CKeyingMaterial(random_vector.begin(), random_vector.end()); }, [&] { - cipher_text_ed = ConsumeRandomLengthByteVector(fuzzed_data_provider); + cipher_text_ed = ConsumeRandomLengthByteVector(fuzzed_data_provider, 64); }, [&] { (void)crypt.Encrypt(plain_text_ed, cipher_text_ed); @@ -67,12 +62,12 @@ FUZZ_TARGET(crypter, .init = initialize_crypter) [&] { const CKeyingMaterial master_key(random_key.begin(), random_key.end()); const uint256 iv = ConsumeUInt256(fuzzed_data_provider); - EncryptSecret(master_key, plain_text_ed, iv, cipher_text_ed); + (void)EncryptSecret(master_key, plain_text_ed, iv, cipher_text_ed); }, [&] { const CKeyingMaterial master_key(random_key.begin(), random_key.end()); const uint256 iv = ConsumeUInt256(fuzzed_data_provider); - DecryptSecret(master_key, cipher_text_ed, iv, plain_text_ed); + (void)DecryptSecret(master_key, cipher_text_ed, iv, plain_text_ed); }, [&] { std::optional<CPubKey> random_pub_key = ConsumeDeserializable<CPubKey>(fuzzed_data_provider); @@ -82,9 +77,9 @@ FUZZ_TARGET(crypter, .init = initialize_crypter) } const CPubKey pub_key = *random_pub_key; const CKeyingMaterial master_key(random_key.begin(), random_key.end()); - const std::vector<unsigned char> crypted_secret = ConsumeRandomLengthByteVector(fuzzed_data_provider); + const std::vector<unsigned char> crypted_secret = ConsumeRandomLengthByteVector(fuzzed_data_provider, 64); CKey key; - DecryptKey(master_key, crypted_secret, pub_key, key); + (void)DecryptKey(master_key, crypted_secret, pub_key, key); }); } } |