18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Glue Code for assembler optimized version of TWOFISH
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Originally Twofish for GPG
58c2ecf20Sopenharmony_ci * By Matthew Skala <mskala@ansuz.sooke.bc.ca>, July 26, 1998
68c2ecf20Sopenharmony_ci * 256-bit key length added March 20, 1999
78c2ecf20Sopenharmony_ci * Some modifications to reduce the text size by Werner Koch, April, 1998
88c2ecf20Sopenharmony_ci * Ported to the kerneli patch by Marc Mutz <Marc@Mutz.com>
98c2ecf20Sopenharmony_ci * Ported to CryptoAPI by Colin Slater <hoho@tacomeat.net>
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The original author has disclaimed all copyright interest in this
128c2ecf20Sopenharmony_ci * code and thus put it in the public domain. The subsequent authors
138c2ecf20Sopenharmony_ci * have put this under the GNU General Public License.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
168c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
178c2ecf20Sopenharmony_ci * the Free Software Foundation; either version 2 of the License, or
188c2ecf20Sopenharmony_ci * (at your option) any later version.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful,
218c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
228c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
238c2ecf20Sopenharmony_ci * GNU General Public License for more details.
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License
268c2ecf20Sopenharmony_ci * along with this program; if not, write to the Free Software
278c2ecf20Sopenharmony_ci * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
288c2ecf20Sopenharmony_ci * USA
298c2ecf20Sopenharmony_ci *
308c2ecf20Sopenharmony_ci * This code is a "clean room" implementation, written from the paper
318c2ecf20Sopenharmony_ci * _Twofish: A 128-Bit Block Cipher_ by Bruce Schneier, John Kelsey,
328c2ecf20Sopenharmony_ci * Doug Whiting, David Wagner, Chris Hall, and Niels Ferguson, available
338c2ecf20Sopenharmony_ci * through http://www.counterpane.com/twofish.html
348c2ecf20Sopenharmony_ci *
358c2ecf20Sopenharmony_ci * For background information on multiplication in finite fields, used for
368c2ecf20Sopenharmony_ci * the matrix operations in the key schedule, see the book _Contemporary
378c2ecf20Sopenharmony_ci * Abstract Algebra_ by Joseph A. Gallian, especially chapter 22 in the
388c2ecf20Sopenharmony_ci * Third Edition.
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#include <crypto/twofish.h>
428c2ecf20Sopenharmony_ci#include <linux/crypto.h>
438c2ecf20Sopenharmony_ci#include <linux/init.h>
448c2ecf20Sopenharmony_ci#include <linux/module.h>
458c2ecf20Sopenharmony_ci#include <linux/types.h>
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciasmlinkage void twofish_enc_blk(struct twofish_ctx *ctx, u8 *dst,
488c2ecf20Sopenharmony_ci				const u8 *src);
498c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(twofish_enc_blk);
508c2ecf20Sopenharmony_ciasmlinkage void twofish_dec_blk(struct twofish_ctx *ctx, u8 *dst,
518c2ecf20Sopenharmony_ci				const u8 *src);
528c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(twofish_dec_blk);
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic void twofish_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	twofish_enc_blk(crypto_tfm_ctx(tfm), dst, src);
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic void twofish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	twofish_dec_blk(crypto_tfm_ctx(tfm), dst, src);
628c2ecf20Sopenharmony_ci}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistatic struct crypto_alg alg = {
658c2ecf20Sopenharmony_ci	.cra_name		=	"twofish",
668c2ecf20Sopenharmony_ci	.cra_driver_name	=	"twofish-asm",
678c2ecf20Sopenharmony_ci	.cra_priority		=	200,
688c2ecf20Sopenharmony_ci	.cra_flags		=	CRYPTO_ALG_TYPE_CIPHER,
698c2ecf20Sopenharmony_ci	.cra_blocksize		=	TF_BLOCK_SIZE,
708c2ecf20Sopenharmony_ci	.cra_ctxsize		=	sizeof(struct twofish_ctx),
718c2ecf20Sopenharmony_ci	.cra_alignmask		=	0,
728c2ecf20Sopenharmony_ci	.cra_module		=	THIS_MODULE,
738c2ecf20Sopenharmony_ci	.cra_u			=	{
748c2ecf20Sopenharmony_ci		.cipher = {
758c2ecf20Sopenharmony_ci			.cia_min_keysize	=	TF_MIN_KEY_SIZE,
768c2ecf20Sopenharmony_ci			.cia_max_keysize	=	TF_MAX_KEY_SIZE,
778c2ecf20Sopenharmony_ci			.cia_setkey		=	twofish_setkey,
788c2ecf20Sopenharmony_ci			.cia_encrypt		=	twofish_encrypt,
798c2ecf20Sopenharmony_ci			.cia_decrypt		=	twofish_decrypt
808c2ecf20Sopenharmony_ci		}
818c2ecf20Sopenharmony_ci	}
828c2ecf20Sopenharmony_ci};
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cistatic int __init init(void)
858c2ecf20Sopenharmony_ci{
868c2ecf20Sopenharmony_ci	return crypto_register_alg(&alg);
878c2ecf20Sopenharmony_ci}
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistatic void __exit fini(void)
908c2ecf20Sopenharmony_ci{
918c2ecf20Sopenharmony_ci	crypto_unregister_alg(&alg);
928c2ecf20Sopenharmony_ci}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cimodule_init(init);
958c2ecf20Sopenharmony_cimodule_exit(fini);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
988c2ecf20Sopenharmony_ciMODULE_DESCRIPTION ("Twofish Cipher Algorithm, asm optimized");
998c2ecf20Sopenharmony_ciMODULE_ALIAS_CRYPTO("twofish");
1008c2ecf20Sopenharmony_ciMODULE_ALIAS_CRYPTO("twofish-asm");
101