blob: 442949e7e849f17e8911def1e6ae55285043d654 [file] [log] [blame]
Ard Biesheuvel317f2f72014-02-05 18:13:38 +01001/*
2 * aes-ce-cipher.c - core AES cipher using ARMv8 Crypto Extensions
3 *
4 * Copyright (C) 2013 - 2014 Linaro Ltd <ard.biesheuvel@linaro.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
Ard Biesheuvel317f2f72014-02-05 18:13:38 +010011#include <crypto/aes.h>
12#include <linux/cpufeature.h>
13#include <linux/crypto.h>
14#include <linux/module.h>
15
Ard Biesheuvel12ac3ef2014-11-03 16:50:01 +000016#include "aes-ce-setkey.h"
17
Ard Biesheuvel317f2f72014-02-05 18:13:38 +010018MODULE_DESCRIPTION("Synchronous AES cipher using ARMv8 Crypto Extensions");
19MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
20MODULE_LICENSE("GPL v2");
21
Sami Tolvanen7c20af02017-08-10 09:42:10 -070022extern void aes_cipher_encrypt(struct crypto_tfm *tfm, u8 dst[], u8 const src[]);
23extern void aes_cipher_decrypt(struct crypto_tfm *tfm, u8 dst[], u8 const src[]);
Ard Biesheuvel317f2f72014-02-05 18:13:38 +010024
Sami Tolvanen7c20af02017-08-10 09:42:10 -070025#ifdef CONFIG_CFI_CLANG
26static inline void __cfi_aes_cipher_encrypt(struct crypto_tfm *tfm, u8 dst[], u8 const src[])
Ard Biesheuvel317f2f72014-02-05 18:13:38 +010027{
Sami Tolvanen7c20af02017-08-10 09:42:10 -070028 aes_cipher_encrypt(tfm, dst, src);
Ard Biesheuvel317f2f72014-02-05 18:13:38 +010029}
30
Sami Tolvanen7c20af02017-08-10 09:42:10 -070031static inline void __cfi_aes_cipher_decrypt(struct crypto_tfm *tfm, u8 dst[], u8 const src[])
Ard Biesheuvel317f2f72014-02-05 18:13:38 +010032{
Sami Tolvanen7c20af02017-08-10 09:42:10 -070033 aes_cipher_decrypt(tfm, dst, src);
Ard Biesheuvel317f2f72014-02-05 18:13:38 +010034}
35
Sami Tolvanen7c20af02017-08-10 09:42:10 -070036#define aes_cipher_encrypt __cfi_aes_cipher_encrypt
37#define aes_cipher_decrypt __cfi_aes_cipher_decrypt
Ard Biesheuveld33a4902016-10-11 19:15:13 +010038#endif
Ard Biesheuvel12ac3ef2014-11-03 16:50:01 +000039
40int ce_aes_setkey(struct crypto_tfm *tfm, const u8 *in_key,
41 unsigned int key_len)
42{
43 struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
44 int ret;
45
46 ret = ce_aes_expandkey(ctx, in_key, key_len);
47 if (!ret)
48 return 0;
49
50 tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
51 return -EINVAL;
52}
53EXPORT_SYMBOL(ce_aes_setkey);
54
Ard Biesheuvel317f2f72014-02-05 18:13:38 +010055static struct crypto_alg aes_alg = {
56 .cra_name = "aes",
57 .cra_driver_name = "aes-ce",
Ard Biesheuvel08c67812015-11-16 13:12:48 +010058 .cra_priority = 250,
Ard Biesheuvel317f2f72014-02-05 18:13:38 +010059 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
60 .cra_blocksize = AES_BLOCK_SIZE,
61 .cra_ctxsize = sizeof(struct crypto_aes_ctx),
62 .cra_module = THIS_MODULE,
63 .cra_cipher = {
64 .cia_min_keysize = AES_MIN_KEY_SIZE,
65 .cia_max_keysize = AES_MAX_KEY_SIZE,
Ard Biesheuvel12ac3ef2014-11-03 16:50:01 +000066 .cia_setkey = ce_aes_setkey,
Ard Biesheuvel317f2f72014-02-05 18:13:38 +010067 .cia_encrypt = aes_cipher_encrypt,
68 .cia_decrypt = aes_cipher_decrypt
69 }
70};
71
72static int __init aes_mod_init(void)
73{
74 return crypto_register_alg(&aes_alg);
75}
76
77static void __exit aes_mod_exit(void)
78{
79 crypto_unregister_alg(&aes_alg);
80}
81
82module_cpu_feature_match(AES, aes_mod_init);
83module_exit(aes_mod_exit);