4 #include <crypto/sha2/sha2.h>
5 #include <crypto/chacha/chacha.h>
7 #include <sys/callout.h>
8 #include <sys/spinlock.h>
12 /* Flags for various calls */
13 #define CSPRNG_TRYLOCK 0x0001
14 #define CSPRNG_UNLIMITED 0x0002
21 CTASSERT(SHA256_DIGEST_LENGTH == 32);
24 uint8_t key[SHA256_DIGEST_LENGTH];
25 uint64_t nonce; /* Effectively high 64-bits of ctr */
28 uint64_t reseed_cnt; /* Times we have reseeded */
30 chacha_ctx cipher_ctx; /* (Stream) cipher context */
32 /* Pools and the per-source round robin pool index */
33 struct csprng_pool pool[32];
34 uint8_t src_pool_idx[256];
37 struct callout reseed_callout;
38 uint32_t failed_reseeds;
39 int callout_based_reseed;
40 uint8_t inject_counter[256];
43 struct timeval last_reseed;
44 struct ibaa_state ibaa;
48 int csprng_init(struct csprng_state *state);
49 int csprng_get_random(struct csprng_state *state, uint8_t *out, int bytes,
50 int flags, int unlimited);
51 int csprng_add_entropy(struct csprng_state *state, int src_id,
52 const uint8_t *entropy, size_t bytes, int flags);