sha512-glue.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Linux/arm64 port of the OpenSSL SHA512 implementation for AArch64
  3. *
  4. * Copyright (c) 2016 Linaro Ltd. <ard.biesheuvel@linaro.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. */
  12. #include <crypto/internal/hash.h>
  13. #include <linux/cryptohash.h>
  14. #include <linux/types.h>
  15. #include <linux/string.h>
  16. #include <crypto/sha.h>
  17. #include <crypto/sha512_base.h>
  18. #include <asm/neon.h>
  19. MODULE_DESCRIPTION("SHA-384/SHA-512 secure hash for arm64");
  20. MODULE_AUTHOR("Andy Polyakov <appro@openssl.org>");
  21. MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
  22. MODULE_LICENSE("GPL v2");
  23. MODULE_ALIAS_CRYPTO("sha384");
  24. MODULE_ALIAS_CRYPTO("sha512");
  25. asmlinkage void sha512_block_data_order(u32 *digest, const void *data,
  26. unsigned int num_blks);
  27. static int sha512_update(struct shash_desc *desc, const u8 *data,
  28. unsigned int len)
  29. {
  30. return sha512_base_do_update(desc, data, len,
  31. (sha512_block_fn *)sha512_block_data_order);
  32. }
  33. static int sha512_finup(struct shash_desc *desc, const u8 *data,
  34. unsigned int len, u8 *out)
  35. {
  36. if (len)
  37. sha512_base_do_update(desc, data, len,
  38. (sha512_block_fn *)sha512_block_data_order);
  39. sha512_base_do_finalize(desc,
  40. (sha512_block_fn *)sha512_block_data_order);
  41. return sha512_base_finish(desc, out);
  42. }
  43. static int sha512_final(struct shash_desc *desc, u8 *out)
  44. {
  45. return sha512_finup(desc, NULL, 0, out);
  46. }
  47. static struct shash_alg algs[] = { {
  48. .digestsize = SHA512_DIGEST_SIZE,
  49. .init = sha512_base_init,
  50. .update = sha512_update,
  51. .final = sha512_final,
  52. .finup = sha512_finup,
  53. .descsize = sizeof(struct sha512_state),
  54. .base.cra_name = "sha512",
  55. .base.cra_driver_name = "sha512-arm64",
  56. .base.cra_priority = 150,
  57. .base.cra_flags = CRYPTO_ALG_TYPE_SHASH,
  58. .base.cra_blocksize = SHA512_BLOCK_SIZE,
  59. .base.cra_module = THIS_MODULE,
  60. }, {
  61. .digestsize = SHA384_DIGEST_SIZE,
  62. .init = sha384_base_init,
  63. .update = sha512_update,
  64. .final = sha512_final,
  65. .finup = sha512_finup,
  66. .descsize = sizeof(struct sha512_state),
  67. .base.cra_name = "sha384",
  68. .base.cra_driver_name = "sha384-arm64",
  69. .base.cra_priority = 150,
  70. .base.cra_flags = CRYPTO_ALG_TYPE_SHASH,
  71. .base.cra_blocksize = SHA384_BLOCK_SIZE,
  72. .base.cra_module = THIS_MODULE,
  73. } };
  74. static int __init sha512_mod_init(void)
  75. {
  76. return crypto_register_shashes(algs, ARRAY_SIZE(algs));
  77. }
  78. static void __exit sha512_mod_fini(void)
  79. {
  80. crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
  81. }
  82. module_init(sha512_mod_init);
  83. module_exit(sha512_mod_fini);