20 const auto key = ConsumeFixedLengthByteVector<std::byte>(fuzzed_data_provider,
ChaCha20::KEYLEN);
27 auto key = ConsumeFixedLengthByteVector<std::byte>(fuzzed_data_provider,
ChaCha20::KEYLEN);
32 fuzzed_data_provider.ConsumeIntegral<uint32_t>(),
33 fuzzed_data_provider.ConsumeIntegral<uint64_t>()};
34 chacha20.Seek(
nonce, fuzzed_data_provider.ConsumeIntegral<uint32_t>());
37 std::vector<uint8_t> output(fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(0, 4096));
41 std::vector<std::byte> output(fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(0, 4096));
42 const auto input = ConsumeFixedLengthByteVector<std::byte>(fuzzed_data_provider, output.size());
43 chacha20.Crypt(input, output);
58template<
bool UseCrypt>
62 auto key_bytes = ConsumeFixedLengthByteVector<std::byte>(provider,
ChaCha20::KEYLEN);
72 crypt1.Seek({iv_prefix, iv}, seek);
73 crypt2.Seek({iv_prefix, iv}, seek);
76 std::vector<std::byte> data1, data2;
77 data1.resize(total_bytes);
78 data2.resize(total_bytes);
82 if constexpr (UseCrypt) {
84 std::copy(data1.begin(), data1.end(), data2.begin());
91 if constexpr (UseCrypt) {
92 crypt1.Crypt(data1, data1);
94 crypt1.Keystream(data1);
101 bool is_last = (iter == 255) || (bytes2 == total_bytes) || provider.
ConsumeBool();
105 uint64_t now = is_last ? total_bytes - bytes2 :
113 crypt2.Keystream(
Span{data2}.
subspan(bytes2, now));
119 assert(bytes2 == total_bytes);
129 ChaCha20SplitFuzz<true>(provider);
135 ChaCha20SplitFuzz<false>(provider);
145 auto fsc20 =
FSChaCha20{key, fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(1, 1024)};
149 auto input = fuzzed_data_provider.ConsumeBytes<std::byte>(fuzzed_data_provider.ConsumeIntegralInRange(0, 4096));
150 std::vector<std::byte> output;
151 output.resize(input.size());
152 fsc20.Crypt(input, output);
Unrestricted ChaCha20 cipher.
static constexpr unsigned KEYLEN
Expected key length in constructor and SetKey.
ChaCha20Aligned::Nonce96 Nonce96
96-bit nonce type.
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)