sha512-glue.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * sha512-glue.c - accelerated SHA-384/512 for ARM
  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/hwcap.h>
  16. #include <asm/neon.h>
  17. #include "sha512.h"
  18. MODULE_DESCRIPTION("Accelerated SHA-384/SHA-512 secure hash for ARM");
  19. MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
  20. MODULE_LICENSE("GPL v2");
  21. MODULE_ALIAS_CRYPTO("sha384");
  22. MODULE_ALIAS_CRYPTO("sha512");
  23. MODULE_ALIAS_CRYPTO("sha384-arm");
  24. MODULE_ALIAS_CRYPTO("sha512-arm");
  25. asmlinkage void sha512_block_data_order(u64 *state, u8 const *src, int blocks);
  26. int sha512_arm_update(struct shash_desc *desc, const u8 *data,
  27. unsigned int len)
  28. {
  29. return sha512_base_do_update(desc, data, len,
  30. (sha512_block_fn *)sha512_block_data_order);
  31. }
  32. int sha512_arm_final(struct shash_desc *desc, u8 *out)
  33. {
  34. sha512_base_do_finalize(desc,
  35. (sha512_block_fn *)sha512_block_data_order);
  36. return sha512_base_finish(desc, out);
  37. }
  38. int sha512_arm_finup(struct shash_desc *desc, const u8 *data,
  39. unsigned int len, u8 *out)
  40. {
  41. sha512_base_do_update(desc, data, len,
  42. (sha512_block_fn *)sha512_block_data_order);
  43. return sha512_arm_final(desc, out);
  44. }
  45. static struct shash_alg sha512_arm_algs[] = { {
  46. .init = sha384_base_init,
  47. .update = sha512_arm_update,
  48. .final = sha512_arm_final,
  49. .finup = sha512_arm_finup,
  50. .descsize = sizeof(struct sha512_state),
  51. .digestsize = SHA384_DIGEST_SIZE,
  52. .base = {
  53. .cra_name = "sha384",
  54. .cra_driver_name = "sha384-arm",
  55. .cra_priority = 250,
  56. .cra_flags = CRYPTO_ALG_TYPE_SHASH,
  57. .cra_blocksize = SHA512_BLOCK_SIZE,
  58. .cra_module = THIS_MODULE,
  59. }
  60. }, {
  61. .init = sha512_base_init,
  62. .update = sha512_arm_update,
  63. .final = sha512_arm_final,
  64. .finup = sha512_arm_finup,
  65. .descsize = sizeof(struct sha512_state),
  66. .digestsize = SHA512_DIGEST_SIZE,
  67. .base = {
  68. .cra_name = "sha512",
  69. .cra_driver_name = "sha512-arm",
  70. .cra_priority = 250,
  71. .cra_flags = CRYPTO_ALG_TYPE_SHASH,
  72. .cra_blocksize = SHA512_BLOCK_SIZE,
  73. .cra_module = THIS_MODULE,
  74. }
  75. } };
  76. static int __init sha512_arm_mod_init(void)
  77. {
  78. int err;
  79. err = crypto_register_shashes(sha512_arm_algs,
  80. ARRAY_SIZE(sha512_arm_algs));
  81. if (err)
  82. return err;
  83. if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && cpu_has_neon()) {
  84. err = crypto_register_shashes(sha512_neon_algs,
  85. ARRAY_SIZE(sha512_neon_algs));
  86. if (err)
  87. goto err_unregister;
  88. }
  89. return 0;
  90. err_unregister:
  91. crypto_unregister_shashes(sha512_arm_algs,
  92. ARRAY_SIZE(sha512_arm_algs));
  93. return err;
  94. }
  95. static void __exit sha512_arm_mod_fini(void)
  96. {
  97. crypto_unregister_shashes(sha512_arm_algs,
  98. ARRAY_SIZE(sha512_arm_algs));
  99. if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && cpu_has_neon())
  100. crypto_unregister_shashes(sha512_neon_algs,
  101. ARRAY_SIZE(sha512_neon_algs));
  102. }
  103. module_init(sha512_arm_mod_init);
  104. module_exit(sha512_arm_mod_fini);