summaryrefslogtreecommitdiffstats
path: root/crypto/eseqiv.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-06-03 14:49:25 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2015-06-04 15:05:00 +0800
commit4ce43ceb71cb5d5cde9f9bd4e51d17b966c462f7 (patch)
treee1cd75434bde06edd207b743772060abdbf9025b /crypto/eseqiv.c
parentf261c5fbe7121fd88198f3ee4be4e34a5a268120 (diff)
downloadlinux-4ce43ceb71cb5d5cde9f9bd4e51d17b966c462f7.tar.gz
linux-4ce43ceb71cb5d5cde9f9bd4e51d17b966c462f7.tar.bz2
linux-4ce43ceb71cb5d5cde9f9bd4e51d17b966c462f7.zip
crypto: eseqiv - Move IV seeding into init function
We currently do the IV seeding on the first givencrypt call in order to conserve entropy. However, this does not work with DRBG which cannot be called from interrupt context. In fact, with DRBG we don't need to conserve entropy anyway. So this patch moves the seeding into the init function. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/eseqiv.c')
-rw-r--r--crypto/eseqiv.c29
1 files changed, 4 insertions, 25 deletions
diff --git a/crypto/eseqiv.c b/crypto/eseqiv.c
index f116fae766f8..78a72645390c 100644
--- a/crypto/eseqiv.c
+++ b/crypto/eseqiv.c
@@ -146,29 +146,6 @@ out:
return err;
}
-static int eseqiv_givencrypt_first(struct skcipher_givcrypt_request *req)
-{
- struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
- struct eseqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
- int err = 0;
-
- spin_lock_bh(&ctx->lock);
- if (crypto_ablkcipher_crt(geniv)->givencrypt != eseqiv_givencrypt_first)
- goto unlock;
-
- crypto_ablkcipher_crt(geniv)->givencrypt = eseqiv_givencrypt;
- err = crypto_rng_get_bytes(crypto_default_rng, ctx->salt,
- crypto_ablkcipher_ivsize(geniv));
-
-unlock:
- spin_unlock_bh(&ctx->lock);
-
- if (err)
- return err;
-
- return eseqiv_givencrypt(req);
-}
-
static int eseqiv_init(struct crypto_tfm *tfm)
{
struct crypto_ablkcipher *geniv = __crypto_ablkcipher_cast(tfm);
@@ -198,7 +175,9 @@ static int eseqiv_init(struct crypto_tfm *tfm)
tfm->crt_ablkcipher.reqsize = reqsize +
sizeof(struct ablkcipher_request);
- return skcipher_geniv_init(tfm);
+ return crypto_rng_get_bytes(crypto_default_rng, ctx->salt,
+ crypto_ablkcipher_ivsize(geniv)) ?:
+ skcipher_geniv_init(tfm);
}
static struct crypto_template eseqiv_tmpl;
@@ -220,7 +199,7 @@ static struct crypto_instance *eseqiv_alloc(struct rtattr **tb)
if (inst->alg.cra_ablkcipher.ivsize != inst->alg.cra_blocksize)
goto free_inst;
- inst->alg.cra_ablkcipher.givencrypt = eseqiv_givencrypt_first;
+ inst->alg.cra_ablkcipher.givencrypt = eseqiv_givencrypt;
inst->alg.cra_init = eseqiv_init;
inst->alg.cra_exit = skcipher_geniv_exit;