twofish_glue.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Glue Code for assembler optimized version of TWOFISH
  3. *
  4. * Originally Twofish for GPG
  5. * By Matthew Skala <mskala@ansuz.sooke.bc.ca>, July 26, 1998
  6. * 256-bit key length added March 20, 1999
  7. * Some modifications to reduce the text size by Werner Koch, April, 1998
  8. * Ported to the kerneli patch by Marc Mutz <Marc@Mutz.com>
  9. * Ported to CryptoAPI by Colin Slater <hoho@tacomeat.net>
  10. *
  11. * The original author has disclaimed all copyright interest in this
  12. * code and thus put it in the public domain. The subsequent authors
  13. * have put this under the GNU General Public License.
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  28. * USA
  29. *
  30. * This code is a "clean room" implementation, written from the paper
  31. * _Twofish: A 128-Bit Block Cipher_ by Bruce Schneier, John Kelsey,
  32. * Doug Whiting, David Wagner, Chris Hall, and Niels Ferguson, available
  33. * through http://www.counterpane.com/twofish.html
  34. *
  35. * For background information on multiplication in finite fields, used for
  36. * the matrix operations in the key schedule, see the book _Contemporary
  37. * Abstract Algebra_ by Joseph A. Gallian, especially chapter 22 in the
  38. * Third Edition.
  39. */
  40. #include <crypto/twofish.h>
  41. #include <linux/crypto.h>
  42. #include <linux/init.h>
  43. #include <linux/module.h>
  44. #include <linux/types.h>
  45. asmlinkage void twofish_enc_blk(struct twofish_ctx *ctx, u8 *dst,
  46. const u8 *src);
  47. EXPORT_SYMBOL_GPL(twofish_enc_blk);
  48. asmlinkage void twofish_dec_blk(struct twofish_ctx *ctx, u8 *dst,
  49. const u8 *src);
  50. EXPORT_SYMBOL_GPL(twofish_dec_blk);
  51. static void twofish_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
  52. {
  53. twofish_enc_blk(crypto_tfm_ctx(tfm), dst, src);
  54. }
  55. static void twofish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
  56. {
  57. twofish_dec_blk(crypto_tfm_ctx(tfm), dst, src);
  58. }
  59. static struct crypto_alg alg = {
  60. .cra_name = "twofish",
  61. .cra_driver_name = "twofish-asm",
  62. .cra_priority = 200,
  63. .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
  64. .cra_blocksize = TF_BLOCK_SIZE,
  65. .cra_ctxsize = sizeof(struct twofish_ctx),
  66. .cra_alignmask = 0,
  67. .cra_module = THIS_MODULE,
  68. .cra_u = {
  69. .cipher = {
  70. .cia_min_keysize = TF_MIN_KEY_SIZE,
  71. .cia_max_keysize = TF_MAX_KEY_SIZE,
  72. .cia_setkey = twofish_setkey,
  73. .cia_encrypt = twofish_encrypt,
  74. .cia_decrypt = twofish_decrypt
  75. }
  76. }
  77. };
  78. static int __init init(void)
  79. {
  80. return crypto_register_alg(&alg);
  81. }
  82. static void __exit fini(void)
  83. {
  84. crypto_unregister_alg(&alg);
  85. }
  86. module_init(init);
  87. module_exit(fini);
  88. MODULE_LICENSE("GPL");
  89. MODULE_DESCRIPTION ("Twofish Cipher Algorithm, asm optimized");
  90. MODULE_ALIAS_CRYPTO("twofish");
  91. MODULE_ALIAS_CRYPTO("twofish-asm");