aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/ansi_cprng.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/ansi_cprng.c')
-rw-r--r--crypto/ansi_cprng.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
index ff00b58c2cdc..5357ba7d821a 100644
--- a/crypto/ansi_cprng.c
+++ b/crypto/ansi_cprng.c
@@ -283,7 +283,6 @@ static int reset_prng_context(struct prng_context *ctx,
283 unsigned char *V, unsigned char *DT) 283 unsigned char *V, unsigned char *DT)
284{ 284{
285 int ret; 285 int ret;
286 int rc = -EINVAL;
287 unsigned char *prng_key; 286 unsigned char *prng_key;
288 287
289 spin_lock_bh(&ctx->prng_lock); 288 spin_lock_bh(&ctx->prng_lock);
@@ -307,34 +306,20 @@ static int reset_prng_context(struct prng_context *ctx,
307 memset(ctx->rand_data, 0, DEFAULT_BLK_SZ); 306 memset(ctx->rand_data, 0, DEFAULT_BLK_SZ);
308 memset(ctx->last_rand_data, 0, DEFAULT_BLK_SZ); 307 memset(ctx->last_rand_data, 0, DEFAULT_BLK_SZ);
309 308
310 if (ctx->tfm)
311 crypto_free_cipher(ctx->tfm);
312
313 ctx->tfm = crypto_alloc_cipher("aes", 0, 0);
314 if (IS_ERR(ctx->tfm)) {
315 dbgprint(KERN_CRIT "Failed to alloc tfm for context %p\n",
316 ctx);
317 ctx->tfm = NULL;
318 goto out;
319 }
320
321 ctx->rand_data_valid = DEFAULT_BLK_SZ; 309 ctx->rand_data_valid = DEFAULT_BLK_SZ;
322 310
323 ret = crypto_cipher_setkey(ctx->tfm, prng_key, klen); 311 ret = crypto_cipher_setkey(ctx->tfm, prng_key, klen);
324 if (ret) { 312 if (ret) {
325 dbgprint(KERN_CRIT "PRNG: setkey() failed flags=%x\n", 313 dbgprint(KERN_CRIT "PRNG: setkey() failed flags=%x\n",
326 crypto_cipher_get_flags(ctx->tfm)); 314 crypto_cipher_get_flags(ctx->tfm));
327 crypto_free_cipher(ctx->tfm);
328 goto out; 315 goto out;
329 } 316 }
330 317
331 rc = 0; 318 ret = 0;
332 ctx->flags &= ~PRNG_NEED_RESET; 319 ctx->flags &= ~PRNG_NEED_RESET;
333out: 320out:
334 spin_unlock_bh(&ctx->prng_lock); 321 spin_unlock_bh(&ctx->prng_lock);
335 322 return ret;
336 return rc;
337
338} 323}
339 324
340static int cprng_init(struct crypto_tfm *tfm) 325static int cprng_init(struct crypto_tfm *tfm)
@@ -342,6 +327,12 @@ static int cprng_init(struct crypto_tfm *tfm)
342 struct prng_context *ctx = crypto_tfm_ctx(tfm); 327 struct prng_context *ctx = crypto_tfm_ctx(tfm);
343 328
344 spin_lock_init(&ctx->prng_lock); 329 spin_lock_init(&ctx->prng_lock);
330 ctx->tfm = crypto_alloc_cipher("aes", 0, 0);
331 if (IS_ERR(ctx->tfm)) {
332 dbgprint(KERN_CRIT "Failed to alloc tfm for context %p\n",
333 ctx);
334 return PTR_ERR(ctx->tfm);
335 }
345 336
346 if (reset_prng_context(ctx, NULL, DEFAULT_PRNG_KSZ, NULL, NULL) < 0) 337 if (reset_prng_context(ctx, NULL, DEFAULT_PRNG_KSZ, NULL, NULL) < 0)
347 return -EINVAL; 338 return -EINVAL;