sha512.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * arm64-optimized SHA-512 block function
  4. *
  5. * Copyright 2025 Google LLC
  6. */
  7. #include <asm/simd.h>
  8. #include <linux/cpufeature.h>
  9. static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_sha512_insns);
  10. asmlinkage void sha512_block_data_order(struct sha512_block_state *state,
  11. const u8 *data, size_t nblocks);
  12. asmlinkage size_t __sha512_ce_transform(struct sha512_block_state *state,
  13. const u8 *data, size_t nblocks);
  14. static void sha512_blocks(struct sha512_block_state *state,
  15. const u8 *data, size_t nblocks)
  16. {
  17. if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) &&
  18. static_branch_likely(&have_sha512_insns) &&
  19. likely(may_use_simd())) {
  20. do {
  21. size_t rem;
  22. scoped_ksimd()
  23. rem = __sha512_ce_transform(state, data, nblocks);
  24. data += (nblocks - rem) * SHA512_BLOCK_SIZE;
  25. nblocks = rem;
  26. } while (nblocks);
  27. } else {
  28. sha512_block_data_order(state, data, nblocks);
  29. }
  30. }
  31. #ifdef CONFIG_KERNEL_MODE_NEON
  32. #define sha512_mod_init_arch sha512_mod_init_arch
  33. static void sha512_mod_init_arch(void)
  34. {
  35. if (cpu_have_named_feature(SHA512))
  36. static_branch_enable(&have_sha512_insns);
  37. }
  38. #endif /* CONFIG_KERNEL_MODE_NEON */