1
2
3
4
5
6
7
8
9
10
11#include <crypto/aes.h>
12#include <linux/crypto.h>
13#include <linux/module.h>
14
15asmlinkage void __aes_arm64_encrypt(u32 *rk, u8 *out, const u8 *in, int rounds);
16EXPORT_SYMBOL(__aes_arm64_encrypt);
17
18asmlinkage void __aes_arm64_decrypt(u32 *rk, u8 *out, const u8 *in, int rounds);
19EXPORT_SYMBOL(__aes_arm64_decrypt);
20
21static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
22{
23 struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
24 int rounds = 6 + ctx->key_length / 4;
25
26 __aes_arm64_encrypt(ctx->key_enc, out, in, rounds);
27}
28
29static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
30{
31 struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
32 int rounds = 6 + ctx->key_length / 4;
33
34 __aes_arm64_decrypt(ctx->key_dec, out, in, rounds);
35}
36
37static struct crypto_alg aes_alg = {
38 .cra_name = "aes",
39 .cra_driver_name = "aes-arm64",
40 .cra_priority = 200,
41 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
42 .cra_blocksize = AES_BLOCK_SIZE,
43 .cra_ctxsize = sizeof(struct crypto_aes_ctx),
44 .cra_module = THIS_MODULE,
45
46 .cra_cipher.cia_min_keysize = AES_MIN_KEY_SIZE,
47 .cra_cipher.cia_max_keysize = AES_MAX_KEY_SIZE,
48 .cra_cipher.cia_setkey = crypto_aes_set_key,
49 .cra_cipher.cia_encrypt = aes_encrypt,
50 .cra_cipher.cia_decrypt = aes_decrypt
51};
52
53static int __init aes_init(void)
54{
55 return crypto_register_alg(&aes_alg);
56}
57
58static void __exit aes_fini(void)
59{
60 crypto_unregister_alg(&aes_alg);
61}
62
63module_init(aes_init);
64module_exit(aes_fini);
65
66MODULE_DESCRIPTION("Scalar AES cipher for arm64");
67MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
68MODULE_LICENSE("GPL v2");
69MODULE_ALIAS_CRYPTO("aes");
70