1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2266d0516SHerbert Xu /* 3266d0516SHerbert Xu * Shared crypto simd helpers 4266d0516SHerbert Xu */ 5266d0516SHerbert Xu 6266d0516SHerbert Xu #ifndef _CRYPTO_INTERNAL_SIMD_H 7266d0516SHerbert Xu #define _CRYPTO_INTERNAL_SIMD_H 8266d0516SHerbert Xu 9b55e1a39SEric Biggers #include <linux/percpu.h> 10b55e1a39SEric Biggers #include <linux/types.h> 11b55e1a39SEric Biggers 121661131aSEric Biggers /* skcipher support */ 131661131aSEric Biggers 14266d0516SHerbert Xu struct simd_skcipher_alg; 15d14f0a1fSEric Biggers struct skcipher_alg; 16266d0516SHerbert Xu 17*b60d2bc6SHerbert Xu struct simd_skcipher_alg *simd_skcipher_create_compat(struct skcipher_alg *ialg, 18*b60d2bc6SHerbert Xu const char *algname, 19266d0516SHerbert Xu const char *drvname, 20266d0516SHerbert Xu const char *basename); 21266d0516SHerbert Xu void simd_skcipher_free(struct simd_skcipher_alg *alg); 22266d0516SHerbert Xu 23d14f0a1fSEric Biggers int simd_register_skciphers_compat(struct skcipher_alg *algs, int count, 24d14f0a1fSEric Biggers struct simd_skcipher_alg **simd_algs); 25d14f0a1fSEric Biggers 26d14f0a1fSEric Biggers void simd_unregister_skciphers(struct skcipher_alg *algs, int count, 27d14f0a1fSEric Biggers struct simd_skcipher_alg **simd_algs); 28d14f0a1fSEric Biggers 291661131aSEric Biggers /* AEAD support */ 301661131aSEric Biggers 311661131aSEric Biggers struct simd_aead_alg; 321661131aSEric Biggers struct aead_alg; 331661131aSEric Biggers 341661131aSEric Biggers int simd_register_aeads_compat(struct aead_alg *algs, int count, 351661131aSEric Biggers struct simd_aead_alg **simd_algs); 361661131aSEric Biggers 371661131aSEric Biggers void simd_unregister_aeads(struct aead_alg *algs, int count, 381661131aSEric Biggers struct simd_aead_alg **simd_algs); 391661131aSEric Biggers 40b55e1a39SEric Biggers /* 41b55e1a39SEric Biggers * crypto_simd_usable() - is it allowed at this time to use SIMD instructions or 42b55e1a39SEric Biggers * access the SIMD register file? 43b55e1a39SEric Biggers * 44b55e1a39SEric Biggers * This delegates to may_use_simd(), except that this also returns false if SIMD 45b55e1a39SEric Biggers * in crypto code has been temporarily disabled on this CPU by the crypto 46b55e1a39SEric Biggers * self-tests, in order to test the no-SIMD fallback code. This override is 47b55e1a39SEric Biggers * currently limited to configurations where the extra self-tests are enabled, 48b55e1a39SEric Biggers * because it might be a bit too invasive to be part of the regular self-tests. 49b55e1a39SEric Biggers * 50b55e1a39SEric Biggers * This is a macro so that <asm/simd.h>, which some architectures don't have, 51b55e1a39SEric Biggers * doesn't have to be included directly here. 52b55e1a39SEric Biggers */ 53b55e1a39SEric Biggers #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS 54b55e1a39SEric Biggers DECLARE_PER_CPU(bool, crypto_simd_disabled_for_test); 55b55e1a39SEric Biggers #define crypto_simd_usable() \ 56b55e1a39SEric Biggers (may_use_simd() && !this_cpu_read(crypto_simd_disabled_for_test)) 57b55e1a39SEric Biggers #else 58b55e1a39SEric Biggers #define crypto_simd_usable() may_use_simd() 59b55e1a39SEric Biggers #endif 60b55e1a39SEric Biggers 61266d0516SHerbert Xu #endif /* _CRYPTO_INTERNAL_SIMD_H */ 62