Lines Matching refs:ctx

81 static int _get_more_prng_bytes(struct prng_context *ctx, int cont_test)
89 ctx);
91 hexdump("Input DT: ", ctx->DT, DEFAULT_BLK_SZ);
92 hexdump("Input I: ", ctx->I, DEFAULT_BLK_SZ);
93 hexdump("Input V: ", ctx->V, DEFAULT_BLK_SZ);
106 memcpy(tmp, ctx->DT, DEFAULT_BLK_SZ);
107 output = ctx->I;
117 xor_vectors(ctx->I, ctx->V, tmp, DEFAULT_BLK_SZ);
119 output = ctx->rand_data;
126 if (!memcmp(ctx->rand_data, ctx->last_rand_data,
130 ctx);
134 "ctx %p Failed repetition check!\n",
135 ctx);
137 ctx->flags |= PRNG_NEED_RESET;
140 memcpy(ctx->last_rand_data, ctx->rand_data,
147 xor_vectors(ctx->rand_data, ctx->I, tmp,
149 output = ctx->V;
156 crypto_cipher_encrypt_one(ctx->tfm, output, tmp);
164 ctx->DT[i] += 1;
165 if (ctx->DT[i] != 0)
169 dbgprint("Returning new block for context %p\n", ctx);
170 ctx->rand_data_valid = 0;
172 hexdump("Output DT: ", ctx->DT, DEFAULT_BLK_SZ);
173 hexdump("Output I: ", ctx->I, DEFAULT_BLK_SZ);
174 hexdump("Output V: ", ctx->V, DEFAULT_BLK_SZ);
175 hexdump("New Random Data: ", ctx->rand_data, DEFAULT_BLK_SZ);
181 static int get_prng_bytes(char *buf, size_t nbytes, struct prng_context *ctx,
189 spin_lock_bh(&ctx->prng_lock);
192 if (ctx->flags & PRNG_NEED_RESET)
200 if (ctx->flags & PRNG_FIXED_SIZE) {
213 byte_count, ctx);
217 if (ctx->rand_data_valid == DEFAULT_BLK_SZ) {
218 if (_get_more_prng_bytes(ctx, do_cont_test) < 0) {
230 while (ctx->rand_data_valid < DEFAULT_BLK_SZ) {
231 *ptr = ctx->rand_data[ctx->rand_data_valid];
234 ctx->rand_data_valid++;
244 if (ctx->rand_data_valid == DEFAULT_BLK_SZ) {
245 if (_get_more_prng_bytes(ctx, do_cont_test) < 0) {
251 if (ctx->rand_data_valid > 0)
253 memcpy(ptr, ctx->rand_data, DEFAULT_BLK_SZ);
254 ctx->rand_data_valid += DEFAULT_BLK_SZ;
265 spin_unlock_bh(&ctx->prng_lock);
267 err, ctx);
271 static void free_prng_context(struct prng_context *ctx)
273 crypto_free_cipher(ctx->tfm);
276 static int reset_prng_context(struct prng_context *ctx,
283 spin_lock_bh(&ctx->prng_lock);
284 ctx->flags |= PRNG_NEED_RESET;
292 memcpy(ctx->V, V, DEFAULT_BLK_SZ);
294 memcpy(ctx->V, DEFAULT_V_SEED, DEFAULT_BLK_SZ);
297 memcpy(ctx->DT, DT, DEFAULT_BLK_SZ);
299 memset(ctx->DT, 0, DEFAULT_BLK_SZ);
301 memset(ctx->rand_data, 0, DEFAULT_BLK_SZ);
302 memset(ctx->last_rand_data, 0, DEFAULT_BLK_SZ);
304 ctx->rand_data_valid = DEFAULT_BLK_SZ;
306 ret = crypto_cipher_setkey(ctx->tfm, prng_key, klen);
309 crypto_cipher_get_flags(ctx->tfm));
314 ctx->flags &= ~PRNG_NEED_RESET;
316 spin_unlock_bh(&ctx->prng_lock);
322 struct prng_context *ctx = crypto_tfm_ctx(tfm);
324 spin_lock_init(&ctx->prng_lock);
325 ctx->tfm = crypto_alloc_cipher("aes", 0, 0);
326 if (IS_ERR(ctx->tfm)) {
328 ctx);
329 return PTR_ERR(ctx->tfm);
332 if (reset_prng_context(ctx, NULL, DEFAULT_PRNG_KSZ, NULL, NULL) < 0)
340 ctx->flags |= PRNG_NEED_RESET;