simd.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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(const char *algname,
  13. const char *drvname,
  14. const char *basename);
  15. struct simd_skcipher_alg *simd_skcipher_create(const char *algname,
  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. struct simd_aead_alg *simd_aead_create_compat(const char *algname,
  26. const char *drvname,
  27. const char *basename);
  28. struct simd_aead_alg *simd_aead_create(const char *algname,
  29. const char *basename);
  30. void simd_aead_free(struct simd_aead_alg *alg);
  31. int simd_register_aeads_compat(struct aead_alg *algs, int count,
  32. struct simd_aead_alg **simd_algs);
  33. void simd_unregister_aeads(struct aead_alg *algs, int count,
  34. struct simd_aead_alg **simd_algs);
  35. /*
  36. * crypto_simd_usable() - is it allowed at this time to use SIMD instructions or
  37. * access the SIMD register file?
  38. *
  39. * This delegates to may_use_simd(), except that this also returns false if SIMD
  40. * in crypto code has been temporarily disabled on this CPU by the crypto
  41. * self-tests, in order to test the no-SIMD fallback code. This override is
  42. * currently limited to configurations where the extra self-tests are enabled,
  43. * because it might be a bit too invasive to be part of the regular self-tests.
  44. *
  45. * This is a macro so that <asm/simd.h>, which some architectures don't have,
  46. * doesn't have to be included directly here.
  47. */
  48. #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
  49. DECLARE_PER_CPU(bool, crypto_simd_disabled_for_test);
  50. #define crypto_simd_usable() \
  51. (may_use_simd() && !this_cpu_read(crypto_simd_disabled_for_test))
  52. #else
  53. #define crypto_simd_usable() may_use_simd()
  54. #endif
  55. #endif /* _CRYPTO_INTERNAL_SIMD_H */