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