diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-10 14:20:42 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-10 14:20:42 -0400 |
commit | f6bccf695431da0e9bd773550ae91b8cb9ffb227 (patch) | |
tree | ff81689bd9bf849b4827da6fbd69fce471842057 /crypto/chainiv.c | |
parent | 3af73d392c9c414ca527bab9c5d4c2a97698acbd (diff) | |
parent | a0f000ec9b61b99111757df138b11144236fc59b (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
crypto: skcipher - Use RNG interface instead of get_random_bytes
crypto: rng - RNG interface and implementation
crypto: api - Add fips_enable flag
crypto: skcipher - Move IV generators into their own modules
crypto: cryptomgr - Test ciphers using ECB
crypto: api - Use test infrastructure
crypto: cryptomgr - Add test infrastructure
crypto: tcrypt - Add alg_test interface
crypto: tcrypt - Abort and only log if there is an error
crypto: crc32c - Use Intel CRC32 instruction
crypto: tcrypt - Avoid using contiguous pages
crypto: api - Display larval objects properly
crypto: api - Export crypto_alg_lookup instead of __crypto_alg_lookup
crypto: Kconfig - Replace leading spaces with tabs
Diffstat (limited to 'crypto/chainiv.c')
-rw-r--r-- | crypto/chainiv.c | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/crypto/chainiv.c b/crypto/chainiv.c index 9affadee3287..7c37a497b860 100644 --- a/crypto/chainiv.c +++ b/crypto/chainiv.c | |||
@@ -14,11 +14,11 @@ | |||
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <crypto/internal/skcipher.h> | 16 | #include <crypto/internal/skcipher.h> |
17 | #include <crypto/rng.h> | ||
17 | #include <linux/err.h> | 18 | #include <linux/err.h> |
18 | #include <linux/init.h> | 19 | #include <linux/init.h> |
19 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
20 | #include <linux/module.h> | 21 | #include <linux/module.h> |
21 | #include <linux/random.h> | ||
22 | #include <linux/spinlock.h> | 22 | #include <linux/spinlock.h> |
23 | #include <linux/string.h> | 23 | #include <linux/string.h> |
24 | #include <linux/workqueue.h> | 24 | #include <linux/workqueue.h> |
@@ -83,6 +83,7 @@ static int chainiv_givencrypt_first(struct skcipher_givcrypt_request *req) | |||
83 | { | 83 | { |
84 | struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req); | 84 | struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req); |
85 | struct chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv); | 85 | struct chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv); |
86 | int err = 0; | ||
86 | 87 | ||
87 | spin_lock_bh(&ctx->lock); | 88 | spin_lock_bh(&ctx->lock); |
88 | if (crypto_ablkcipher_crt(geniv)->givencrypt != | 89 | if (crypto_ablkcipher_crt(geniv)->givencrypt != |
@@ -90,11 +91,15 @@ static int chainiv_givencrypt_first(struct skcipher_givcrypt_request *req) | |||
90 | goto unlock; | 91 | goto unlock; |
91 | 92 | ||
92 | crypto_ablkcipher_crt(geniv)->givencrypt = chainiv_givencrypt; | 93 | crypto_ablkcipher_crt(geniv)->givencrypt = chainiv_givencrypt; |
93 | get_random_bytes(ctx->iv, crypto_ablkcipher_ivsize(geniv)); | 94 | err = crypto_rng_get_bytes(crypto_default_rng, ctx->iv, |
95 | crypto_ablkcipher_ivsize(geniv)); | ||
94 | 96 | ||
95 | unlock: | 97 | unlock: |
96 | spin_unlock_bh(&ctx->lock); | 98 | spin_unlock_bh(&ctx->lock); |
97 | 99 | ||
100 | if (err) | ||
101 | return err; | ||
102 | |||
98 | return chainiv_givencrypt(req); | 103 | return chainiv_givencrypt(req); |
99 | } | 104 | } |
100 | 105 | ||
@@ -203,6 +208,7 @@ static int async_chainiv_givencrypt_first(struct skcipher_givcrypt_request *req) | |||
203 | { | 208 | { |
204 | struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req); | 209 | struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req); |
205 | struct async_chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv); | 210 | struct async_chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv); |
211 | int err = 0; | ||
206 | 212 | ||
207 | if (test_and_set_bit(CHAINIV_STATE_INUSE, &ctx->state)) | 213 | if (test_and_set_bit(CHAINIV_STATE_INUSE, &ctx->state)) |
208 | goto out; | 214 | goto out; |
@@ -212,11 +218,15 @@ static int async_chainiv_givencrypt_first(struct skcipher_givcrypt_request *req) | |||
212 | goto unlock; | 218 | goto unlock; |
213 | 219 | ||
214 | crypto_ablkcipher_crt(geniv)->givencrypt = async_chainiv_givencrypt; | 220 | crypto_ablkcipher_crt(geniv)->givencrypt = async_chainiv_givencrypt; |
215 | get_random_bytes(ctx->iv, crypto_ablkcipher_ivsize(geniv)); | 221 | err = crypto_rng_get_bytes(crypto_default_rng, ctx->iv, |
222 | crypto_ablkcipher_ivsize(geniv)); | ||
216 | 223 | ||
217 | unlock: | 224 | unlock: |
218 | clear_bit(CHAINIV_STATE_INUSE, &ctx->state); | 225 | clear_bit(CHAINIV_STATE_INUSE, &ctx->state); |
219 | 226 | ||
227 | if (err) | ||
228 | return err; | ||
229 | |||
220 | out: | 230 | out: |
221 | return async_chainiv_givencrypt(req); | 231 | return async_chainiv_givencrypt(req); |
222 | } | 232 | } |
@@ -284,9 +294,13 @@ static struct crypto_instance *chainiv_alloc(struct rtattr **tb) | |||
284 | if (IS_ERR(algt)) | 294 | if (IS_ERR(algt)) |
285 | return ERR_PTR(err); | 295 | return ERR_PTR(err); |
286 | 296 | ||
297 | err = crypto_get_default_rng(); | ||
298 | if (err) | ||
299 | return ERR_PTR(err); | ||
300 | |||
287 | inst = skcipher_geniv_alloc(&chainiv_tmpl, tb, 0, 0); | 301 | inst = skcipher_geniv_alloc(&chainiv_tmpl, tb, 0, 0); |
288 | if (IS_ERR(inst)) | 302 | if (IS_ERR(inst)) |
289 | goto out; | 303 | goto put_rng; |
290 | 304 | ||
291 | inst->alg.cra_ablkcipher.givencrypt = chainiv_givencrypt_first; | 305 | inst->alg.cra_ablkcipher.givencrypt = chainiv_givencrypt_first; |
292 | 306 | ||
@@ -311,21 +325,37 @@ static struct crypto_instance *chainiv_alloc(struct rtattr **tb) | |||
311 | 325 | ||
312 | out: | 326 | out: |
313 | return inst; | 327 | return inst; |
328 | |||
329 | put_rng: | ||
330 | crypto_put_default_rng(); | ||
331 | goto out; | ||
332 | } | ||
333 | |||
334 | static void chainiv_free(struct crypto_instance *inst) | ||
335 | { | ||
336 | skcipher_geniv_free(inst); | ||
337 | crypto_put_default_rng(); | ||
314 | } | 338 | } |
315 | 339 | ||
316 | static struct crypto_template chainiv_tmpl = { | 340 | static struct crypto_template chainiv_tmpl = { |
317 | .name = "chainiv", | 341 | .name = "chainiv", |
318 | .alloc = chainiv_alloc, | 342 | .alloc = chainiv_alloc, |
319 | .free = skcipher_geniv_free, | 343 | .free = chainiv_free, |
320 | .module = THIS_MODULE, | 344 | .module = THIS_MODULE, |
321 | }; | 345 | }; |
322 | 346 | ||
323 | int __init chainiv_module_init(void) | 347 | static int __init chainiv_module_init(void) |
324 | { | 348 | { |
325 | return crypto_register_template(&chainiv_tmpl); | 349 | return crypto_register_template(&chainiv_tmpl); |
326 | } | 350 | } |
327 | 351 | ||
328 | void chainiv_module_exit(void) | 352 | static void chainiv_module_exit(void) |
329 | { | 353 | { |
330 | crypto_unregister_template(&chainiv_tmpl); | 354 | crypto_unregister_template(&chainiv_tmpl); |
331 | } | 355 | } |
356 | |||
357 | module_init(chainiv_module_init); | ||
358 | module_exit(chainiv_module_exit); | ||
359 | |||
360 | MODULE_LICENSE("GPL"); | ||
361 | MODULE_DESCRIPTION("Chain IV Generator"); | ||