115e7b445SSebastian Siewior /* 215e7b445SSebastian Siewior * Glue Code for assembler optimized version of TWOFISH 315e7b445SSebastian Siewior * 415e7b445SSebastian Siewior * Originally Twofish for GPG 515e7b445SSebastian Siewior * By Matthew Skala <mskala@ansuz.sooke.bc.ca>, July 26, 1998 615e7b445SSebastian Siewior * 256-bit key length added March 20, 1999 715e7b445SSebastian Siewior * Some modifications to reduce the text size by Werner Koch, April, 1998 815e7b445SSebastian Siewior * Ported to the kerneli patch by Marc Mutz <Marc@Mutz.com> 915e7b445SSebastian Siewior * Ported to CryptoAPI by Colin Slater <hoho@tacomeat.net> 1015e7b445SSebastian Siewior * 1115e7b445SSebastian Siewior * The original author has disclaimed all copyright interest in this 1215e7b445SSebastian Siewior * code and thus put it in the public domain. The subsequent authors 1315e7b445SSebastian Siewior * have put this under the GNU General Public License. 1415e7b445SSebastian Siewior * 1515e7b445SSebastian Siewior * This program is free software; you can redistribute it and/or modify 1615e7b445SSebastian Siewior * it under the terms of the GNU General Public License as published by 1715e7b445SSebastian Siewior * the Free Software Foundation; either version 2 of the License, or 1815e7b445SSebastian Siewior * (at your option) any later version. 1915e7b445SSebastian Siewior * 2015e7b445SSebastian Siewior * This program is distributed in the hope that it will be useful, 2115e7b445SSebastian Siewior * but WITHOUT ANY WARRANTY; without even the implied warranty of 2215e7b445SSebastian Siewior * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2315e7b445SSebastian Siewior * GNU General Public License for more details. 2415e7b445SSebastian Siewior * 2515e7b445SSebastian Siewior * You should have received a copy of the GNU General Public License 2615e7b445SSebastian Siewior * along with this program; if not, write to the Free Software 2715e7b445SSebastian Siewior * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 2815e7b445SSebastian Siewior * USA 2915e7b445SSebastian Siewior * 3015e7b445SSebastian Siewior * This code is a "clean room" implementation, written from the paper 3115e7b445SSebastian Siewior * _Twofish: A 128-Bit Block Cipher_ by Bruce Schneier, John Kelsey, 3215e7b445SSebastian Siewior * Doug Whiting, David Wagner, Chris Hall, and Niels Ferguson, available 3315e7b445SSebastian Siewior * through http://www.counterpane.com/twofish.html 3415e7b445SSebastian Siewior * 3515e7b445SSebastian Siewior * For background information on multiplication in finite fields, used for 3615e7b445SSebastian Siewior * the matrix operations in the key schedule, see the book _Contemporary 3715e7b445SSebastian Siewior * Abstract Algebra_ by Joseph A. Gallian, especially chapter 22 in the 3815e7b445SSebastian Siewior * Third Edition. 3915e7b445SSebastian Siewior */ 4015e7b445SSebastian Siewior 4115e7b445SSebastian Siewior #include <crypto/twofish.h> 4215e7b445SSebastian Siewior #include <linux/crypto.h> 4315e7b445SSebastian Siewior #include <linux/init.h> 4415e7b445SSebastian Siewior #include <linux/module.h> 4515e7b445SSebastian Siewior #include <linux/types.h> 4615e7b445SSebastian Siewior 47*91d41f15SJussi Kivilinna asmlinkage void twofish_enc_blk(struct twofish_ctx *ctx, u8 *dst, 48*91d41f15SJussi Kivilinna const u8 *src); 49*91d41f15SJussi Kivilinna EXPORT_SYMBOL_GPL(twofish_enc_blk); 50*91d41f15SJussi Kivilinna asmlinkage void twofish_dec_blk(struct twofish_ctx *ctx, u8 *dst, 51*91d41f15SJussi Kivilinna const u8 *src); 52*91d41f15SJussi Kivilinna EXPORT_SYMBOL_GPL(twofish_dec_blk); 5315e7b445SSebastian Siewior 5415e7b445SSebastian Siewior static void twofish_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 5515e7b445SSebastian Siewior { 56*91d41f15SJussi Kivilinna twofish_enc_blk(crypto_tfm_ctx(tfm), dst, src); 5715e7b445SSebastian Siewior } 5815e7b445SSebastian Siewior 5915e7b445SSebastian Siewior static void twofish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 6015e7b445SSebastian Siewior { 61*91d41f15SJussi Kivilinna twofish_dec_blk(crypto_tfm_ctx(tfm), dst, src); 6215e7b445SSebastian Siewior } 6315e7b445SSebastian Siewior 6415e7b445SSebastian Siewior static struct crypto_alg alg = { 6515e7b445SSebastian Siewior .cra_name = "twofish", 6615e7b445SSebastian Siewior .cra_driver_name = "twofish-asm", 6715e7b445SSebastian Siewior .cra_priority = 200, 6815e7b445SSebastian Siewior .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 6915e7b445SSebastian Siewior .cra_blocksize = TF_BLOCK_SIZE, 7015e7b445SSebastian Siewior .cra_ctxsize = sizeof(struct twofish_ctx), 7115e7b445SSebastian Siewior .cra_alignmask = 3, 7215e7b445SSebastian Siewior .cra_module = THIS_MODULE, 7315e7b445SSebastian Siewior .cra_list = LIST_HEAD_INIT(alg.cra_list), 7415e7b445SSebastian Siewior .cra_u = { 7515e7b445SSebastian Siewior .cipher = { 7615e7b445SSebastian Siewior .cia_min_keysize = TF_MIN_KEY_SIZE, 7715e7b445SSebastian Siewior .cia_max_keysize = TF_MAX_KEY_SIZE, 7815e7b445SSebastian Siewior .cia_setkey = twofish_setkey, 7915e7b445SSebastian Siewior .cia_encrypt = twofish_encrypt, 8015e7b445SSebastian Siewior .cia_decrypt = twofish_decrypt 8115e7b445SSebastian Siewior } 8215e7b445SSebastian Siewior } 8315e7b445SSebastian Siewior }; 8415e7b445SSebastian Siewior 8515e7b445SSebastian Siewior static int __init init(void) 8615e7b445SSebastian Siewior { 8715e7b445SSebastian Siewior return crypto_register_alg(&alg); 8815e7b445SSebastian Siewior } 8915e7b445SSebastian Siewior 9015e7b445SSebastian Siewior static void __exit fini(void) 9115e7b445SSebastian Siewior { 9215e7b445SSebastian Siewior crypto_unregister_alg(&alg); 9315e7b445SSebastian Siewior } 9415e7b445SSebastian Siewior 9515e7b445SSebastian Siewior module_init(init); 9615e7b445SSebastian Siewior module_exit(fini); 9715e7b445SSebastian Siewior 9815e7b445SSebastian Siewior MODULE_LICENSE("GPL"); 9915e7b445SSebastian Siewior MODULE_DESCRIPTION ("Twofish Cipher Algorithm, asm optimized"); 10015e7b445SSebastian Siewior MODULE_ALIAS("twofish"); 10115e7b445SSebastian Siewior MODULE_ALIAS("twofish-asm"); 102