xref: /openbmc/linux/arch/arm/crypto/aes-cipher-glue.c (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
281edb426SArd Biesheuvel /*
381edb426SArd Biesheuvel  * Scalar AES core transform
481edb426SArd Biesheuvel  *
581edb426SArd Biesheuvel  * Copyright (C) 2017 Linaro Ltd.
681edb426SArd Biesheuvel  * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
781edb426SArd Biesheuvel  */
881edb426SArd Biesheuvel 
981edb426SArd Biesheuvel #include <crypto/aes.h>
10*14386d47SHerbert Xu #include <crypto/algapi.h>
1181edb426SArd Biesheuvel #include <linux/module.h>
1281edb426SArd Biesheuvel 
1381edb426SArd Biesheuvel asmlinkage void __aes_arm_encrypt(u32 *rk, int rounds, const u8 *in, u8 *out);
1481edb426SArd Biesheuvel asmlinkage void __aes_arm_decrypt(u32 *rk, int rounds, const u8 *in, u8 *out);
1581edb426SArd Biesheuvel 
aes_arm_encrypt(struct crypto_tfm * tfm,u8 * out,const u8 * in)16724ecd3cSArd Biesheuvel static void aes_arm_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
1781edb426SArd Biesheuvel {
1881edb426SArd Biesheuvel 	struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
1981edb426SArd Biesheuvel 	int rounds = 6 + ctx->key_length / 4;
2081edb426SArd Biesheuvel 
2181edb426SArd Biesheuvel 	__aes_arm_encrypt(ctx->key_enc, rounds, in, out);
2281edb426SArd Biesheuvel }
2381edb426SArd Biesheuvel 
aes_arm_decrypt(struct crypto_tfm * tfm,u8 * out,const u8 * in)24724ecd3cSArd Biesheuvel static void aes_arm_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
2581edb426SArd Biesheuvel {
2681edb426SArd Biesheuvel 	struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
2781edb426SArd Biesheuvel 	int rounds = 6 + ctx->key_length / 4;
2881edb426SArd Biesheuvel 
2981edb426SArd Biesheuvel 	__aes_arm_decrypt(ctx->key_dec, rounds, in, out);
3081edb426SArd Biesheuvel }
3181edb426SArd Biesheuvel 
3281edb426SArd Biesheuvel static struct crypto_alg aes_alg = {
3381edb426SArd Biesheuvel 	.cra_name			= "aes",
3481edb426SArd Biesheuvel 	.cra_driver_name		= "aes-arm",
3581edb426SArd Biesheuvel 	.cra_priority			= 200,
3681edb426SArd Biesheuvel 	.cra_flags			= CRYPTO_ALG_TYPE_CIPHER,
3781edb426SArd Biesheuvel 	.cra_blocksize			= AES_BLOCK_SIZE,
3881edb426SArd Biesheuvel 	.cra_ctxsize			= sizeof(struct crypto_aes_ctx),
3981edb426SArd Biesheuvel 	.cra_module			= THIS_MODULE,
4081edb426SArd Biesheuvel 
4181edb426SArd Biesheuvel 	.cra_cipher.cia_min_keysize	= AES_MIN_KEY_SIZE,
4281edb426SArd Biesheuvel 	.cra_cipher.cia_max_keysize	= AES_MAX_KEY_SIZE,
4381edb426SArd Biesheuvel 	.cra_cipher.cia_setkey		= crypto_aes_set_key,
44724ecd3cSArd Biesheuvel 	.cra_cipher.cia_encrypt		= aes_arm_encrypt,
45724ecd3cSArd Biesheuvel 	.cra_cipher.cia_decrypt		= aes_arm_decrypt,
4681edb426SArd Biesheuvel 
4781edb426SArd Biesheuvel #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
4881edb426SArd Biesheuvel 	.cra_alignmask			= 3,
4981edb426SArd Biesheuvel #endif
5081edb426SArd Biesheuvel };
5181edb426SArd Biesheuvel 
aes_init(void)5281edb426SArd Biesheuvel static int __init aes_init(void)
5381edb426SArd Biesheuvel {
5481edb426SArd Biesheuvel 	return crypto_register_alg(&aes_alg);
5581edb426SArd Biesheuvel }
5681edb426SArd Biesheuvel 
aes_fini(void)5781edb426SArd Biesheuvel static void __exit aes_fini(void)
5881edb426SArd Biesheuvel {
5981edb426SArd Biesheuvel 	crypto_unregister_alg(&aes_alg);
6081edb426SArd Biesheuvel }
6181edb426SArd Biesheuvel 
6281edb426SArd Biesheuvel module_init(aes_init);
6381edb426SArd Biesheuvel module_exit(aes_fini);
6481edb426SArd Biesheuvel 
6581edb426SArd Biesheuvel MODULE_DESCRIPTION("Scalar AES cipher for ARM");
6681edb426SArd Biesheuvel MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
6781edb426SArd Biesheuvel MODULE_LICENSE("GPL v2");
6881edb426SArd Biesheuvel MODULE_ALIAS_CRYPTO("aes");
69