43 chacha20.
Crypt(input, output);
58template<
bool UseCrypt>
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 :
111 crypt2.Crypt(std::span{data2}.subspan(bytes2, now), std::span{data2}.subspan(bytes2, now));
113 crypt2.Keystream(std::span{data2}.subspan(bytes2, now));
119 assert(bytes2 == total_bytes);
129 ChaCha20SplitFuzz<true>(provider);
135 ChaCha20SplitFuzz<false>(provider);
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.
void SetKey(std::span< const std::byte > key) noexcept
Set 32-byte key, and seek to nonce 0 and block position 0.
void Keystream(std::span< std::byte > out) noexcept
outputs the keystream to out.
void Crypt(std::span< const std::byte > in_bytes, std::span< std::byte > out_bytes) noexcept
en/deciphers the message <in_bytes> and write the result into <out_bytes>
void Seek(Nonce96 nonce, uint32_t block_counter) noexcept
Set the 96-bit nonce and 32-bit block counter.
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(std::span< std::byte > span) noexcept
Fill a span with random bytes.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
auto MakeWritableByteSpan(V &&v) noexcept
std::vector< B > 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...
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)