sm3-ce-glue.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * sm3-ce-glue.c - SM3 secure hash using ARMv8.2 Crypto Extensions
  4. *
  5. * Copyright (C) 2018 Linaro Ltd <ard.biesheuvel@linaro.org>
  6. */
  7. #include <crypto/internal/hash.h>
  8. #include <crypto/sm3.h>
  9. #include <crypto/sm3_base.h>
  10. #include <linux/cpufeature.h>
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <asm/simd.h>
  14. MODULE_DESCRIPTION("SM3 secure hash using ARMv8 Crypto Extensions");
  15. MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
  16. MODULE_LICENSE("GPL v2");
  17. asmlinkage void sm3_ce_transform(struct sm3_state *sst, u8 const *src,
  18. int blocks);
  19. static int sm3_ce_update(struct shash_desc *desc, const u8 *data,
  20. unsigned int len)
  21. {
  22. int remain;
  23. scoped_ksimd() {
  24. remain = sm3_base_do_update_blocks(desc, data, len, sm3_ce_transform);
  25. }
  26. return remain;
  27. }
  28. static int sm3_ce_finup(struct shash_desc *desc, const u8 *data,
  29. unsigned int len, u8 *out)
  30. {
  31. scoped_ksimd() {
  32. sm3_base_do_finup(desc, data, len, sm3_ce_transform);
  33. }
  34. return sm3_base_finish(desc, out);
  35. }
  36. static struct shash_alg sm3_alg = {
  37. .digestsize = SM3_DIGEST_SIZE,
  38. .init = sm3_base_init,
  39. .update = sm3_ce_update,
  40. .finup = sm3_ce_finup,
  41. .descsize = SM3_STATE_SIZE,
  42. .base.cra_name = "sm3",
  43. .base.cra_driver_name = "sm3-ce",
  44. .base.cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY |
  45. CRYPTO_AHASH_ALG_FINUP_MAX,
  46. .base.cra_blocksize = SM3_BLOCK_SIZE,
  47. .base.cra_module = THIS_MODULE,
  48. .base.cra_priority = 400,
  49. };
  50. static int __init sm3_ce_mod_init(void)
  51. {
  52. return crypto_register_shash(&sm3_alg);
  53. }
  54. static void __exit sm3_ce_mod_fini(void)
  55. {
  56. crypto_unregister_shash(&sm3_alg);
  57. }
  58. module_cpu_feature_match(SM3, sm3_ce_mod_init);
  59. module_exit(sm3_ce_mod_fini);