2 * Scalar AES core transform
4 * Copyright (C) 2017 Linaro Ltd.
5 * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
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.
12 #include <crypto/aes.h>
13 #include <linux/crypto.h>
14 #include <linux/module.h>
16 asmlinkage
void __aes_arm_encrypt(u32
*rk
, int rounds
, const u8
*in
, u8
*out
);
17 EXPORT_SYMBOL(__aes_arm_encrypt
);
19 asmlinkage
void __aes_arm_decrypt(u32
*rk
, int rounds
, const u8
*in
, u8
*out
);
20 EXPORT_SYMBOL(__aes_arm_decrypt
);
22 static void aes_encrypt(struct crypto_tfm
*tfm
, u8
*out
, const u8
*in
)
24 struct crypto_aes_ctx
*ctx
= crypto_tfm_ctx(tfm
);
25 int rounds
= 6 + ctx
->key_length
/ 4;
27 __aes_arm_encrypt(ctx
->key_enc
, rounds
, in
, out
);
30 static void aes_decrypt(struct crypto_tfm
*tfm
, u8
*out
, const u8
*in
)
32 struct crypto_aes_ctx
*ctx
= crypto_tfm_ctx(tfm
);
33 int rounds
= 6 + ctx
->key_length
/ 4;
35 __aes_arm_decrypt(ctx
->key_dec
, rounds
, in
, out
);
38 static struct crypto_alg aes_alg
= {
40 .cra_driver_name
= "aes-arm",
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
,
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
,
53 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
58 static int __init
aes_init(void)
60 return crypto_register_alg(&aes_alg
);
63 static void __exit
aes_fini(void)
65 crypto_unregister_alg(&aes_alg
);
68 module_init(aes_init
);
69 module_exit(aes_fini
);
71 MODULE_DESCRIPTION("Scalar AES cipher for ARM");
72 MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
73 MODULE_LICENSE("GPL v2");
74 MODULE_ALIAS_CRYPTO("aes");