sha512-neon-glue.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * sha512-neon-glue.c - accelerated SHA-384/512 for ARM NEON
  3. *
  4. * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <crypto/internal/hash.h>
  11. #include <crypto/sha.h>
  12. #include <crypto/sha512_base.h>
  13. #include <linux/crypto.h>
  14. #include <linux/module.h>
  15. #include <asm/simd.h>
  16. #include <asm/neon.h>
  17. #include "sha512.h"
  18. MODULE_ALIAS_CRYPTO("sha384-neon");
  19. MODULE_ALIAS_CRYPTO("sha512-neon");
  20. asmlinkage void sha512_block_data_order_neon(u64 *state, u8 const *src,
  21. int blocks);
  22. static int sha512_neon_update(struct shash_desc *desc, const u8 *data,
  23. unsigned int len)
  24. {
  25. struct sha512_state *sctx = shash_desc_ctx(desc);
  26. if (!may_use_simd() ||
  27. (sctx->count[0] % SHA512_BLOCK_SIZE) + len < SHA512_BLOCK_SIZE)
  28. return sha512_arm_update(desc, data, len);
  29. kernel_neon_begin();
  30. sha512_base_do_update(desc, data, len,
  31. (sha512_block_fn *)sha512_block_data_order_neon);
  32. kernel_neon_end();
  33. return 0;
  34. }
  35. static int sha512_neon_finup(struct shash_desc *desc, const u8 *data,
  36. unsigned int len, u8 *out)
  37. {
  38. if (!may_use_simd())
  39. return sha512_arm_finup(desc, data, len, out);
  40. kernel_neon_begin();
  41. if (len)
  42. sha512_base_do_update(desc, data, len,
  43. (sha512_block_fn *)sha512_block_data_order_neon);
  44. sha512_base_do_finalize(desc,
  45. (sha512_block_fn *)sha512_block_data_order_neon);
  46. kernel_neon_end();
  47. return sha512_base_finish(desc, out);
  48. }
  49. static int sha512_neon_final(struct shash_desc *desc, u8 *out)
  50. {
  51. return sha512_neon_finup(desc, NULL, 0, out);
  52. }
  53. struct shash_alg sha512_neon_algs[] = { {
  54. .init = sha384_base_init,
  55. .update = sha512_neon_update,
  56. .final = sha512_neon_final,
  57. .finup = sha512_neon_finup,
  58. .descsize = sizeof(struct sha512_state),
  59. .digestsize = SHA384_DIGEST_SIZE,
  60. .base = {
  61. .cra_name = "sha384",
  62. .cra_driver_name = "sha384-neon",
  63. .cra_priority = 300,
  64. .cra_flags = CRYPTO_ALG_TYPE_SHASH,
  65. .cra_blocksize = SHA384_BLOCK_SIZE,
  66. .cra_module = THIS_MODULE,
  67. }
  68. }, {
  69. .init = sha512_base_init,
  70. .update = sha512_neon_update,
  71. .final = sha512_neon_final,
  72. .finup = sha512_neon_finup,
  73. .descsize = sizeof(struct sha512_state),
  74. .digestsize = SHA512_DIGEST_SIZE,
  75. .base = {
  76. .cra_name = "sha512",
  77. .cra_driver_name = "sha512-neon",
  78. .cra_priority = 300,
  79. .cra_flags = CRYPTO_ALG_TYPE_SHASH,
  80. .cra_blocksize = SHA512_BLOCK_SIZE,
  81. .cra_module = THIS_MODULE,
  82. }
  83. } };