blob: d2316242a98843deed0128ef9470bcba3750caa0 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Herbert Xu266d0512016-11-22 20:08:25 +08002/*
3 * Shared crypto simd helpers
4 */
5
6#ifndef _CRYPTO_INTERNAL_SIMD_H
7#define _CRYPTO_INTERNAL_SIMD_H
8
Eric Biggersb55e1a32019-03-12 22:12:47 -07009#include <linux/percpu.h>
10#include <linux/types.h>
11
Eric Biggers16611312019-03-10 12:00:50 -070012/* skcipher support */
13
Herbert Xu266d0512016-11-22 20:08:25 +080014struct simd_skcipher_alg;
Eric Biggersd14f0a12018-02-19 23:47:59 -080015struct skcipher_alg;
Herbert Xu266d0512016-11-22 20:08:25 +080016
17struct simd_skcipher_alg *simd_skcipher_create_compat(const char *algname,
18 const char *drvname,
19 const char *basename);
20struct simd_skcipher_alg *simd_skcipher_create(const char *algname,
21 const char *basename);
22void simd_skcipher_free(struct simd_skcipher_alg *alg);
23
Eric Biggersd14f0a12018-02-19 23:47:59 -080024int simd_register_skciphers_compat(struct skcipher_alg *algs, int count,
25 struct simd_skcipher_alg **simd_algs);
26
27void simd_unregister_skciphers(struct skcipher_alg *algs, int count,
28 struct simd_skcipher_alg **simd_algs);
29
Eric Biggers16611312019-03-10 12:00:50 -070030/* AEAD support */
31
32struct simd_aead_alg;
33struct aead_alg;
34
35struct simd_aead_alg *simd_aead_create_compat(const char *algname,
36 const char *drvname,
37 const char *basename);
38struct simd_aead_alg *simd_aead_create(const char *algname,
39 const char *basename);
40void simd_aead_free(struct simd_aead_alg *alg);
41
42int simd_register_aeads_compat(struct aead_alg *algs, int count,
43 struct simd_aead_alg **simd_algs);
44
45void simd_unregister_aeads(struct aead_alg *algs, int count,
46 struct simd_aead_alg **simd_algs);
47
Eric Biggersb55e1a32019-03-12 22:12:47 -070048/*
49 * crypto_simd_usable() - is it allowed at this time to use SIMD instructions or
50 * access the SIMD register file?
51 *
52 * This delegates to may_use_simd(), except that this also returns false if SIMD
53 * in crypto code has been temporarily disabled on this CPU by the crypto
54 * self-tests, in order to test the no-SIMD fallback code. This override is
55 * currently limited to configurations where the extra self-tests are enabled,
56 * because it might be a bit too invasive to be part of the regular self-tests.
57 *
58 * This is a macro so that <asm/simd.h>, which some architectures don't have,
59 * doesn't have to be included directly here.
60 */
61#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
62DECLARE_PER_CPU(bool, crypto_simd_disabled_for_test);
63#define crypto_simd_usable() \
64 (may_use_simd() && !this_cpu_read(crypto_simd_disabled_for_test))
65#else
66#define crypto_simd_usable() may_use_simd()
67#endif
68
Herbert Xu266d0512016-11-22 20:08:25 +080069#endif /* _CRYPTO_INTERNAL_SIMD_H */