Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Glue Code for assembler optimized version of TWOFISH
0003  *
0004  * Originally Twofish for GPG
0005  * By Matthew Skala <mskala@ansuz.sooke.bc.ca>, July 26, 1998
0006  * 256-bit key length added March 20, 1999
0007  * Some modifications to reduce the text size by Werner Koch, April, 1998
0008  * Ported to the kerneli patch by Marc Mutz <Marc@Mutz.com>
0009  * Ported to CryptoAPI by Colin Slater <hoho@tacomeat.net>
0010  *
0011  * The original author has disclaimed all copyright interest in this
0012  * code and thus put it in the public domain. The subsequent authors
0013  * have put this under the GNU General Public License.
0014  *
0015  * This program is free software; you can redistribute it and/or modify
0016  * it under the terms of the GNU General Public License as published by
0017  * the Free Software Foundation; either version 2 of the License, or
0018  * (at your option) any later version.
0019  *
0020  * This program is distributed in the hope that it will be useful,
0021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0023  * GNU General Public License for more details.
0024  *
0025  * You should have received a copy of the GNU General Public License
0026  * along with this program; if not, write to the Free Software
0027  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
0028  * USA
0029  *
0030  * This code is a "clean room" implementation, written from the paper
0031  * _Twofish: A 128-Bit Block Cipher_ by Bruce Schneier, John Kelsey,
0032  * Doug Whiting, David Wagner, Chris Hall, and Niels Ferguson, available
0033  * through http://www.counterpane.com/twofish.html
0034  *
0035  * For background information on multiplication in finite fields, used for
0036  * the matrix operations in the key schedule, see the book _Contemporary
0037  * Abstract Algebra_ by Joseph A. Gallian, especially chapter 22 in the
0038  * Third Edition.
0039  */
0040 
0041 #include <crypto/twofish.h>
0042 #include <linux/crypto.h>
0043 #include <linux/init.h>
0044 #include <linux/module.h>
0045 #include <linux/types.h>
0046 
0047 asmlinkage void twofish_enc_blk(struct twofish_ctx *ctx, u8 *dst,
0048                 const u8 *src);
0049 EXPORT_SYMBOL_GPL(twofish_enc_blk);
0050 asmlinkage void twofish_dec_blk(struct twofish_ctx *ctx, u8 *dst,
0051                 const u8 *src);
0052 EXPORT_SYMBOL_GPL(twofish_dec_blk);
0053 
0054 static void twofish_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
0055 {
0056     twofish_enc_blk(crypto_tfm_ctx(tfm), dst, src);
0057 }
0058 
0059 static void twofish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
0060 {
0061     twofish_dec_blk(crypto_tfm_ctx(tfm), dst, src);
0062 }
0063 
0064 static struct crypto_alg alg = {
0065     .cra_name       =   "twofish",
0066     .cra_driver_name    =   "twofish-asm",
0067     .cra_priority       =   200,
0068     .cra_flags      =   CRYPTO_ALG_TYPE_CIPHER,
0069     .cra_blocksize      =   TF_BLOCK_SIZE,
0070     .cra_ctxsize        =   sizeof(struct twofish_ctx),
0071     .cra_alignmask      =   0,
0072     .cra_module     =   THIS_MODULE,
0073     .cra_u          =   {
0074         .cipher = {
0075             .cia_min_keysize    =   TF_MIN_KEY_SIZE,
0076             .cia_max_keysize    =   TF_MAX_KEY_SIZE,
0077             .cia_setkey     =   twofish_setkey,
0078             .cia_encrypt        =   twofish_encrypt,
0079             .cia_decrypt        =   twofish_decrypt
0080         }
0081     }
0082 };
0083 
0084 static int __init twofish_glue_init(void)
0085 {
0086     return crypto_register_alg(&alg);
0087 }
0088 
0089 static void __exit twofish_glue_fini(void)
0090 {
0091     crypto_unregister_alg(&alg);
0092 }
0093 
0094 module_init(twofish_glue_init);
0095 module_exit(twofish_glue_fini);
0096 
0097 MODULE_LICENSE("GPL");
0098 MODULE_DESCRIPTION ("Twofish Cipher Algorithm, asm optimized");
0099 MODULE_ALIAS_CRYPTO("twofish");
0100 MODULE_ALIAS_CRYPTO("twofish-asm");