aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/eseqiv.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2008-08-14 08:21:31 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2008-08-29 01:50:06 -0400
commita0f000ec9b61b99111757df138b11144236fc59b (patch)
treebd698163c48b5cd6d6a3c05c8d34d862ebcd86ed /crypto/eseqiv.c
parent17f0f4a47df9aea9ee26c939f8057c35e0be1847 (diff)
crypto: skcipher - Use RNG interface instead of get_random_bytes
This patch makes the IV generators use the new RNG interface so that the user can pick an RNG other than the default get_random_bytes. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/eseqiv.c')
-rw-r--r--crypto/eseqiv.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/crypto/eseqiv.c b/crypto/eseqiv.c
index f5def217a8f1..2a342c8e52b3 100644
--- a/crypto/eseqiv.c
+++ b/crypto/eseqiv.c
@@ -16,13 +16,13 @@
16 */ 16 */
17 17
18#include <crypto/internal/skcipher.h> 18#include <crypto/internal/skcipher.h>
19#include <crypto/rng.h>
19#include <crypto/scatterwalk.h> 20#include <crypto/scatterwalk.h>
20#include <linux/err.h> 21#include <linux/err.h>
21#include <linux/init.h> 22#include <linux/init.h>
22#include <linux/kernel.h> 23#include <linux/kernel.h>
23#include <linux/mm.h> 24#include <linux/mm.h>
24#include <linux/module.h> 25#include <linux/module.h>
25#include <linux/random.h>
26#include <linux/scatterlist.h> 26#include <linux/scatterlist.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/string.h> 28#include <linux/string.h>
@@ -163,17 +163,22 @@ static int eseqiv_givencrypt_first(struct skcipher_givcrypt_request *req)
163{ 163{
164 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req); 164 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
165 struct eseqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv); 165 struct eseqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
166 int err = 0;
166 167
167 spin_lock_bh(&ctx->lock); 168 spin_lock_bh(&ctx->lock);
168 if (crypto_ablkcipher_crt(geniv)->givencrypt != eseqiv_givencrypt_first) 169 if (crypto_ablkcipher_crt(geniv)->givencrypt != eseqiv_givencrypt_first)
169 goto unlock; 170 goto unlock;
170 171
171 crypto_ablkcipher_crt(geniv)->givencrypt = eseqiv_givencrypt; 172 crypto_ablkcipher_crt(geniv)->givencrypt = eseqiv_givencrypt;
172 get_random_bytes(ctx->salt, crypto_ablkcipher_ivsize(geniv)); 173 err = crypto_rng_get_bytes(crypto_default_rng, ctx->salt,
174 crypto_ablkcipher_ivsize(geniv));
173 175
174unlock: 176unlock:
175 spin_unlock_bh(&ctx->lock); 177 spin_unlock_bh(&ctx->lock);
176 178
179 if (err)
180 return err;
181
177 return eseqiv_givencrypt(req); 182 return eseqiv_givencrypt(req);
178} 183}
179 184
@@ -216,9 +221,13 @@ static struct crypto_instance *eseqiv_alloc(struct rtattr **tb)
216 struct crypto_instance *inst; 221 struct crypto_instance *inst;
217 int err; 222 int err;
218 223
224 err = crypto_get_default_rng();
225 if (err)
226 return ERR_PTR(err);
227
219 inst = skcipher_geniv_alloc(&eseqiv_tmpl, tb, 0, 0); 228 inst = skcipher_geniv_alloc(&eseqiv_tmpl, tb, 0, 0);
220 if (IS_ERR(inst)) 229 if (IS_ERR(inst))
221 goto out; 230 goto put_rng;
222 231
223 err = -EINVAL; 232 err = -EINVAL;
224 if (inst->alg.cra_ablkcipher.ivsize != inst->alg.cra_blocksize) 233 if (inst->alg.cra_ablkcipher.ivsize != inst->alg.cra_blocksize)
@@ -238,13 +247,21 @@ out:
238free_inst: 247free_inst:
239 skcipher_geniv_free(inst); 248 skcipher_geniv_free(inst);
240 inst = ERR_PTR(err); 249 inst = ERR_PTR(err);
250put_rng:
251 crypto_put_default_rng();
241 goto out; 252 goto out;
242} 253}
243 254
255static void eseqiv_free(struct crypto_instance *inst)
256{
257 skcipher_geniv_free(inst);
258 crypto_put_default_rng();
259}
260
244static struct crypto_template eseqiv_tmpl = { 261static struct crypto_template eseqiv_tmpl = {
245 .name = "eseqiv", 262 .name = "eseqiv",
246 .alloc = eseqiv_alloc, 263 .alloc = eseqiv_alloc,
247 .free = skcipher_geniv_free, 264 .free = eseqiv_free,
248 .module = THIS_MODULE, 265 .module = THIS_MODULE,
249}; 266};
250 267