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>
12 unsigned int rd_key
[4 *(AES_MAXNR
+ 1)];
21 asmlinkage
void AES_encrypt(const u8
*in
, u8
*out
, AES_KEY
*ctx
);
22 asmlinkage
void AES_decrypt(const u8
*in
, u8
*out
, AES_KEY
*ctx
);
23 asmlinkage
int private_AES_set_decrypt_key(const unsigned char *userKey
, const int bits
, AES_KEY
*key
);
24 asmlinkage
int private_AES_set_encrypt_key(const unsigned char *userKey
, const int bits
, AES_KEY
*key
);
26 static void aes_encrypt(struct crypto_tfm
*tfm
, u8
*dst
, const u8
*src
)
28 struct AES_CTX
*ctx
= crypto_tfm_ctx(tfm
);
29 AES_encrypt(src
, dst
, &ctx
->enc_key
);
32 static void aes_decrypt(struct crypto_tfm
*tfm
, u8
*dst
, const u8
*src
)
34 struct AES_CTX
*ctx
= crypto_tfm_ctx(tfm
);
35 AES_decrypt(src
, dst
, &ctx
->dec_key
);
38 static int aes_set_key(struct crypto_tfm
*tfm
, const u8
*in_key
,
41 struct AES_CTX
*ctx
= crypto_tfm_ctx(tfm
);
54 tfm
->crt_flags
|= CRYPTO_TFM_RES_BAD_KEY_LEN
;
58 if (private_AES_set_encrypt_key(in_key
, key_len
, &ctx
->enc_key
) == -1) {
59 tfm
->crt_flags
|= CRYPTO_TFM_RES_BAD_KEY_LEN
;
62 /* private_AES_set_decrypt_key expects an encryption key as input */
63 ctx
->dec_key
= ctx
->enc_key
;
64 if (private_AES_set_decrypt_key(in_key
, key_len
, &ctx
->dec_key
) == -1) {
65 tfm
->crt_flags
|= CRYPTO_TFM_RES_BAD_KEY_LEN
;
71 static struct crypto_alg aes_alg
= {
73 .cra_driver_name
= "aes-asm",
75 .cra_flags
= CRYPTO_ALG_TYPE_CIPHER
,
76 .cra_blocksize
= AES_BLOCK_SIZE
,
77 .cra_ctxsize
= sizeof(struct AES_CTX
),
78 .cra_module
= THIS_MODULE
,
79 .cra_list
= LIST_HEAD_INIT(aes_alg
.cra_list
),
82 .cia_min_keysize
= AES_MIN_KEY_SIZE
,
83 .cia_max_keysize
= AES_MAX_KEY_SIZE
,
84 .cia_setkey
= aes_set_key
,
85 .cia_encrypt
= aes_encrypt
,
86 .cia_decrypt
= aes_decrypt
91 static int __init
aes_init(void)
93 return crypto_register_alg(&aes_alg
);
96 static void __exit
aes_fini(void)
98 crypto_unregister_alg(&aes_alg
);
101 module_init(aes_init
);
102 module_exit(aes_fini
);
104 MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm (ASM)");
105 MODULE_LICENSE("GPL");
107 MODULE_ALIAS("aes-asm");
108 MODULE_AUTHOR("David McCullough <ucdevel@gmail.com>");