X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=crypto%2Fchainiv.c;h=ba200b07449d259cebf846a43e3f768e335606ef;hb=c3935e30495869dd611e1cd62253c94ebc7c6c04;hp=9affadee32879c5114afab56d4bc82428c01dcf6;hpb=872ac8743cb400192a9fce4ba2d3ffd7bb309685;p=safe%2Fjmp%2Flinux-2.6 diff --git a/crypto/chainiv.c b/crypto/chainiv.c index 9affade..ba200b0 100644 --- a/crypto/chainiv.c +++ b/crypto/chainiv.c @@ -14,11 +14,12 @@ */ #include +#include +#include #include #include #include #include -#include #include #include #include @@ -83,6 +84,7 @@ static int chainiv_givencrypt_first(struct skcipher_givcrypt_request *req) { struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req); struct chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv); + int err = 0; spin_lock_bh(&ctx->lock); if (crypto_ablkcipher_crt(geniv)->givencrypt != @@ -90,11 +92,15 @@ static int chainiv_givencrypt_first(struct skcipher_givcrypt_request *req) goto unlock; crypto_ablkcipher_crt(geniv)->givencrypt = chainiv_givencrypt; - get_random_bytes(ctx->iv, crypto_ablkcipher_ivsize(geniv)); + err = crypto_rng_get_bytes(crypto_default_rng, ctx->iv, + crypto_ablkcipher_ivsize(geniv)); unlock: spin_unlock_bh(&ctx->lock); + if (err) + return err; + return chainiv_givencrypt(req); } @@ -128,7 +134,7 @@ static int async_chainiv_schedule_work(struct async_chainiv_ctx *ctx) goto out; } - queued = schedule_work(&ctx->postponed); + queued = queue_work(kcrypto_wq, &ctx->postponed); BUG_ON(!queued); out: @@ -203,6 +209,7 @@ static int async_chainiv_givencrypt_first(struct skcipher_givcrypt_request *req) { struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req); struct async_chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv); + int err = 0; if (test_and_set_bit(CHAINIV_STATE_INUSE, &ctx->state)) goto out; @@ -212,11 +219,15 @@ static int async_chainiv_givencrypt_first(struct skcipher_givcrypt_request *req) goto unlock; crypto_ablkcipher_crt(geniv)->givencrypt = async_chainiv_givencrypt; - get_random_bytes(ctx->iv, crypto_ablkcipher_ivsize(geniv)); + err = crypto_rng_get_bytes(crypto_default_rng, ctx->iv, + crypto_ablkcipher_ivsize(geniv)); unlock: clear_bit(CHAINIV_STATE_INUSE, &ctx->state); + if (err) + return err; + out: return async_chainiv_givencrypt(req); } @@ -284,9 +295,13 @@ static struct crypto_instance *chainiv_alloc(struct rtattr **tb) if (IS_ERR(algt)) return ERR_PTR(err); + err = crypto_get_default_rng(); + if (err) + return ERR_PTR(err); + inst = skcipher_geniv_alloc(&chainiv_tmpl, tb, 0, 0); if (IS_ERR(inst)) - goto out; + goto put_rng; inst->alg.cra_ablkcipher.givencrypt = chainiv_givencrypt_first; @@ -311,21 +326,37 @@ static struct crypto_instance *chainiv_alloc(struct rtattr **tb) out: return inst; + +put_rng: + crypto_put_default_rng(); + goto out; +} + +static void chainiv_free(struct crypto_instance *inst) +{ + skcipher_geniv_free(inst); + crypto_put_default_rng(); } static struct crypto_template chainiv_tmpl = { .name = "chainiv", .alloc = chainiv_alloc, - .free = skcipher_geniv_free, + .free = chainiv_free, .module = THIS_MODULE, }; -int __init chainiv_module_init(void) +static int __init chainiv_module_init(void) { return crypto_register_template(&chainiv_tmpl); } -void chainiv_module_exit(void) +static void chainiv_module_exit(void) { crypto_unregister_template(&chainiv_tmpl); } + +module_init(chainiv_module_init); +module_exit(chainiv_module_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Chain IV Generator");