simd.h 1.9 KB

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