X-Git-Url: http://ftp.safe.ca/?p=safe%2Fjmp%2Flinux-2.6;a=blobdiff_plain;f=crypto%2Feseqiv.c;h=3ca3b669d5d501ed491a1c70dc2694b30e9cb0e0;hp=eb90d27ae118e0b79bc2d24daf94b476a4f89075;hb=4434ade8c9334a3ab975d8993de456f06841899e;hpb=806d183aa6cc565d0f6bd2fb7fc6bfb175cc4813 diff --git a/crypto/eseqiv.c b/crypto/eseqiv.c index eb90d27..3ca3b66 100644 --- a/crypto/eseqiv.c +++ b/crypto/eseqiv.c @@ -16,13 +16,13 @@ */ #include +#include #include #include #include #include #include #include -#include #include #include #include @@ -136,7 +136,8 @@ static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req) } ablkcipher_request_set_crypt(subreq, reqctx->src, dst, - req->creq.nbytes, req->creq.info); + req->creq.nbytes + ivsize, + req->creq.info); memcpy(req->creq.info, ctx->salt, ivsize); @@ -152,7 +153,8 @@ static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req) if (err) goto out; - eseqiv_complete2(req); + if (giv != req->giv) + eseqiv_complete2(req); out: return err; @@ -162,17 +164,22 @@ 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; - get_random_bytes(ctx->salt, crypto_ablkcipher_ivsize(geniv)); + 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); } @@ -215,9 +222,13 @@ static struct crypto_instance *eseqiv_alloc(struct rtattr **tb) struct crypto_instance *inst; int err; + err = crypto_get_default_rng(); + if (err) + return ERR_PTR(err); + inst = skcipher_geniv_alloc(&eseqiv_tmpl, tb, 0, 0); if (IS_ERR(inst)) - goto out; + goto put_rng; err = -EINVAL; if (inst->alg.cra_ablkcipher.ivsize != inst->alg.cra_blocksize) @@ -237,13 +248,21 @@ out: free_inst: skcipher_geniv_free(inst); inst = ERR_PTR(err); +put_rng: + crypto_put_default_rng(); goto out; } +static void eseqiv_free(struct crypto_instance *inst) +{ + skcipher_geniv_free(inst); + crypto_put_default_rng(); +} + static struct crypto_template eseqiv_tmpl = { .name = "eseqiv", .alloc = eseqiv_alloc, - .free = skcipher_geniv_free, + .free = eseqiv_free, .module = THIS_MODULE, };