hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/arch/x86/crypto/ghash-clmulni-intel_glue.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Accelerated GHASH implementation with Intel PCLMULQDQ-NI
34 * instructions. This file contains glue code.
45 *
56 * Copyright (c) 2009 Intel Corp.
67 * Author: Huang Ying <ying.huang@intel.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify it
9
- * under the terms of the GNU General Public License version 2 as published
10
- * by the Free Software Foundation.
118 */
129
1310 #include <linux/err.h>
....@@ -19,8 +16,9 @@
1916 #include <crypto/cryptd.h>
2017 #include <crypto/gf128mul.h>
2118 #include <crypto/internal/hash.h>
22
-#include <asm/fpu/api.h>
19
+#include <crypto/internal/simd.h>
2320 #include <asm/cpu_device_id.h>
21
+#include <asm/simd.h>
2422
2523 #define GHASH_BLOCK_SIZE 16
2624 #define GHASH_DIGEST_SIZE 16
....@@ -59,10 +57,8 @@
5957 be128 *x = (be128 *)key;
6058 u64 a, b;
6159
62
- if (keylen != GHASH_BLOCK_SIZE) {
63
- crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
60
+ if (keylen != GHASH_BLOCK_SIZE)
6461 return -EINVAL;
65
- }
6662
6763 /* perform multiplication by 'x' in GF(2^128) */
6864 a = be64_to_cpu(x->a);
....@@ -171,7 +167,6 @@
171167 struct crypto_shash *child = cryptd_ahash_child(cryptd_tfm);
172168
173169 desc->tfm = child;
174
- desc->flags = req->base.flags;
175170 return crypto_shash_init(desc);
176171 }
177172
....@@ -182,7 +177,7 @@
182177 struct ghash_async_ctx *ctx = crypto_ahash_ctx(tfm);
183178 struct cryptd_ahash *cryptd_tfm = ctx->cryptd_tfm;
184179
185
- if (!irq_fpu_usable() ||
180
+ if (!crypto_simd_usable() ||
186181 (in_atomic() && cryptd_ahash_queued(cryptd_tfm))) {
187182 memcpy(cryptd_req, req, sizeof(*req));
188183 ahash_request_set_tfm(cryptd_req, &cryptd_tfm->base);
....@@ -200,7 +195,7 @@
200195 struct ghash_async_ctx *ctx = crypto_ahash_ctx(tfm);
201196 struct cryptd_ahash *cryptd_tfm = ctx->cryptd_tfm;
202197
203
- if (!irq_fpu_usable() ||
198
+ if (!crypto_simd_usable() ||
204199 (in_atomic() && cryptd_ahash_queued(cryptd_tfm))) {
205200 memcpy(cryptd_req, req, sizeof(*req));
206201 ahash_request_set_tfm(cryptd_req, &cryptd_tfm->base);
....@@ -241,7 +236,7 @@
241236 struct ahash_request *cryptd_req = ahash_request_ctx(req);
242237 struct cryptd_ahash *cryptd_tfm = ctx->cryptd_tfm;
243238
244
- if (!irq_fpu_usable() ||
239
+ if (!crypto_simd_usable() ||
245240 (in_atomic() && cryptd_ahash_queued(cryptd_tfm))) {
246241 memcpy(cryptd_req, req, sizeof(*req));
247242 ahash_request_set_tfm(cryptd_req, &cryptd_tfm->base);
....@@ -251,7 +246,6 @@
251246 struct crypto_shash *child = cryptd_ahash_child(cryptd_tfm);
252247
253248 desc->tfm = child;
254
- desc->flags = req->base.flags;
255249 return shash_ahash_digest(req, desc);
256250 }
257251 }
....@@ -261,16 +255,11 @@
261255 {
262256 struct ghash_async_ctx *ctx = crypto_ahash_ctx(tfm);
263257 struct crypto_ahash *child = &ctx->cryptd_tfm->base;
264
- int err;
265258
266259 crypto_ahash_clear_flags(child, CRYPTO_TFM_REQ_MASK);
267260 crypto_ahash_set_flags(child, crypto_ahash_get_flags(tfm)
268261 & CRYPTO_TFM_REQ_MASK);
269
- err = crypto_ahash_setkey(child, key, keylen);
270
- crypto_ahash_set_flags(tfm, crypto_ahash_get_flags(child)
271
- & CRYPTO_TFM_RES_MASK);
272
-
273
- return err;
262
+ return crypto_ahash_setkey(child, key, keylen);
274263 }
275264
276265 static int ghash_async_init_tfm(struct crypto_tfm *tfm)
....@@ -324,7 +313,7 @@
324313 };
325314
326315 static const struct x86_cpu_id pcmul_cpu_id[] = {
327
- X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ), /* Pickle-Mickle-Duck */
316
+ X86_MATCH_FEATURE(X86_FEATURE_PCLMULQDQ, NULL), /* Pickle-Mickle-Duck */
328317 {}
329318 };
330319 MODULE_DEVICE_TABLE(x86cpu, pcmul_cpu_id);
....@@ -361,6 +350,5 @@
361350 module_exit(ghash_pclmulqdqni_mod_exit);
362351
363352 MODULE_LICENSE("GPL");
364
-MODULE_DESCRIPTION("GHASH Message Digest Algorithm, "
365
- "accelerated by PCLMULQDQ-NI");
353
+MODULE_DESCRIPTION("GHASH hash function, accelerated by PCLMULQDQ-NI");
366354 MODULE_ALIAS_CRYPTO("ghash");