aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/echainiv.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-06-21 07:11:50 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-06-22 03:49:29 -0400
commit9fcc704dfd7967ebfbdd1031603e4332a905994b (patch)
treef489c83ce1269fa2fe13e8ceab7f447bb62e5ec5 /crypto/echainiv.c
parenteeee12aa34d840c6c99051f0ff85a9ffa1badd07 (diff)
crypto: echainiv - Only hold RNG during initialisation
This patch changes the RNG allocation so that we only hold a reference to the RNG during initialisation. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/echainiv.c')
-rw-r--r--crypto/echainiv.c28
1 files changed, 6 insertions, 22 deletions
diff --git a/crypto/echainiv.c b/crypto/echainiv.c
index 08d33367801d..b6e43dc61356 100644
--- a/crypto/echainiv.c
+++ b/crypto/echainiv.c
@@ -197,8 +197,13 @@ static int echainiv_init(struct crypto_tfm *tfm)
197 197
198 crypto_aead_set_reqsize(geniv, sizeof(struct aead_request)); 198 crypto_aead_set_reqsize(geniv, sizeof(struct aead_request));
199 199
200 err = crypto_get_default_rng();
201 if (err)
202 goto out;
203
200 err = crypto_rng_get_bytes(crypto_default_rng, ctx->salt, 204 err = crypto_rng_get_bytes(crypto_default_rng, ctx->salt,
201 crypto_aead_ivsize(geniv)); 205 crypto_aead_ivsize(geniv));
206 crypto_put_default_rng();
202 if (err) 207 if (err)
203 goto out; 208 goto out;
204 209
@@ -277,35 +282,14 @@ free_inst:
277 goto out; 282 goto out;
278} 283}
279 284
280static int echainiv_create(struct crypto_template *tmpl, struct rtattr **tb)
281{
282 int err;
283
284 err = crypto_get_default_rng();
285 if (err)
286 goto out;
287
288 err = echainiv_aead_create(tmpl, tb);
289 if (err)
290 goto put_rng;
291
292out:
293 return err;
294
295put_rng:
296 crypto_put_default_rng();
297 goto out;
298}
299
300static void echainiv_free(struct crypto_instance *inst) 285static void echainiv_free(struct crypto_instance *inst)
301{ 286{
302 aead_geniv_free(aead_instance(inst)); 287 aead_geniv_free(aead_instance(inst));
303 crypto_put_default_rng();
304} 288}
305 289
306static struct crypto_template echainiv_tmpl = { 290static struct crypto_template echainiv_tmpl = {
307 .name = "echainiv", 291 .name = "echainiv",
308 .create = echainiv_create, 292 .create = echainiv_aead_create,
309 .free = echainiv_free, 293 .free = echainiv_free,
310 .module = THIS_MODULE, 294 .module = THIS_MODULE,
311}; 295};