Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Shared crypto simd helpers
0004  */
0005 
0006 #ifndef _CRYPTO_INTERNAL_SIMD_H
0007 #define _CRYPTO_INTERNAL_SIMD_H
0008 
0009 #include <linux/percpu.h>
0010 #include <linux/types.h>
0011 
0012 /* skcipher support */
0013 
0014 struct simd_skcipher_alg;
0015 struct skcipher_alg;
0016 
0017 struct simd_skcipher_alg *simd_skcipher_create_compat(const char *algname,
0018                               const char *drvname,
0019                               const char *basename);
0020 struct simd_skcipher_alg *simd_skcipher_create(const char *algname,
0021                            const char *basename);
0022 void simd_skcipher_free(struct simd_skcipher_alg *alg);
0023 
0024 int simd_register_skciphers_compat(struct skcipher_alg *algs, int count,
0025                    struct simd_skcipher_alg **simd_algs);
0026 
0027 void simd_unregister_skciphers(struct skcipher_alg *algs, int count,
0028                    struct simd_skcipher_alg **simd_algs);
0029 
0030 /* AEAD support */
0031 
0032 struct simd_aead_alg;
0033 struct aead_alg;
0034 
0035 struct simd_aead_alg *simd_aead_create_compat(const char *algname,
0036                           const char *drvname,
0037                           const char *basename);
0038 struct simd_aead_alg *simd_aead_create(const char *algname,
0039                        const char *basename);
0040 void simd_aead_free(struct simd_aead_alg *alg);
0041 
0042 int simd_register_aeads_compat(struct aead_alg *algs, int count,
0043                    struct simd_aead_alg **simd_algs);
0044 
0045 void simd_unregister_aeads(struct aead_alg *algs, int count,
0046                struct simd_aead_alg **simd_algs);
0047 
0048 /*
0049  * crypto_simd_usable() - is it allowed at this time to use SIMD instructions or
0050  *            access the SIMD register file?
0051  *
0052  * This delegates to may_use_simd(), except that this also returns false if SIMD
0053  * in crypto code has been temporarily disabled on this CPU by the crypto
0054  * self-tests, in order to test the no-SIMD fallback code.  This override is
0055  * currently limited to configurations where the extra self-tests are enabled,
0056  * because it might be a bit too invasive to be part of the regular self-tests.
0057  *
0058  * This is a macro so that <asm/simd.h>, which some architectures don't have,
0059  * doesn't have to be included directly here.
0060  */
0061 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
0062 DECLARE_PER_CPU(bool, crypto_simd_disabled_for_test);
0063 #define crypto_simd_usable() \
0064     (may_use_simd() && !this_cpu_read(crypto_simd_disabled_for_test))
0065 #else
0066 #define crypto_simd_usable() may_use_simd()
0067 #endif
0068 
0069 #endif /* _CRYPTO_INTERNAL_SIMD_H */