Lines Matching refs:ctx
86 static int _get_more_prng_bytes(struct prng_context *ctx, int cont_test) in _get_more_prng_bytes() argument
94 ctx); in _get_more_prng_bytes()
96 hexdump("Input DT: ", ctx->DT, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
97 hexdump("Input I: ", ctx->I, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
98 hexdump("Input V: ", ctx->V, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
111 memcpy(tmp, ctx->DT, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
112 output = ctx->I; in _get_more_prng_bytes()
122 xor_vectors(ctx->I, ctx->V, tmp, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
124 output = ctx->rand_data; in _get_more_prng_bytes()
131 if (!memcmp(ctx->rand_data, ctx->last_rand_data, in _get_more_prng_bytes()
135 ctx); in _get_more_prng_bytes()
140 ctx); in _get_more_prng_bytes()
142 ctx->flags |= PRNG_NEED_RESET; in _get_more_prng_bytes()
145 memcpy(ctx->last_rand_data, ctx->rand_data, in _get_more_prng_bytes()
152 xor_vectors(ctx->rand_data, ctx->I, tmp, in _get_more_prng_bytes()
154 output = ctx->V; in _get_more_prng_bytes()
161 crypto_cipher_encrypt_one(ctx->tfm, output, tmp); in _get_more_prng_bytes()
169 ctx->DT[i] += 1; in _get_more_prng_bytes()
170 if (ctx->DT[i] != 0) in _get_more_prng_bytes()
174 dbgprint("Returning new block for context %p\n", ctx); in _get_more_prng_bytes()
175 ctx->rand_data_valid = 0; in _get_more_prng_bytes()
177 hexdump("Output DT: ", ctx->DT, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
178 hexdump("Output I: ", ctx->I, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
179 hexdump("Output V: ", ctx->V, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
180 hexdump("New Random Data: ", ctx->rand_data, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
186 static int get_prng_bytes(char *buf, size_t nbytes, struct prng_context *ctx, in get_prng_bytes() argument
194 spin_lock_bh(&ctx->prng_lock); in get_prng_bytes()
197 if (ctx->flags & PRNG_NEED_RESET) in get_prng_bytes()
205 if (ctx->flags & PRNG_FIXED_SIZE) { in get_prng_bytes()
218 byte_count, ctx); in get_prng_bytes()
222 if (ctx->rand_data_valid == DEFAULT_BLK_SZ) { in get_prng_bytes()
223 if (_get_more_prng_bytes(ctx, do_cont_test) < 0) { in get_prng_bytes()
235 while (ctx->rand_data_valid < DEFAULT_BLK_SZ) { in get_prng_bytes()
236 *ptr = ctx->rand_data[ctx->rand_data_valid]; in get_prng_bytes()
239 ctx->rand_data_valid++; in get_prng_bytes()
249 if (ctx->rand_data_valid == DEFAULT_BLK_SZ) { in get_prng_bytes()
250 if (_get_more_prng_bytes(ctx, do_cont_test) < 0) { in get_prng_bytes()
256 if (ctx->rand_data_valid > 0) in get_prng_bytes()
258 memcpy(ptr, ctx->rand_data, DEFAULT_BLK_SZ); in get_prng_bytes()
259 ctx->rand_data_valid += DEFAULT_BLK_SZ; in get_prng_bytes()
270 spin_unlock_bh(&ctx->prng_lock); in get_prng_bytes()
272 err, ctx); in get_prng_bytes()
276 static void free_prng_context(struct prng_context *ctx) in free_prng_context() argument
278 crypto_free_cipher(ctx->tfm); in free_prng_context()
281 static int reset_prng_context(struct prng_context *ctx, in reset_prng_context() argument
288 spin_lock_bh(&ctx->prng_lock); in reset_prng_context()
289 ctx->flags |= PRNG_NEED_RESET; in reset_prng_context()
297 memcpy(ctx->V, V, DEFAULT_BLK_SZ); in reset_prng_context()
299 memcpy(ctx->V, DEFAULT_V_SEED, DEFAULT_BLK_SZ); in reset_prng_context()
302 memcpy(ctx->DT, DT, DEFAULT_BLK_SZ); in reset_prng_context()
304 memset(ctx->DT, 0, DEFAULT_BLK_SZ); in reset_prng_context()
306 memset(ctx->rand_data, 0, DEFAULT_BLK_SZ); in reset_prng_context()
307 memset(ctx->last_rand_data, 0, DEFAULT_BLK_SZ); in reset_prng_context()
309 ctx->rand_data_valid = DEFAULT_BLK_SZ; in reset_prng_context()
311 ret = crypto_cipher_setkey(ctx->tfm, prng_key, klen); in reset_prng_context()
314 crypto_cipher_get_flags(ctx->tfm)); in reset_prng_context()
319 ctx->flags &= ~PRNG_NEED_RESET; in reset_prng_context()
321 spin_unlock_bh(&ctx->prng_lock); in reset_prng_context()
327 struct prng_context *ctx = crypto_tfm_ctx(tfm); in cprng_init() local
329 spin_lock_init(&ctx->prng_lock); in cprng_init()
330 ctx->tfm = crypto_alloc_cipher("aes", 0, 0); in cprng_init()
331 if (IS_ERR(ctx->tfm)) { in cprng_init()
333 ctx); in cprng_init()
334 return PTR_ERR(ctx->tfm); in cprng_init()
337 if (reset_prng_context(ctx, NULL, DEFAULT_PRNG_KSZ, NULL, NULL) < 0) in cprng_init()
345 ctx->flags |= PRNG_NEED_RESET; in cprng_init()