nh.h 816 B

12345678910111213141516171819202122232425262728293031323334
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * ARM64 accelerated implementation of NH
  4. *
  5. * Copyright 2018 Google LLC
  6. */
  7. #include <asm/hwcap.h>
  8. #include <asm/simd.h>
  9. #include <linux/cpufeature.h>
  10. static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
  11. asmlinkage void nh_neon(const u32 *key, const u8 *message, size_t message_len,
  12. __le64 hash[NH_NUM_PASSES]);
  13. static bool nh_arch(const u32 *key, const u8 *message, size_t message_len,
  14. __le64 hash[NH_NUM_PASSES])
  15. {
  16. if (static_branch_likely(&have_neon) && message_len >= 64 &&
  17. may_use_simd()) {
  18. scoped_ksimd()
  19. nh_neon(key, message, message_len, hash);
  20. return true;
  21. }
  22. return false;
  23. }
  24. #define nh_mod_init_arch nh_mod_init_arch
  25. static void nh_mod_init_arch(void)
  26. {
  27. if (cpu_have_named_feature(ASIMD))
  28. static_branch_enable(&have_neon);
  29. }