Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Crypto API support for AES block cipher
4 *
5 * Copyright 2026 Google LLC
6 */
7
8#include <crypto/aes.h>
9#include <crypto/algapi.h>
10#include <linux/module.h>
11
12static_assert(__alignof__(struct aes_key) <= CRYPTO_MINALIGN);
13
14static int crypto_aes_setkey(struct crypto_tfm *tfm, const u8 *in_key,
15 unsigned int key_len)
16{
17 struct aes_key *key = crypto_tfm_ctx(tfm);
18
19 return aes_preparekey(key, in_key, key_len);
20}
21
22static void crypto_aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
23{
24 const struct aes_key *key = crypto_tfm_ctx(tfm);
25
26 aes_encrypt(key, out, in);
27}
28
29static void crypto_aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
30{
31 const struct aes_key *key = crypto_tfm_ctx(tfm);
32
33 aes_decrypt(key, out, in);
34}
35
36static struct crypto_alg alg = {
37 .cra_name = "aes",
38 .cra_driver_name = "aes-lib",
39 .cra_priority = 100,
40 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
41 .cra_blocksize = AES_BLOCK_SIZE,
42 .cra_ctxsize = sizeof(struct aes_key),
43 .cra_module = THIS_MODULE,
44 .cra_u = { .cipher = { .cia_min_keysize = AES_MIN_KEY_SIZE,
45 .cia_max_keysize = AES_MAX_KEY_SIZE,
46 .cia_setkey = crypto_aes_setkey,
47 .cia_encrypt = crypto_aes_encrypt,
48 .cia_decrypt = crypto_aes_decrypt } }
49};
50
51static int __init crypto_aes_mod_init(void)
52{
53 return crypto_register_alg(&alg);
54}
55module_init(crypto_aes_mod_init);
56
57static void __exit crypto_aes_mod_exit(void)
58{
59 crypto_unregister_alg(&alg);
60}
61module_exit(crypto_aes_mod_exit);
62
63MODULE_DESCRIPTION("Crypto API support for AES block cipher");
64MODULE_LICENSE("GPL");
65MODULE_ALIAS_CRYPTO("aes");
66MODULE_ALIAS_CRYPTO("aes-lib");