Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Sebastian Siewior | 06e1a8f | 2007-11-30 00:15:11 +1100 | [diff] [blame] | 2 | /* |
| 3 | * Glue Code for the asm optimized version of the AES Cipher Algorithm |
| 4 | * |
| 5 | */ |
| 6 | |
Paul Gortmaker | 7c52d55 | 2011-05-27 12:33:10 -0400 | [diff] [blame] | 7 | #include <linux/module.h> |
Sebastian Siewior | 06e1a8f | 2007-11-30 00:15:11 +1100 | [diff] [blame] | 8 | #include <crypto/aes.h> |
Jussi Kivilinna | 70ef260 | 2012-06-18 14:07:50 +0300 | [diff] [blame] | 9 | #include <asm/crypto/aes.h> |
Sebastian Siewior | 06e1a8f | 2007-11-30 00:15:11 +1100 | [diff] [blame] | 10 | |
Huang Ying | 07bf44f | 2009-01-09 17:25:50 +1100 | [diff] [blame] | 11 | asmlinkage void aes_enc_blk(struct crypto_aes_ctx *ctx, u8 *out, const u8 *in); |
| 12 | asmlinkage void aes_dec_blk(struct crypto_aes_ctx *ctx, u8 *out, const u8 *in); |
| 13 | |
| 14 | void crypto_aes_encrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src) |
| 15 | { |
| 16 | aes_enc_blk(ctx, dst, src); |
| 17 | } |
| 18 | EXPORT_SYMBOL_GPL(crypto_aes_encrypt_x86); |
| 19 | |
| 20 | void crypto_aes_decrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src) |
| 21 | { |
| 22 | aes_dec_blk(ctx, dst, src); |
| 23 | } |
| 24 | EXPORT_SYMBOL_GPL(crypto_aes_decrypt_x86); |
Sebastian Siewior | 06e1a8f | 2007-11-30 00:15:11 +1100 | [diff] [blame] | 25 | |
| 26 | static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) |
| 27 | { |
Huang Ying | 07bf44f | 2009-01-09 17:25:50 +1100 | [diff] [blame] | 28 | aes_enc_blk(crypto_tfm_ctx(tfm), dst, src); |
Sebastian Siewior | 06e1a8f | 2007-11-30 00:15:11 +1100 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) |
| 32 | { |
Huang Ying | 07bf44f | 2009-01-09 17:25:50 +1100 | [diff] [blame] | 33 | aes_dec_blk(crypto_tfm_ctx(tfm), dst, src); |
Sebastian Siewior | 06e1a8f | 2007-11-30 00:15:11 +1100 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static struct crypto_alg aes_alg = { |
| 37 | .cra_name = "aes", |
| 38 | .cra_driver_name = "aes-asm", |
| 39 | .cra_priority = 200, |
| 40 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, |
| 41 | .cra_blocksize = AES_BLOCK_SIZE, |
| 42 | .cra_ctxsize = sizeof(struct crypto_aes_ctx), |
| 43 | .cra_module = THIS_MODULE, |
Sebastian Siewior | 06e1a8f | 2007-11-30 00:15:11 +1100 | [diff] [blame] | 44 | .cra_u = { |
| 45 | .cipher = { |
| 46 | .cia_min_keysize = AES_MIN_KEY_SIZE, |
| 47 | .cia_max_keysize = AES_MAX_KEY_SIZE, |
| 48 | .cia_setkey = crypto_aes_set_key, |
| 49 | .cia_encrypt = aes_encrypt, |
| 50 | .cia_decrypt = aes_decrypt |
| 51 | } |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | static int __init aes_init(void) |
| 56 | { |
| 57 | return crypto_register_alg(&aes_alg); |
| 58 | } |
| 59 | |
| 60 | static void __exit aes_fini(void) |
| 61 | { |
| 62 | crypto_unregister_alg(&aes_alg); |
| 63 | } |
| 64 | |
| 65 | module_init(aes_init); |
| 66 | module_exit(aes_fini); |
| 67 | |
| 68 | MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm, asm optimized"); |
| 69 | MODULE_LICENSE("GPL"); |
Kees Cook | 5d26a10 | 2014-11-20 17:05:53 -0800 | [diff] [blame] | 70 | MODULE_ALIAS_CRYPTO("aes"); |
| 71 | MODULE_ALIAS_CRYPTO("aes-asm"); |