| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Cryptographic API. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 11 | 12 | * Copyright (c) Jean-Francois Dive <jef@linuxbe.org> |
|---|
| 12 | 13 | * Copyright (c) Mathias Krause <minipli@googlemail.com> |
|---|
| 13 | 14 | * Copyright (c) Chandramouli Narayanan <mouli@linux.intel.com> |
|---|
| 14 | | - * |
|---|
| 15 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 16 | | - * under the terms of the GNU General Public License as published by the Free |
|---|
| 17 | | - * Software Foundation; either version 2 of the License, or (at your option) |
|---|
| 18 | | - * any later version. |
|---|
| 19 | | - * |
|---|
| 20 | 15 | */ |
|---|
| 21 | 16 | |
|---|
| 22 | 17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| 23 | 18 | |
|---|
| 24 | 19 | #include <crypto/internal/hash.h> |
|---|
| 20 | +#include <crypto/internal/simd.h> |
|---|
| 25 | 21 | #include <linux/init.h> |
|---|
| 26 | 22 | #include <linux/module.h> |
|---|
| 27 | 23 | #include <linux/mm.h> |
|---|
| 28 | | -#include <linux/cryptohash.h> |
|---|
| 29 | 24 | #include <linux/types.h> |
|---|
| 30 | 25 | #include <crypto/sha.h> |
|---|
| 31 | 26 | #include <crypto/sha1_base.h> |
|---|
| 32 | | -#include <asm/fpu/api.h> |
|---|
| 27 | +#include <asm/simd.h> |
|---|
| 33 | 28 | |
|---|
| 34 | 29 | static int sha1_update(struct shash_desc *desc, const u8 *data, |
|---|
| 35 | 30 | unsigned int len, sha1_block_fn *sha1_xform) |
|---|
| 36 | 31 | { |
|---|
| 37 | 32 | struct sha1_state *sctx = shash_desc_ctx(desc); |
|---|
| 38 | 33 | |
|---|
| 39 | | - if (!irq_fpu_usable() || |
|---|
| 34 | + if (!crypto_simd_usable() || |
|---|
| 40 | 35 | (sctx->count % SHA1_BLOCK_SIZE) + len < SHA1_BLOCK_SIZE) |
|---|
| 41 | 36 | return crypto_sha1_update(desc, data, len); |
|---|
| 42 | 37 | |
|---|
| .. | .. |
|---|
| 56 | 51 | static int sha1_finup(struct shash_desc *desc, const u8 *data, |
|---|
| 57 | 52 | unsigned int len, u8 *out, sha1_block_fn *sha1_xform) |
|---|
| 58 | 53 | { |
|---|
| 59 | | - if (!irq_fpu_usable()) |
|---|
| 54 | + if (!crypto_simd_usable()) |
|---|
| 60 | 55 | return crypto_sha1_finup(desc, data, len, out); |
|---|
| 61 | 56 | |
|---|
| 62 | 57 | kernel_fpu_begin(); |
|---|
| .. | .. |
|---|
| 118 | 113 | crypto_unregister_shash(&sha1_ssse3_alg); |
|---|
| 119 | 114 | } |
|---|
| 120 | 115 | |
|---|
| 121 | | -#ifdef CONFIG_AS_AVX |
|---|
| 122 | 116 | asmlinkage void sha1_transform_avx(struct sha1_state *state, |
|---|
| 123 | 117 | const u8 *data, int blocks); |
|---|
| 124 | 118 | |
|---|
| .. | .. |
|---|
| 179 | 173 | crypto_unregister_shash(&sha1_avx_alg); |
|---|
| 180 | 174 | } |
|---|
| 181 | 175 | |
|---|
| 182 | | -#else /* CONFIG_AS_AVX */ |
|---|
| 183 | | -static inline int register_sha1_avx(void) { return 0; } |
|---|
| 184 | | -static inline void unregister_sha1_avx(void) { } |
|---|
| 185 | | -#endif /* CONFIG_AS_AVX */ |
|---|
| 186 | | - |
|---|
| 187 | | - |
|---|
| 188 | | -#if defined(CONFIG_AS_AVX2) && (CONFIG_AS_AVX) |
|---|
| 189 | 176 | #define SHA1_AVX2_BLOCK_OPTSIZE 4 /* optimal 4*64 bytes of SHA1 blocks */ |
|---|
| 190 | 177 | |
|---|
| 191 | 178 | asmlinkage void sha1_transform_avx2(struct sha1_state *state, |
|---|
| .. | .. |
|---|
| 256 | 243 | if (avx2_usable()) |
|---|
| 257 | 244 | crypto_unregister_shash(&sha1_avx2_alg); |
|---|
| 258 | 245 | } |
|---|
| 259 | | - |
|---|
| 260 | | -#else |
|---|
| 261 | | -static inline int register_sha1_avx2(void) { return 0; } |
|---|
| 262 | | -static inline void unregister_sha1_avx2(void) { } |
|---|
| 263 | | -#endif |
|---|
| 264 | 246 | |
|---|
| 265 | 247 | #ifdef CONFIG_AS_SHA1_NI |
|---|
| 266 | 248 | asmlinkage void sha1_ni_transform(struct sha1_state *digest, const u8 *data, |
|---|