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) {
85 std::copy(data1.begin(), data1.end(), data2.begin());
92 if constexpr (UseCrypt) {
93 crypt1.Crypt(data1, data1);
95 crypt1.Keystream(data1);
102 bool is_last = (iter == 255) || (bytes2 == total_bytes) || provider.
ConsumeBool();
106 uint64_t now = is_last ? total_bytes - bytes2 :
114 crypt2.Keystream(
Span{data2}.
subspan(bytes2, now));
120 assert(bytes2 == total_bytes);
130 ChaCha20SplitFuzz<true>(provider);
136 ChaCha20SplitFuzz<false>(provider);
146 auto fsc20 =
FSChaCha20{key, fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(1, 1024)};
150 auto input = fuzzed_data_provider.ConsumeBytes<std::byte>(fuzzed_data_provider.ConsumeIntegralInRange(0, 4096));
151 std::vector<std::byte> output;
152 output.resize(input.size());
153 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)
void fillrand(Span< std::byte > span) noexcept
Fill a Span with random bytes.
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
FUZZ_TARGET(crypto_chacha20)
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Span< std::byte > MakeWritableByteSpan(V &&v) noexcept
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)