md5.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * MD5 accelerated using the sparc64 crypto opcodes
  4. *
  5. * Copyright (c) Alan Smithee.
  6. * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
  7. * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
  8. * Copyright (c) Mathias Krause <minipli@googlemail.com>
  9. * Copyright (c) Cryptoapi developers.
  10. * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  11. */
  12. #include <asm/elf.h>
  13. #include <asm/opcodes.h>
  14. #include <asm/pstate.h>
  15. static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_md5_opcodes);
  16. asmlinkage void md5_sparc64_transform(struct md5_block_state *state,
  17. const u8 *data, size_t nblocks);
  18. static void md5_blocks(struct md5_block_state *state,
  19. const u8 *data, size_t nblocks)
  20. {
  21. if (static_branch_likely(&have_md5_opcodes)) {
  22. cpu_to_le32_array(state->h, ARRAY_SIZE(state->h));
  23. md5_sparc64_transform(state, data, nblocks);
  24. le32_to_cpu_array(state->h, ARRAY_SIZE(state->h));
  25. } else {
  26. md5_blocks_generic(state, data, nblocks);
  27. }
  28. }
  29. #define md5_mod_init_arch md5_mod_init_arch
  30. static void md5_mod_init_arch(void)
  31. {
  32. unsigned long cfr;
  33. if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO))
  34. return;
  35. __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr));
  36. if (!(cfr & CFR_MD5))
  37. return;
  38. static_branch_enable(&have_md5_opcodes);
  39. pr_info("Using sparc64 md5 opcode optimized MD5 implementation\n");
  40. }