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