.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Accelerated GHASH implementation with Intel PCLMULQDQ-NI |
---|
3 | 4 | * instructions. This file contains glue code. |
---|
4 | 5 | * |
---|
5 | 6 | * Copyright (c) 2009 Intel Corp. |
---|
6 | 7 | * 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. |
---|
11 | 8 | */ |
---|
12 | 9 | |
---|
13 | 10 | #include <linux/err.h> |
---|
.. | .. |
---|
19 | 16 | #include <crypto/cryptd.h> |
---|
20 | 17 | #include <crypto/gf128mul.h> |
---|
21 | 18 | #include <crypto/internal/hash.h> |
---|
22 | | -#include <asm/fpu/api.h> |
---|
| 19 | +#include <crypto/internal/simd.h> |
---|
23 | 20 | #include <asm/cpu_device_id.h> |
---|
| 21 | +#include <asm/simd.h> |
---|
24 | 22 | |
---|
25 | 23 | #define GHASH_BLOCK_SIZE 16 |
---|
26 | 24 | #define GHASH_DIGEST_SIZE 16 |
---|
.. | .. |
---|
59 | 57 | be128 *x = (be128 *)key; |
---|
60 | 58 | u64 a, b; |
---|
61 | 59 | |
---|
62 | | - if (keylen != GHASH_BLOCK_SIZE) { |
---|
63 | | - crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); |
---|
| 60 | + if (keylen != GHASH_BLOCK_SIZE) |
---|
64 | 61 | return -EINVAL; |
---|
65 | | - } |
---|
66 | 62 | |
---|
67 | 63 | /* perform multiplication by 'x' in GF(2^128) */ |
---|
68 | 64 | a = be64_to_cpu(x->a); |
---|
.. | .. |
---|
171 | 167 | struct crypto_shash *child = cryptd_ahash_child(cryptd_tfm); |
---|
172 | 168 | |
---|
173 | 169 | desc->tfm = child; |
---|
174 | | - desc->flags = req->base.flags; |
---|
175 | 170 | return crypto_shash_init(desc); |
---|
176 | 171 | } |
---|
177 | 172 | |
---|
.. | .. |
---|
182 | 177 | struct ghash_async_ctx *ctx = crypto_ahash_ctx(tfm); |
---|
183 | 178 | struct cryptd_ahash *cryptd_tfm = ctx->cryptd_tfm; |
---|
184 | 179 | |
---|
185 | | - if (!irq_fpu_usable() || |
---|
| 180 | + if (!crypto_simd_usable() || |
---|
186 | 181 | (in_atomic() && cryptd_ahash_queued(cryptd_tfm))) { |
---|
187 | 182 | memcpy(cryptd_req, req, sizeof(*req)); |
---|
188 | 183 | ahash_request_set_tfm(cryptd_req, &cryptd_tfm->base); |
---|
.. | .. |
---|
200 | 195 | struct ghash_async_ctx *ctx = crypto_ahash_ctx(tfm); |
---|
201 | 196 | struct cryptd_ahash *cryptd_tfm = ctx->cryptd_tfm; |
---|
202 | 197 | |
---|
203 | | - if (!irq_fpu_usable() || |
---|
| 198 | + if (!crypto_simd_usable() || |
---|
204 | 199 | (in_atomic() && cryptd_ahash_queued(cryptd_tfm))) { |
---|
205 | 200 | memcpy(cryptd_req, req, sizeof(*req)); |
---|
206 | 201 | ahash_request_set_tfm(cryptd_req, &cryptd_tfm->base); |
---|
.. | .. |
---|
241 | 236 | struct ahash_request *cryptd_req = ahash_request_ctx(req); |
---|
242 | 237 | struct cryptd_ahash *cryptd_tfm = ctx->cryptd_tfm; |
---|
243 | 238 | |
---|
244 | | - if (!irq_fpu_usable() || |
---|
| 239 | + if (!crypto_simd_usable() || |
---|
245 | 240 | (in_atomic() && cryptd_ahash_queued(cryptd_tfm))) { |
---|
246 | 241 | memcpy(cryptd_req, req, sizeof(*req)); |
---|
247 | 242 | ahash_request_set_tfm(cryptd_req, &cryptd_tfm->base); |
---|
.. | .. |
---|
251 | 246 | struct crypto_shash *child = cryptd_ahash_child(cryptd_tfm); |
---|
252 | 247 | |
---|
253 | 248 | desc->tfm = child; |
---|
254 | | - desc->flags = req->base.flags; |
---|
255 | 249 | return shash_ahash_digest(req, desc); |
---|
256 | 250 | } |
---|
257 | 251 | } |
---|
.. | .. |
---|
261 | 255 | { |
---|
262 | 256 | struct ghash_async_ctx *ctx = crypto_ahash_ctx(tfm); |
---|
263 | 257 | struct crypto_ahash *child = &ctx->cryptd_tfm->base; |
---|
264 | | - int err; |
---|
265 | 258 | |
---|
266 | 259 | crypto_ahash_clear_flags(child, CRYPTO_TFM_REQ_MASK); |
---|
267 | 260 | crypto_ahash_set_flags(child, crypto_ahash_get_flags(tfm) |
---|
268 | 261 | & 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); |
---|
274 | 263 | } |
---|
275 | 264 | |
---|
276 | 265 | static int ghash_async_init_tfm(struct crypto_tfm *tfm) |
---|
.. | .. |
---|
324 | 313 | }; |
---|
325 | 314 | |
---|
326 | 315 | 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 */ |
---|
328 | 317 | {} |
---|
329 | 318 | }; |
---|
330 | 319 | MODULE_DEVICE_TABLE(x86cpu, pcmul_cpu_id); |
---|
.. | .. |
---|
361 | 350 | module_exit(ghash_pclmulqdqni_mod_exit); |
---|
362 | 351 | |
---|
363 | 352 | 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"); |
---|
366 | 354 | MODULE_ALIAS_CRYPTO("ghash"); |
---|