9 #include <sodium/crypto_stream_chacha20.h>
21 : data_used(sizeof(block))
25 seed_size = std::min(seed_size,
sizeof(key));
26 memcpy(key, seed, seed_size);
27 if (seed_size <
sizeof(key)) {
28 memset(((uint8_t *)key) + seed_size, 0,
sizeof(key) - seed_size);
32 memset(counter, 0,
sizeof(counter));
41 uint8_t *target = (uint8_t *)output;
42 while (output_size > 0) {
43 if (data_used ==
sizeof(block)) {
47 const size_t data_remaining =
sizeof(block) - data_used;
48 const size_t to_write = std::min(data_remaining, output_size);
50 memcpy(target, &block[data_used], to_write);
51 data_used += to_write;
53 output_size -= to_write;
57 void chacha_rng::update()
75 memset(block, 0,
sizeof(block));
76 crypto_stream_chacha20_ietf_xor_ic(
80 (
const uint8_t *)&counter[1],
82 (
const uint8_t *)&key[0]);
88 if (++counter[0] != 0) {
91 if (++counter[1] != 0) {
94 if (++counter[2] != 0) {