20 const auto key = ConsumeFixedLengthByteVector<std::byte>(fuzzed_data_provider,
ChaCha20::KEYLEN);
27 auto key = ConsumeFixedLengthByteVector<std::byte>(fuzzed_data_provider,
ChaCha20::KEYLEN);
33 fuzzed_data_provider.ConsumeIntegral<uint32_t>(),
34 fuzzed_data_provider.ConsumeIntegral<uint64_t>()
35 }, fuzzed_data_provider.ConsumeIntegral<uint32_t>());
38 std::vector<uint8_t> output(fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(0, 4096));
42 std::vector<std::byte> output(fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(0, 4096));
43 const auto input = ConsumeFixedLengthByteVector<std::byte>(fuzzed_data_provider, output.size());
44 chacha20.Crypt(input, output);
59 template<
bool UseCrypt>
63 auto key_bytes = ConsumeFixedLengthByteVector<std::byte>(provider,
ChaCha20::KEYLEN);
73 crypt1.Seek({iv_prefix, iv}, seek);
74 crypt2.Seek({iv_prefix, iv}, seek);
77 std::vector<std::byte> data1, data2;
78 data1.resize(total_bytes);
79 data2.resize(total_bytes);
83 if constexpr (UseCrypt) {
87 while (bytes < (total_bytes & ~uint64_t{7})) {
93 if (bytes < total_bytes) {
94 std::byte valbytes[8];
97 std::copy(valbytes, valbytes + (total_bytes - bytes), data1.data() + bytes);
98 std::copy(valbytes, valbytes + (total_bytes - bytes), data2.data() + bytes);
106 if constexpr (UseCrypt) {
107 crypt1.Crypt(data1, data1);
109 crypt1.Keystream(data1);
116 bool is_last = (iter == 255) || (bytes2 == total_bytes) || provider.
ConsumeBool();
120 uint64_t now = is_last ? total_bytes - bytes2 :
128 crypt2.Keystream(
Span{data2}.
subspan(bytes2, now));
134 assert(bytes2 == total_bytes);
144 ChaCha20SplitFuzz<true>(provider);
150 ChaCha20SplitFuzz<false>(provider);
160 auto fsc20 =
FSChaCha20{key, fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(1, 1024)};
164 auto input = fuzzed_data_provider.ConsumeBytes<std::byte>(fuzzed_data_provider.ConsumeIntegralInRange(0, 4096));
165 std::vector<std::byte> output;
166 output.resize(input.size());
167 fsc20.Crypt(input, output);
Unrestricted ChaCha20 cipher.
static constexpr unsigned KEYLEN
Expected key length in constructor and SetKey.
static constexpr unsigned KEYLEN
Length of keys expected by the constructor.
std::vector< T > ConsumeBytes(size_t num_bytes)
T ConsumeIntegralInRange(T min, T max)
A Span is an object that can refer to a contiguous sequence of objects.
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset) const noexcept
static void WriteLE64(unsigned char *ptr, uint64_t x)
FUZZ_TARGET(crypto_chacha20)
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
unsigned char * UCharCast(char *c)
Span< std::byte > MakeWritableByteSpan(V &&v) noexcept
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)