mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-06 10:18:44 -05:00
fae216a73d
-BEGIN VERIFY SCRIPT- # Rename sed -i -e 's/MakeFuzzingContext/MakeNoLogFileContext/g' $(git grep -l MakeFuzzingContext) # Bump the copyright of touched files in this scripted diff to avoid touching them again later ./contrib/devtools/copyright_header.py update ./src/test/fuzz/ -END VERIFY SCRIPT-
45 lines
1.8 KiB
C++
45 lines
1.8 KiB
C++
// Copyright (c) 2020-2021 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/chacha20.h>
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
#include <test/fuzz/fuzz.h>
|
|
#include <test/fuzz/util.h>
|
|
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
FUZZ_TARGET(crypto_chacha20)
|
|
{
|
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
|
|
|
ChaCha20 chacha20;
|
|
if (fuzzed_data_provider.ConsumeBool()) {
|
|
const std::vector<unsigned char> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(16, 32));
|
|
chacha20 = ChaCha20{key.data(), key.size()};
|
|
}
|
|
while (fuzzed_data_provider.ConsumeBool()) {
|
|
CallOneOf(
|
|
fuzzed_data_provider,
|
|
[&] {
|
|
const std::vector<unsigned char> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(16, 32));
|
|
chacha20.SetKey(key.data(), key.size());
|
|
},
|
|
[&] {
|
|
chacha20.SetIV(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
|
},
|
|
[&] {
|
|
chacha20.Seek(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
|
},
|
|
[&] {
|
|
std::vector<uint8_t> output(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
|
|
chacha20.Keystream(output.data(), output.size());
|
|
},
|
|
[&] {
|
|
std::vector<uint8_t> output(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
|
|
const std::vector<uint8_t> input = ConsumeFixedLengthByteVector(fuzzed_data_provider, output.size());
|
|
chacha20.Crypt(input.data(), output.data(), input.size());
|
|
});
|
|
}
|
|
}
|