diff options
author | Jussi Kivilinna <jussi.kivilinna@mbnet.fi> | 2012-02-17 15:48:48 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2012-02-25 04:20:23 -0500 |
commit | d433208cfc3db3ae0520da92a15ac1f82d8b61ed (patch) | |
tree | 141688fc3ae7452daef4e378d5168b595a21666b | |
parent | 53709ddee36cbd19434aa0f0ac8c1e27b92aca33 (diff) |
crypto: blowfish-x86_64 - use crypto_[un]register_algs
Combine all crypto_alg to be registered and use new crypto_[un]register_algs
functions. Simplifies init/exit code and reduce object size.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | arch/x86/crypto/blowfish_glue.c | 163 |
1 files changed, 65 insertions, 98 deletions
diff --git a/arch/x86/crypto/blowfish_glue.c b/arch/x86/crypto/blowfish_glue.c index 2970110d2cea..73bc8a93f0ce 100644 --- a/arch/x86/crypto/blowfish_glue.c +++ b/arch/x86/crypto/blowfish_glue.c | |||
@@ -77,27 +77,6 @@ static void blowfish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | |||
77 | blowfish_dec_blk(crypto_tfm_ctx(tfm), dst, src); | 77 | blowfish_dec_blk(crypto_tfm_ctx(tfm), dst, src); |
78 | } | 78 | } |
79 | 79 | ||
80 | static struct crypto_alg bf_alg = { | ||
81 | .cra_name = "blowfish", | ||
82 | .cra_driver_name = "blowfish-asm", | ||
83 | .cra_priority = 200, | ||
84 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | ||
85 | .cra_blocksize = BF_BLOCK_SIZE, | ||
86 | .cra_ctxsize = sizeof(struct bf_ctx), | ||
87 | .cra_alignmask = 3, | ||
88 | .cra_module = THIS_MODULE, | ||
89 | .cra_list = LIST_HEAD_INIT(bf_alg.cra_list), | ||
90 | .cra_u = { | ||
91 | .cipher = { | ||
92 | .cia_min_keysize = BF_MIN_KEY_SIZE, | ||
93 | .cia_max_keysize = BF_MAX_KEY_SIZE, | ||
94 | .cia_setkey = blowfish_setkey, | ||
95 | .cia_encrypt = blowfish_encrypt, | ||
96 | .cia_decrypt = blowfish_decrypt, | ||
97 | } | ||
98 | } | ||
99 | }; | ||
100 | |||
101 | static int ecb_crypt(struct blkcipher_desc *desc, struct blkcipher_walk *walk, | 80 | static int ecb_crypt(struct blkcipher_desc *desc, struct blkcipher_walk *walk, |
102 | void (*fn)(struct bf_ctx *, u8 *, const u8 *), | 81 | void (*fn)(struct bf_ctx *, u8 *, const u8 *), |
103 | void (*fn_4way)(struct bf_ctx *, u8 *, const u8 *)) | 82 | void (*fn_4way)(struct bf_ctx *, u8 *, const u8 *)) |
@@ -161,28 +140,6 @@ static int ecb_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, | |||
161 | return ecb_crypt(desc, &walk, blowfish_dec_blk, blowfish_dec_blk_4way); | 140 | return ecb_crypt(desc, &walk, blowfish_dec_blk, blowfish_dec_blk_4way); |
162 | } | 141 | } |
163 | 142 | ||
164 | static struct crypto_alg blk_ecb_alg = { | ||
165 | .cra_name = "ecb(blowfish)", | ||
166 | .cra_driver_name = "ecb-blowfish-asm", | ||
167 | .cra_priority = 300, | ||
168 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
169 | .cra_blocksize = BF_BLOCK_SIZE, | ||
170 | .cra_ctxsize = sizeof(struct bf_ctx), | ||
171 | .cra_alignmask = 0, | ||
172 | .cra_type = &crypto_blkcipher_type, | ||
173 | .cra_module = THIS_MODULE, | ||
174 | .cra_list = LIST_HEAD_INIT(blk_ecb_alg.cra_list), | ||
175 | .cra_u = { | ||
176 | .blkcipher = { | ||
177 | .min_keysize = BF_MIN_KEY_SIZE, | ||
178 | .max_keysize = BF_MAX_KEY_SIZE, | ||
179 | .setkey = blowfish_setkey, | ||
180 | .encrypt = ecb_encrypt, | ||
181 | .decrypt = ecb_decrypt, | ||
182 | }, | ||
183 | }, | ||
184 | }; | ||
185 | |||
186 | static unsigned int __cbc_encrypt(struct blkcipher_desc *desc, | 143 | static unsigned int __cbc_encrypt(struct blkcipher_desc *desc, |
187 | struct blkcipher_walk *walk) | 144 | struct blkcipher_walk *walk) |
188 | { | 145 | { |
@@ -308,29 +265,6 @@ static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, | |||
308 | return err; | 265 | return err; |
309 | } | 266 | } |
310 | 267 | ||
311 | static struct crypto_alg blk_cbc_alg = { | ||
312 | .cra_name = "cbc(blowfish)", | ||
313 | .cra_driver_name = "cbc-blowfish-asm", | ||
314 | .cra_priority = 300, | ||
315 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
316 | .cra_blocksize = BF_BLOCK_SIZE, | ||
317 | .cra_ctxsize = sizeof(struct bf_ctx), | ||
318 | .cra_alignmask = 0, | ||
319 | .cra_type = &crypto_blkcipher_type, | ||
320 | .cra_module = THIS_MODULE, | ||
321 | .cra_list = LIST_HEAD_INIT(blk_cbc_alg.cra_list), | ||
322 | .cra_u = { | ||
323 | .blkcipher = { | ||
324 | .min_keysize = BF_MIN_KEY_SIZE, | ||
325 | .max_keysize = BF_MAX_KEY_SIZE, | ||
326 | .ivsize = BF_BLOCK_SIZE, | ||
327 | .setkey = blowfish_setkey, | ||
328 | .encrypt = cbc_encrypt, | ||
329 | .decrypt = cbc_decrypt, | ||
330 | }, | ||
331 | }, | ||
332 | }; | ||
333 | |||
334 | static void ctr_crypt_final(struct bf_ctx *ctx, struct blkcipher_walk *walk) | 268 | static void ctr_crypt_final(struct bf_ctx *ctx, struct blkcipher_walk *walk) |
335 | { | 269 | { |
336 | u8 *ctrblk = walk->iv; | 270 | u8 *ctrblk = walk->iv; |
@@ -424,7 +358,67 @@ static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst, | |||
424 | return err; | 358 | return err; |
425 | } | 359 | } |
426 | 360 | ||
427 | static struct crypto_alg blk_ctr_alg = { | 361 | static struct crypto_alg bf_algs[4] = { { |
362 | .cra_name = "blowfish", | ||
363 | .cra_driver_name = "blowfish-asm", | ||
364 | .cra_priority = 200, | ||
365 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | ||
366 | .cra_blocksize = BF_BLOCK_SIZE, | ||
367 | .cra_ctxsize = sizeof(struct bf_ctx), | ||
368 | .cra_alignmask = 3, | ||
369 | .cra_module = THIS_MODULE, | ||
370 | .cra_list = LIST_HEAD_INIT(bf_algs[0].cra_list), | ||
371 | .cra_u = { | ||
372 | .cipher = { | ||
373 | .cia_min_keysize = BF_MIN_KEY_SIZE, | ||
374 | .cia_max_keysize = BF_MAX_KEY_SIZE, | ||
375 | .cia_setkey = blowfish_setkey, | ||
376 | .cia_encrypt = blowfish_encrypt, | ||
377 | .cia_decrypt = blowfish_decrypt, | ||
378 | } | ||
379 | } | ||
380 | }, { | ||
381 | .cra_name = "ecb(blowfish)", | ||
382 | .cra_driver_name = "ecb-blowfish-asm", | ||
383 | .cra_priority = 300, | ||
384 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
385 | .cra_blocksize = BF_BLOCK_SIZE, | ||
386 | .cra_ctxsize = sizeof(struct bf_ctx), | ||
387 | .cra_alignmask = 0, | ||
388 | .cra_type = &crypto_blkcipher_type, | ||
389 | .cra_module = THIS_MODULE, | ||
390 | .cra_list = LIST_HEAD_INIT(bf_algs[1].cra_list), | ||
391 | .cra_u = { | ||
392 | .blkcipher = { | ||
393 | .min_keysize = BF_MIN_KEY_SIZE, | ||
394 | .max_keysize = BF_MAX_KEY_SIZE, | ||
395 | .setkey = blowfish_setkey, | ||
396 | .encrypt = ecb_encrypt, | ||
397 | .decrypt = ecb_decrypt, | ||
398 | }, | ||
399 | }, | ||
400 | }, { | ||
401 | .cra_name = "cbc(blowfish)", | ||
402 | .cra_driver_name = "cbc-blowfish-asm", | ||
403 | .cra_priority = 300, | ||
404 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
405 | .cra_blocksize = BF_BLOCK_SIZE, | ||
406 | .cra_ctxsize = sizeof(struct bf_ctx), | ||
407 | .cra_alignmask = 0, | ||
408 | .cra_type = &crypto_blkcipher_type, | ||
409 | .cra_module = THIS_MODULE, | ||
410 | .cra_list = LIST_HEAD_INIT(bf_algs[2].cra_list), | ||
411 | .cra_u = { | ||
412 | .blkcipher = { | ||
413 | .min_keysize = BF_MIN_KEY_SIZE, | ||
414 | .max_keysize = BF_MAX_KEY_SIZE, | ||
415 | .ivsize = BF_BLOCK_SIZE, | ||
416 | .setkey = blowfish_setkey, | ||
417 | .encrypt = cbc_encrypt, | ||
418 | .decrypt = cbc_decrypt, | ||
419 | }, | ||
420 | }, | ||
421 | }, { | ||
428 | .cra_name = "ctr(blowfish)", | 422 | .cra_name = "ctr(blowfish)", |
429 | .cra_driver_name = "ctr-blowfish-asm", | 423 | .cra_driver_name = "ctr-blowfish-asm", |
430 | .cra_priority = 300, | 424 | .cra_priority = 300, |
@@ -434,7 +428,7 @@ static struct crypto_alg blk_ctr_alg = { | |||
434 | .cra_alignmask = 0, | 428 | .cra_alignmask = 0, |
435 | .cra_type = &crypto_blkcipher_type, | 429 | .cra_type = &crypto_blkcipher_type, |
436 | .cra_module = THIS_MODULE, | 430 | .cra_module = THIS_MODULE, |
437 | .cra_list = LIST_HEAD_INIT(blk_ctr_alg.cra_list), | 431 | .cra_list = LIST_HEAD_INIT(bf_algs[3].cra_list), |
438 | .cra_u = { | 432 | .cra_u = { |
439 | .blkcipher = { | 433 | .blkcipher = { |
440 | .min_keysize = BF_MIN_KEY_SIZE, | 434 | .min_keysize = BF_MIN_KEY_SIZE, |
@@ -445,7 +439,7 @@ static struct crypto_alg blk_ctr_alg = { | |||
445 | .decrypt = ctr_crypt, | 439 | .decrypt = ctr_crypt, |
446 | }, | 440 | }, |
447 | }, | 441 | }, |
448 | }; | 442 | } }; |
449 | 443 | ||
450 | static bool is_blacklisted_cpu(void) | 444 | static bool is_blacklisted_cpu(void) |
451 | { | 445 | { |
@@ -470,8 +464,6 @@ MODULE_PARM_DESC(force, "Force module load, ignore CPU blacklist"); | |||
470 | 464 | ||
471 | static int __init init(void) | 465 | static int __init init(void) |
472 | { | 466 | { |
473 | int err; | ||
474 | |||
475 | if (!force && is_blacklisted_cpu()) { | 467 | if (!force && is_blacklisted_cpu()) { |
476 | printk(KERN_INFO | 468 | printk(KERN_INFO |
477 | "blowfish-x86_64: performance on this CPU " | 469 | "blowfish-x86_64: performance on this CPU " |
@@ -480,37 +472,12 @@ static int __init init(void) | |||
480 | return -ENODEV; | 472 | return -ENODEV; |
481 | } | 473 | } |
482 | 474 | ||
483 | err = crypto_register_alg(&bf_alg); | 475 | return crypto_register_algs(bf_algs, ARRAY_SIZE(bf_algs)); |
484 | if (err) | ||
485 | goto bf_err; | ||
486 | err = crypto_register_alg(&blk_ecb_alg); | ||
487 | if (err) | ||
488 | goto ecb_err; | ||
489 | err = crypto_register_alg(&blk_cbc_alg); | ||
490 | if (err) | ||
491 | goto cbc_err; | ||
492 | err = crypto_register_alg(&blk_ctr_alg); | ||
493 | if (err) | ||
494 | goto ctr_err; | ||
495 | |||
496 | return 0; | ||
497 | |||
498 | ctr_err: | ||
499 | crypto_unregister_alg(&blk_cbc_alg); | ||
500 | cbc_err: | ||
501 | crypto_unregister_alg(&blk_ecb_alg); | ||
502 | ecb_err: | ||
503 | crypto_unregister_alg(&bf_alg); | ||
504 | bf_err: | ||
505 | return err; | ||
506 | } | 476 | } |
507 | 477 | ||
508 | static void __exit fini(void) | 478 | static void __exit fini(void) |
509 | { | 479 | { |
510 | crypto_unregister_alg(&blk_ctr_alg); | 480 | crypto_unregister_algs(bf_algs, ARRAY_SIZE(bf_algs)); |
511 | crypto_unregister_alg(&blk_cbc_alg); | ||
512 | crypto_unregister_alg(&blk_ecb_alg); | ||
513 | crypto_unregister_alg(&bf_alg); | ||
514 | } | 481 | } |
515 | 482 | ||
516 | module_init(init); | 483 | module_init(init); |