1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2bed593c0SArd Biesheuvel /*
3bed593c0SArd Biesheuvel * Scalar AES core transform
4bed593c0SArd Biesheuvel *
5bed593c0SArd Biesheuvel * Copyright (C) 2017 Linaro Ltd <ard.biesheuvel@linaro.org>
6bed593c0SArd Biesheuvel */
7bed593c0SArd Biesheuvel
8bed593c0SArd Biesheuvel #include <crypto/aes.h>
9*14386d47SHerbert Xu #include <crypto/algapi.h>
10bed593c0SArd Biesheuvel #include <linux/module.h>
11bed593c0SArd Biesheuvel
12bed593c0SArd Biesheuvel asmlinkage void __aes_arm64_encrypt(u32 *rk, u8 *out, const u8 *in, int rounds);
13bed593c0SArd Biesheuvel asmlinkage void __aes_arm64_decrypt(u32 *rk, u8 *out, const u8 *in, int rounds);
14bed593c0SArd Biesheuvel
aes_arm64_encrypt(struct crypto_tfm * tfm,u8 * out,const u8 * in)15724ecd3cSArd Biesheuvel static void aes_arm64_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
16bed593c0SArd Biesheuvel {
17bed593c0SArd Biesheuvel struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
18bed593c0SArd Biesheuvel int rounds = 6 + ctx->key_length / 4;
19bed593c0SArd Biesheuvel
20bed593c0SArd Biesheuvel __aes_arm64_encrypt(ctx->key_enc, out, in, rounds);
21bed593c0SArd Biesheuvel }
22bed593c0SArd Biesheuvel
aes_arm64_decrypt(struct crypto_tfm * tfm,u8 * out,const u8 * in)23724ecd3cSArd Biesheuvel static void aes_arm64_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
24bed593c0SArd Biesheuvel {
25bed593c0SArd Biesheuvel struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
26bed593c0SArd Biesheuvel int rounds = 6 + ctx->key_length / 4;
27bed593c0SArd Biesheuvel
28bed593c0SArd Biesheuvel __aes_arm64_decrypt(ctx->key_dec, out, in, rounds);
29bed593c0SArd Biesheuvel }
30bed593c0SArd Biesheuvel
31bed593c0SArd Biesheuvel static struct crypto_alg aes_alg = {
32bed593c0SArd Biesheuvel .cra_name = "aes",
33bed593c0SArd Biesheuvel .cra_driver_name = "aes-arm64",
34bed593c0SArd Biesheuvel .cra_priority = 200,
35bed593c0SArd Biesheuvel .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
36bed593c0SArd Biesheuvel .cra_blocksize = AES_BLOCK_SIZE,
37bed593c0SArd Biesheuvel .cra_ctxsize = sizeof(struct crypto_aes_ctx),
38bed593c0SArd Biesheuvel .cra_module = THIS_MODULE,
39bed593c0SArd Biesheuvel
40bed593c0SArd Biesheuvel .cra_cipher.cia_min_keysize = AES_MIN_KEY_SIZE,
41bed593c0SArd Biesheuvel .cra_cipher.cia_max_keysize = AES_MAX_KEY_SIZE,
42bed593c0SArd Biesheuvel .cra_cipher.cia_setkey = crypto_aes_set_key,
43724ecd3cSArd Biesheuvel .cra_cipher.cia_encrypt = aes_arm64_encrypt,
44724ecd3cSArd Biesheuvel .cra_cipher.cia_decrypt = aes_arm64_decrypt
45bed593c0SArd Biesheuvel };
46bed593c0SArd Biesheuvel
aes_init(void)47bed593c0SArd Biesheuvel static int __init aes_init(void)
48bed593c0SArd Biesheuvel {
49bed593c0SArd Biesheuvel return crypto_register_alg(&aes_alg);
50bed593c0SArd Biesheuvel }
51bed593c0SArd Biesheuvel
aes_fini(void)52bed593c0SArd Biesheuvel static void __exit aes_fini(void)
53bed593c0SArd Biesheuvel {
54bed593c0SArd Biesheuvel crypto_unregister_alg(&aes_alg);
55bed593c0SArd Biesheuvel }
56bed593c0SArd Biesheuvel
57bed593c0SArd Biesheuvel module_init(aes_init);
58bed593c0SArd Biesheuvel module_exit(aes_fini);
59bed593c0SArd Biesheuvel
60bed593c0SArd Biesheuvel MODULE_DESCRIPTION("Scalar AES cipher for arm64");
61bed593c0SArd Biesheuvel MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
62bed593c0SArd Biesheuvel MODULE_LICENSE("GPL v2");
63bed593c0SArd Biesheuvel MODULE_ALIAS_CRYPTO("aes");
64