2 * Glue Code for the asm optimized version of the AES Cipher Algorithm
5 #include <linux/module.h>
6 #include <linux/crypto.h>
7 #include <crypto/aes.h>
11 EXPORT_SYMBOL(AES_encrypt
);
12 EXPORT_SYMBOL(AES_decrypt
);
13 EXPORT_SYMBOL(private_AES_set_encrypt_key
);
14 EXPORT_SYMBOL(private_AES_set_decrypt_key
);
16 static void aes_encrypt(struct crypto_tfm
*tfm
, u8
*dst
, const u8
*src
)
18 struct AES_CTX
*ctx
= crypto_tfm_ctx(tfm
);
19 AES_encrypt(src
, dst
, &ctx
->enc_key
);
22 static void aes_decrypt(struct crypto_tfm
*tfm
, u8
*dst
, const u8
*src
)
24 struct AES_CTX
*ctx
= crypto_tfm_ctx(tfm
);
25 AES_decrypt(src
, dst
, &ctx
->dec_key
);
28 static int aes_set_key(struct crypto_tfm
*tfm
, const u8
*in_key
,
31 struct AES_CTX
*ctx
= crypto_tfm_ctx(tfm
);
44 tfm
->crt_flags
|= CRYPTO_TFM_RES_BAD_KEY_LEN
;
48 if (private_AES_set_encrypt_key(in_key
, key_len
, &ctx
->enc_key
) == -1) {
49 tfm
->crt_flags
|= CRYPTO_TFM_RES_BAD_KEY_LEN
;
52 /* private_AES_set_decrypt_key expects an encryption key as input */
53 ctx
->dec_key
= ctx
->enc_key
;
54 if (private_AES_set_decrypt_key(in_key
, key_len
, &ctx
->dec_key
) == -1) {
55 tfm
->crt_flags
|= CRYPTO_TFM_RES_BAD_KEY_LEN
;
61 static struct crypto_alg aes_alg
= {
63 .cra_driver_name
= "aes-asm",
65 .cra_flags
= CRYPTO_ALG_TYPE_CIPHER
,
66 .cra_blocksize
= AES_BLOCK_SIZE
,
67 .cra_ctxsize
= sizeof(struct AES_CTX
),
68 .cra_module
= THIS_MODULE
,
69 .cra_list
= LIST_HEAD_INIT(aes_alg
.cra_list
),
72 .cia_min_keysize
= AES_MIN_KEY_SIZE
,
73 .cia_max_keysize
= AES_MAX_KEY_SIZE
,
74 .cia_setkey
= aes_set_key
,
75 .cia_encrypt
= aes_encrypt
,
76 .cia_decrypt
= aes_decrypt
81 static int __init
aes_init(void)
83 return crypto_register_alg(&aes_alg
);
86 static void __exit
aes_fini(void)
88 crypto_unregister_alg(&aes_alg
);
91 module_init(aes_init
);
92 module_exit(aes_fini
);
94 MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm (ASM)");
95 MODULE_LICENSE("GPL");
96 MODULE_ALIAS_CRYPTO("aes");
97 MODULE_ALIAS_CRYPTO("aes-asm");
98 MODULE_AUTHOR("David McCullough <ucdevel@gmail.com>");