Lines Matching refs:state

62 static int csprng_reseed(struct csprng_state *state);
80 csprng_init(struct csprng_state *state) in csprng_init() argument
84 bzero(state->key, sizeof(state->key)); in csprng_init()
85 bzero(&state->cipher_ctx, sizeof(state->cipher_ctx)); in csprng_init()
86 bzero(state->src_pool_idx, sizeof(state->src_pool_idx)); in csprng_init()
87 bzero(&state->last_reseed, sizeof(state->last_reseed)); in csprng_init()
89 state->reseed_cnt = 0; in csprng_init()
90 state->failed_reseeds = 0; in csprng_init()
91 state->callout_based_reseed = 0; in csprng_init()
94 r = csprng_pool_init(&state->pool[i], NULL, 0); in csprng_init()
104 csprng_init_reseed(struct csprng_state *state)
106 state->callout_based_reseed = 1;
108 callout_init_mp(&state->reseed_callout);
109 callout_reset(&state->reseed_callout, MIN_RESEED_INTERVAL,
110 csprng_reseed_callout, state);
127 csprng_get_random(struct csprng_state *state, uint8_t *out, int bytes, in csprng_get_random() argument
134 if (!state->callout_based_reseed && in csprng_get_random()
135 ratecheck(&state->last_reseed, &csprng_reseed_interval)) { in csprng_get_random()
136 csprng_reseed(state); in csprng_get_random()
146 if ((flags & CSPRNG_UNLIMITED) == 0 && state->reseed_cnt == 0) { in csprng_get_random()
147 ssleep(state, &state->spin, 0, "csprngrsd", 0); in csprng_get_random()
155 chacha_encrypt_bytes(&state->cipher_ctx, NULL, out, cnt); in csprng_get_random()
158 chacha_encrypt_bytes(&state->cipher_ctx, NULL, state->key, in csprng_get_random()
159 sizeof(state->key)); in csprng_get_random()
160 chacha_keysetup(&state->cipher_ctx, state->key, in csprng_get_random()
161 8 * sizeof(state->key)); in csprng_get_random()
176 csprng_reseed(struct csprng_state *state) in csprng_reseed() argument
188 if (state->pool[0].bytes < MIN_POOL_SIZE) { in csprng_reseed()
189 ++state->failed_reseeds; in csprng_reseed()
199 SHA256_Update(&hash_ctx, state->key, sizeof(state->key)); in csprng_reseed()
201 state->reseed_cnt++; in csprng_reseed()
204 if ((state->reseed_cnt % (1 << i)) != 0) in csprng_reseed()
207 pool = &state->pool[i]; in csprng_reseed()
228 SHA256_Final(state->key, &hash_ctx); in csprng_reseed()
231 chacha_keysetup(&state->cipher_ctx, state->key, 8*sizeof(state->key)); in csprng_reseed()
235 chacha_ivsetup(&state->cipher_ctx, NULL, counter); in csprng_reseed()
245 struct csprng_state *state = (struct csprng_state *)arg;
248 spin_lock(&state->spin);
250 spin_unlock(&state->spin);
251 wakeup(state);
253 callout_reset(&state->reseed_callout, reseed_interval,
254 csprng_reseed_callout, state);
262 csprng_add_entropy(struct csprng_state *state, int src_id, in csprng_add_entropy() argument
273 pool_id = state->src_pool_idx[src_id]++ & 0x1f; in csprng_add_entropy()
274 pool = &state->pool[pool_id]; in csprng_add_entropy()