git://ftp.safe.ca
/
safe
/
jmp
/
linux-2.6
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
crypto: testmgr - Fix warning
[safe/jmp/linux-2.6]
/
crypto
/
chainiv.c
diff --git
a/crypto/chainiv.c
b/crypto/chainiv.c
index
0a7cac6
..
ba200b0
100644
(file)
--- a/
crypto/chainiv.c
+++ b/
crypto/chainiv.c
@@
-14,11
+14,12
@@
*/
#include <crypto/internal/skcipher.h>
*/
#include <crypto/internal/skcipher.h>
+#include <crypto/rng.h>
+#include <crypto/crypto_wq.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
-#include <linux/random.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/workqueue.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/workqueue.h>
@@
-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);
{
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 !=
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;
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);
unlock:
spin_unlock_bh(&ctx->lock);
+ if (err)
+ return err;
+
return chainiv_givencrypt(req);
}
return chainiv_givencrypt(req);
}
@@
-117,6
+123,7
@@
static int chainiv_init(struct crypto_tfm *tfm)
static int async_chainiv_schedule_work(struct async_chainiv_ctx *ctx)
{
int queued;
static int async_chainiv_schedule_work(struct async_chainiv_ctx *ctx)
{
int queued;
+ int err = ctx->err;
if (!ctx->queue.qlen) {
smp_mb__before_clear_bit();
if (!ctx->queue.qlen) {
smp_mb__before_clear_bit();
@@
-127,11
+134,11
@@
static int async_chainiv_schedule_work(struct async_chainiv_ctx *ctx)
goto out;
}
goto out;
}
- queued =
schedule_work(
&ctx->postponed);
+ queued =
queue_work(kcrypto_wq,
&ctx->postponed);
BUG_ON(!queued);
out:
BUG_ON(!queued);
out:
- return
ctx->
err;
+ return err;
}
static int async_chainiv_postpone_request(struct skcipher_givcrypt_request *req)
}
static int async_chainiv_postpone_request(struct skcipher_givcrypt_request *req)
@@
-202,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);
{
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;
if (test_and_set_bit(CHAINIV_STATE_INUSE, &ctx->state))
goto out;
@@
-211,11
+219,15
@@
static int async_chainiv_givencrypt_first(struct skcipher_givcrypt_request *req)
goto unlock;
crypto_ablkcipher_crt(geniv)->givencrypt = async_chainiv_givencrypt;
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);
unlock:
clear_bit(CHAINIV_STATE_INUSE, &ctx->state);
+ if (err)
+ return err;
+
out:
return async_chainiv_givencrypt(req);
}
out:
return async_chainiv_givencrypt(req);
}
@@
-227,6
+239,7
@@
static void async_chainiv_do_postponed(struct work_struct *work)
postponed);
struct skcipher_givcrypt_request *req;
struct ablkcipher_request *subreq;
postponed);
struct skcipher_givcrypt_request *req;
struct ablkcipher_request *subreq;
+ int err;
/* Only handle one request at a time to avoid hogging keventd. */
spin_lock_bh(&ctx->lock);
/* Only handle one request at a time to avoid hogging keventd. */
spin_lock_bh(&ctx->lock);
@@
-241,7
+254,11
@@
static void async_chainiv_do_postponed(struct work_struct *work)
subreq = skcipher_givcrypt_reqctx(req);
subreq->base.flags |= CRYPTO_TFM_REQ_MAY_SLEEP;
subreq = skcipher_givcrypt_reqctx(req);
subreq->base.flags |= CRYPTO_TFM_REQ_MAY_SLEEP;
- async_chainiv_givencrypt_tail(req);
+ err = async_chainiv_givencrypt_tail(req);
+
+ local_bh_disable();
+ skcipher_givcrypt_complete(req, err);
+ local_bh_enable();
}
static int async_chainiv_init(struct crypto_tfm *tfm)
}
static int async_chainiv_init(struct crypto_tfm *tfm)
@@
-278,9
+295,13
@@
static struct crypto_instance *chainiv_alloc(struct rtattr **tb)
if (IS_ERR(algt))
return ERR_PTR(err);
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))
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;
inst->alg.cra_ablkcipher.givencrypt = chainiv_givencrypt_first;
@@
-305,23
+326,37
@@
static struct crypto_instance *chainiv_alloc(struct rtattr **tb)
out:
return inst;
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,
}
static struct crypto_template chainiv_tmpl = {
.name = "chainiv",
.alloc = chainiv_alloc,
- .free =
skcipher_ge
niv_free,
+ .free =
chai
niv_free,
.module = THIS_MODULE,
};
.module = THIS_MODULE,
};
-int __init chainiv_module_init(void)
+
static
int __init chainiv_module_init(void)
{
return crypto_register_template(&chainiv_tmpl);
}
{
return crypto_register_template(&chainiv_tmpl);
}
-EXPORT_SYMBOL_GPL(chainiv_module_init);
-
void __exit
chainiv_module_exit(void)
+
static void
chainiv_module_exit(void)
{
crypto_unregister_template(&chainiv_tmpl);
}
{
crypto_unregister_template(&chainiv_tmpl);
}
-EXPORT_SYMBOL_GPL(chainiv_module_exit);
+
+module_init(chainiv_module_init);
+module_exit(chainiv_module_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Chain IV Generator");