1
0

blake2b.h 991 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * BLAKE2b digest algorithm, NEON accelerated
  4. *
  5. * Copyright 2020 Google LLC
  6. */
  7. #include <asm/neon.h>
  8. #include <asm/simd.h>
  9. static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
  10. asmlinkage void blake2b_compress_neon(struct blake2b_ctx *ctx,
  11. const u8 *data, size_t nblocks, u32 inc);
  12. static void blake2b_compress(struct blake2b_ctx *ctx,
  13. const u8 *data, size_t nblocks, u32 inc)
  14. {
  15. if (!static_branch_likely(&have_neon) || !may_use_simd()) {
  16. blake2b_compress_generic(ctx, data, nblocks, inc);
  17. return;
  18. }
  19. do {
  20. const size_t blocks = min_t(size_t, nblocks,
  21. SZ_4K / BLAKE2B_BLOCK_SIZE);
  22. scoped_ksimd()
  23. blake2b_compress_neon(ctx, data, blocks, inc);
  24. data += blocks * BLAKE2B_BLOCK_SIZE;
  25. nblocks -= blocks;
  26. } while (nblocks);
  27. }
  28. #define blake2b_mod_init_arch blake2b_mod_init_arch
  29. static void blake2b_mod_init_arch(void)
  30. {
  31. if (elf_hwcap & HWCAP_NEON)
  32. static_branch_enable(&have_neon);
  33. }