Lines Matching refs:ctx

88 static int _get_more_prng_bytes(struct prng_context *ctx, int cont_test)  in _get_more_prng_bytes()  argument
96 ctx); in _get_more_prng_bytes()
98 hexdump("Input DT: ", ctx->DT, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
99 hexdump("Input I: ", ctx->I, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
100 hexdump("Input V: ", ctx->V, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
113 memcpy(tmp, ctx->DT, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
114 output = ctx->I; in _get_more_prng_bytes()
124 xor_vectors(ctx->I, ctx->V, tmp, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
126 output = ctx->rand_data; in _get_more_prng_bytes()
133 if (!memcmp(ctx->rand_data, ctx->last_rand_data, in _get_more_prng_bytes()
137 ctx); in _get_more_prng_bytes()
142 ctx); in _get_more_prng_bytes()
144 ctx->flags |= PRNG_NEED_RESET; in _get_more_prng_bytes()
147 memcpy(ctx->last_rand_data, ctx->rand_data, in _get_more_prng_bytes()
154 xor_vectors(ctx->rand_data, ctx->I, tmp, in _get_more_prng_bytes()
156 output = ctx->V; in _get_more_prng_bytes()
163 crypto_cipher_encrypt_one(ctx->tfm, output, tmp); in _get_more_prng_bytes()
171 ctx->DT[i] += 1; in _get_more_prng_bytes()
172 if (ctx->DT[i] != 0) in _get_more_prng_bytes()
176 dbgprint("Returning new block for context %p\n", ctx); in _get_more_prng_bytes()
177 ctx->rand_data_valid = 0; in _get_more_prng_bytes()
179 hexdump("Output DT: ", ctx->DT, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
180 hexdump("Output I: ", ctx->I, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
181 hexdump("Output V: ", ctx->V, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
182 hexdump("New Random Data: ", ctx->rand_data, DEFAULT_BLK_SZ); in _get_more_prng_bytes()
188 static int get_prng_bytes(char *buf, size_t nbytes, struct prng_context *ctx, in get_prng_bytes() argument
196 spin_lock_bh(&ctx->prng_lock); in get_prng_bytes()
199 if (ctx->flags & PRNG_NEED_RESET) in get_prng_bytes()
207 if (ctx->flags & PRNG_FIXED_SIZE) { in get_prng_bytes()
220 byte_count, ctx); in get_prng_bytes()
224 if (ctx->rand_data_valid == DEFAULT_BLK_SZ) { in get_prng_bytes()
225 if (_get_more_prng_bytes(ctx, do_cont_test) < 0) { in get_prng_bytes()
237 while (ctx->rand_data_valid < DEFAULT_BLK_SZ) { in get_prng_bytes()
238 *ptr = ctx->rand_data[ctx->rand_data_valid]; in get_prng_bytes()
241 ctx->rand_data_valid++; in get_prng_bytes()
251 if (ctx->rand_data_valid == DEFAULT_BLK_SZ) { in get_prng_bytes()
252 if (_get_more_prng_bytes(ctx, do_cont_test) < 0) { in get_prng_bytes()
258 if (ctx->rand_data_valid > 0) in get_prng_bytes()
260 memcpy(ptr, ctx->rand_data, DEFAULT_BLK_SZ); in get_prng_bytes()
261 ctx->rand_data_valid += DEFAULT_BLK_SZ; in get_prng_bytes()
272 spin_unlock_bh(&ctx->prng_lock); in get_prng_bytes()
274 err, ctx); in get_prng_bytes()
278 static void free_prng_context(struct prng_context *ctx) in free_prng_context() argument
280 crypto_free_cipher(ctx->tfm); in free_prng_context()
283 static int reset_prng_context(struct prng_context *ctx, in reset_prng_context() argument
290 spin_lock_bh(&ctx->prng_lock); in reset_prng_context()
291 ctx->flags |= PRNG_NEED_RESET; in reset_prng_context()
299 memcpy(ctx->V, V, DEFAULT_BLK_SZ); in reset_prng_context()
301 memcpy(ctx->V, DEFAULT_V_SEED, DEFAULT_BLK_SZ); in reset_prng_context()
304 memcpy(ctx->DT, DT, DEFAULT_BLK_SZ); in reset_prng_context()
306 memset(ctx->DT, 0, DEFAULT_BLK_SZ); in reset_prng_context()
308 memset(ctx->rand_data, 0, DEFAULT_BLK_SZ); in reset_prng_context()
309 memset(ctx->last_rand_data, 0, DEFAULT_BLK_SZ); in reset_prng_context()
311 ctx->rand_data_valid = DEFAULT_BLK_SZ; in reset_prng_context()
313 ret = crypto_cipher_setkey(ctx->tfm, prng_key, klen); in reset_prng_context()
316 crypto_cipher_get_flags(ctx->tfm)); in reset_prng_context()
321 ctx->flags &= ~PRNG_NEED_RESET; in reset_prng_context()
323 spin_unlock_bh(&ctx->prng_lock); in reset_prng_context()
329 struct prng_context *ctx = crypto_tfm_ctx(tfm); in cprng_init() local
331 spin_lock_init(&ctx->prng_lock); in cprng_init()
332 ctx->tfm = crypto_alloc_cipher("aes", 0, 0); in cprng_init()
333 if (IS_ERR(ctx->tfm)) { in cprng_init()
335 ctx); in cprng_init()
336 return PTR_ERR(ctx->tfm); in cprng_init()
339 if (reset_prng_context(ctx, NULL, DEFAULT_PRNG_KSZ, NULL, NULL) < 0) in cprng_init()
347 ctx->flags |= PRNG_NEED_RESET; in cprng_init()