mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-06 10:18:44 -05:00
![Andrew Poelstra](/assets/img/avatar_default.png)
Blindly chose a cap of 10000 iterations for every loop, except for the two in script_ops.cpp and scriptnum_ops.cpp which appeared to (sometimes) be deserializing individual bytes; capped those to one million to ensure that sometimes we try working with massive scripts. There was also one fuzzer-controlled loop in timedata.cpp which was already capped, so I left that alone. git grep 'while (fuzz' should now run clean except for timedata.cpp
30 lines
1.1 KiB
C++
30 lines
1.1 KiB
C++
// Copyright (c) 2020 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 <crypto/aes.h>
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
#include <test/fuzz/fuzz.h>
|
|
#include <test/fuzz/util.h>
|
|
|
|
#include <cassert>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
FUZZ_TARGET(crypto_aes256)
|
|
{
|
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
|
const std::vector<uint8_t> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, AES256_KEYSIZE);
|
|
|
|
AES256Encrypt encrypt{key.data()};
|
|
AES256Decrypt decrypt{key.data()};
|
|
|
|
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
|
|
const std::vector<uint8_t> plaintext = ConsumeFixedLengthByteVector(fuzzed_data_provider, AES_BLOCKSIZE);
|
|
std::vector<uint8_t> ciphertext(AES_BLOCKSIZE);
|
|
encrypt.Encrypt(ciphertext.data(), plaintext.data());
|
|
std::vector<uint8_t> decrypted_plaintext(AES_BLOCKSIZE);
|
|
decrypt.Decrypt(decrypted_plaintext.data(), ciphertext.data());
|
|
assert(decrypted_plaintext == plaintext);
|
|
}
|
|
}
|