hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/arch/arm64/crypto/aes-ce-ccm-glue.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * aes-ccm-glue.c - AES-CCM transform for ARMv8 with Crypto Extensions
34 *
45 * Copyright (C) 2013 - 2017 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.
96 */
107
118 #include <asm/neon.h>
....@@ -14,6 +11,7 @@
1411 #include <crypto/aes.h>
1512 #include <crypto/scatterwalk.h>
1613 #include <crypto/internal/aead.h>
14
+#include <crypto/internal/simd.h>
1715 #include <crypto/internal/skcipher.h>
1816 #include <linux/module.h>
1917
....@@ -45,20 +43,12 @@
4543 asmlinkage void ce_aes_ccm_final(u8 mac[], u8 const ctr[], u32 const rk[],
4644 u32 rounds);
4745
48
-asmlinkage void __aes_arm64_encrypt(u32 *rk, u8 *out, const u8 *in, int rounds);
49
-
5046 static int ccm_setkey(struct crypto_aead *tfm, const u8 *in_key,
5147 unsigned int key_len)
5248 {
5349 struct crypto_aes_ctx *ctx = crypto_aead_ctx(tfm);
54
- int ret;
5550
56
- ret = ce_aes_expandkey(ctx, in_key, key_len);
57
- if (!ret)
58
- return 0;
59
-
60
- tfm->base.crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
61
- return -EINVAL;
51
+ return ce_aes_expandkey(ctx, in_key, key_len);
6252 }
6353
6454 static int ccm_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
....@@ -109,7 +99,7 @@
10999 static void ccm_update_mac(struct crypto_aes_ctx *key, u8 mac[], u8 const in[],
110100 u32 abytes, u32 *macp)
111101 {
112
- if (may_use_simd()) {
102
+ if (crypto_simd_usable()) {
113103 kernel_neon_begin();
114104 ce_aes_ccm_auth_data(mac, in, abytes, macp, key->key_enc,
115105 num_rounds(key));
....@@ -126,8 +116,7 @@
126116 }
127117
128118 while (abytes >= AES_BLOCK_SIZE) {
129
- __aes_arm64_encrypt(key->key_enc, mac, mac,
130
- num_rounds(key));
119
+ aes_encrypt(key, mac, mac);
131120 crypto_xor(mac, in, AES_BLOCK_SIZE);
132121
133122 in += AES_BLOCK_SIZE;
....@@ -135,8 +124,7 @@
135124 }
136125
137126 if (abytes > 0) {
138
- __aes_arm64_encrypt(key->key_enc, mac, mac,
139
- num_rounds(key));
127
+ aes_encrypt(key, mac, mac);
140128 crypto_xor(mac, in, abytes);
141129 *macp = abytes;
142130 }
....@@ -208,10 +196,8 @@
208196 bsize = nbytes;
209197
210198 crypto_inc(walk->iv, AES_BLOCK_SIZE);
211
- __aes_arm64_encrypt(ctx->key_enc, buf, walk->iv,
212
- num_rounds(ctx));
213
- __aes_arm64_encrypt(ctx->key_enc, mac, mac,
214
- num_rounds(ctx));
199
+ aes_encrypt(ctx, buf, walk->iv);
200
+ aes_encrypt(ctx, mac, mac);
215201 if (enc)
216202 crypto_xor(mac, src, bsize);
217203 crypto_xor_cpy(dst, src, buf, bsize);
....@@ -226,8 +212,8 @@
226212 }
227213
228214 if (!err) {
229
- __aes_arm64_encrypt(ctx->key_enc, buf, iv0, num_rounds(ctx));
230
- __aes_arm64_encrypt(ctx->key_enc, mac, mac, num_rounds(ctx));
215
+ aes_encrypt(ctx, buf, iv0);
216
+ aes_encrypt(ctx, mac, mac);
231217 crypto_xor(mac, buf, AES_BLOCK_SIZE);
232218 }
233219 return err;
....@@ -253,9 +239,9 @@
253239 /* preserve the original iv for the final round */
254240 memcpy(buf, req->iv, AES_BLOCK_SIZE);
255241
256
- err = skcipher_walk_aead_encrypt(&walk, req, true);
242
+ err = skcipher_walk_aead_encrypt(&walk, req, false);
257243
258
- if (may_use_simd()) {
244
+ if (crypto_simd_usable()) {
259245 while (walk.nbytes) {
260246 u32 tail = walk.nbytes % AES_BLOCK_SIZE;
261247
....@@ -311,9 +297,9 @@
311297 /* preserve the original iv for the final round */
312298 memcpy(buf, req->iv, AES_BLOCK_SIZE);
313299
314
- err = skcipher_walk_aead_decrypt(&walk, req, true);
300
+ err = skcipher_walk_aead_decrypt(&walk, req, false);
315301
316
- if (may_use_simd()) {
302
+ if (crypto_simd_usable()) {
317303 while (walk.nbytes) {
318304 u32 tail = walk.nbytes % AES_BLOCK_SIZE;
319305
....@@ -372,7 +358,7 @@
372358
373359 static int __init aes_mod_init(void)
374360 {
375
- if (!(elf_hwcap & HWCAP_AES))
361
+ if (!cpu_have_named_feature(AES))
376362 return -ENODEV;
377363 return crypto_register_aead(&ccm_aes_alg);
378364 }