blob: c222f6e072add0d25382715938743b92b7044102 [file] [log] [blame]
Ard Biesheuvelb7912e02017-01-11 16:41:53 +00001/*
2 * Scalar AES core transform
3 *
4 * Copyright (C) 2017 Linaro Ltd.
5 * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <crypto/aes.h>
13#include <linux/crypto.h>
14#include <linux/module.h>
15
16asmlinkage void __aes_arm_encrypt(u32 *rk, int rounds, const u8 *in, u8 *out);
17EXPORT_SYMBOL(__aes_arm_encrypt);
18
19asmlinkage void __aes_arm_decrypt(u32 *rk, int rounds, const u8 *in, u8 *out);
20EXPORT_SYMBOL(__aes_arm_decrypt);
21
22static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
23{
24 struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
25 int rounds = 6 + ctx->key_length / 4;
26
27 __aes_arm_encrypt(ctx->key_enc, rounds, in, out);
28}
29
30static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
31{
32 struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
33 int rounds = 6 + ctx->key_length / 4;
34
35 __aes_arm_decrypt(ctx->key_dec, rounds, in, out);
36}
37
38static struct crypto_alg aes_alg = {
39 .cra_name = "aes",
40 .cra_driver_name = "aes-arm",
41 .cra_priority = 200,
42 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
43 .cra_blocksize = AES_BLOCK_SIZE,
44 .cra_ctxsize = sizeof(struct crypto_aes_ctx),
45 .cra_module = THIS_MODULE,
46
47 .cra_cipher.cia_min_keysize = AES_MIN_KEY_SIZE,
48 .cra_cipher.cia_max_keysize = AES_MAX_KEY_SIZE,
49 .cra_cipher.cia_setkey = crypto_aes_set_key,
50 .cra_cipher.cia_encrypt = aes_encrypt,
51 .cra_cipher.cia_decrypt = aes_decrypt,
52
53#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
54 .cra_alignmask = 3,
55#endif
56};
57
58static int __init aes_init(void)
59{
60 return crypto_register_alg(&aes_alg);
61}
62
63static void __exit aes_fini(void)
64{
65 crypto_unregister_alg(&aes_alg);
66}
67
68module_init(aes_init);
69module_exit(aes_fini);
70
71MODULE_DESCRIPTION("Scalar AES cipher for ARM");
72MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
73MODULE_LICENSE("GPL v2");
74MODULE_ALIAS_CRYPTO("aes");