Bitcoin Core  22.99.0
P2P Digital Currency
crypto_aes256.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 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 <crypto/aes.h>
7 #include <test/fuzz/fuzz.h>
8 #include <test/fuzz/util.h>
9 
10 #include <cassert>
11 #include <cstdint>
12 #include <vector>
13 
14 FUZZ_TARGET(crypto_aes256)
15 {
16  FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
17  const std::vector<uint8_t> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, AES256_KEYSIZE);
18 
19  AES256Encrypt encrypt{key.data()};
20  AES256Decrypt decrypt{key.data()};
21 
22  while (fuzzed_data_provider.ConsumeBool()) {
23  const std::vector<uint8_t> plaintext = ConsumeFixedLengthByteVector(fuzzed_data_provider, AES_BLOCKSIZE);
24  std::vector<uint8_t> ciphertext(AES_BLOCKSIZE);
25  encrypt.Encrypt(ciphertext.data(), plaintext.data());
26  std::vector<uint8_t> decrypted_plaintext(AES_BLOCKSIZE);
27  decrypt.Decrypt(decrypted_plaintext.data(), ciphertext.data());
28  assert(decrypted_plaintext == plaintext);
29  }
30 }
assert
assert(!tx.IsCoinBase())
util.h
AES256_KEYSIZE
static const int AES256_KEYSIZE
Definition: aes.h:15
aes.h
FUZZ_TARGET
FUZZ_TARGET(crypto_aes256)
Definition: crypto_aes256.cpp:14
FuzzedDataProvider.h
AES256Encrypt
An encryption class for AES-256.
Definition: aes.h:18
AES_BLOCKSIZE
static const int AES_BLOCKSIZE
Definition: aes.h:14
fuzz.h
FuzzedDataProvider
Definition: FuzzedDataProvider.h:31
ConsumeFixedLengthByteVector
std::vector< uint8_t > ConsumeFixedLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const size_t length) noexcept
Returns a byte vector of specified size regardless of the number of remaining bytes available from th...
Definition: util.h:230
AES256Decrypt
A decryption class for AES-256.
Definition: aes.h:30