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