simd.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 <asm/simd.h>
  8. #include <linux/percpu.h>
  9. #include <linux/types.h>
  10. /* skcipher support */
  11. struct simd_skcipher_alg;
  12. struct skcipher_alg;
  13. struct simd_skcipher_alg *simd_skcipher_create_compat(struct skcipher_alg *ialg,
  14. const char *algname,
  15. const char *drvname,
  16. const char *basename);
  17. void simd_skcipher_free(struct simd_skcipher_alg *alg);
  18. int simd_register_skciphers_compat(struct skcipher_alg *algs, int count,
  19. struct simd_skcipher_alg **simd_algs);
  20. void simd_unregister_skciphers(struct skcipher_alg *algs, int count,
  21. struct simd_skcipher_alg **simd_algs);
  22. /* AEAD support */
  23. struct simd_aead_alg;
  24. struct aead_alg;
  25. int simd_register_aeads_compat(struct aead_alg *algs, int count,
  26. struct simd_aead_alg **simd_algs);
  27. void simd_unregister_aeads(struct aead_alg *algs, int count,
  28. struct simd_aead_alg **simd_algs);
  29. /*
  30. * crypto_simd_usable() - is it allowed at this time to use SIMD instructions or
  31. * access the SIMD register file?
  32. *
  33. * This delegates to may_use_simd(), except that this also returns false if SIMD
  34. * in crypto code has been temporarily disabled on this CPU by the crypto
  35. * self-tests, in order to test the no-SIMD fallback code. This override is
  36. * currently limited to configurations where the "full" self-tests are enabled,
  37. * because it might be a bit too invasive to be part of the "fast" self-tests.
  38. */
  39. #ifdef CONFIG_CRYPTO_SELFTESTS_FULL
  40. DECLARE_PER_CPU(bool, crypto_simd_disabled_for_test);
  41. #define crypto_simd_usable() \
  42. (may_use_simd() && !this_cpu_read(crypto_simd_disabled_for_test))
  43. #else
  44. #define crypto_simd_usable() may_use_simd()
  45. #endif
  46. #endif /* _CRYPTO_INTERNAL_SIMD_H */