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