sha1_glue.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Cryptographic API.
  4. * Glue code for the SHA1 Secure Hash Algorithm assembler implementation
  5. *
  6. * This file is based on sha1_generic.c and sha1_ssse3_glue.c
  7. *
  8. * Copyright (c) Alan Smithee.
  9. * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
  10. * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
  11. * Copyright (c) Mathias Krause <minipli@googlemail.com>
  12. */
  13. #include <crypto/internal/hash.h>
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/types.h>
  17. #include <crypto/sha.h>
  18. #include <crypto/sha1_base.h>
  19. #include <asm/byteorder.h>
  20. #include "sha1.h"
  21. asmlinkage void sha1_block_data_order(u32 *digest,
  22. const unsigned char *data, unsigned int rounds);
  23. int sha1_update_arm(struct shash_desc *desc, const u8 *data,
  24. unsigned int len)
  25. {
  26. /* make sure casting to sha1_block_fn() is safe */
  27. BUILD_BUG_ON(offsetof(struct sha1_state, state) != 0);
  28. return sha1_base_do_update(desc, data, len,
  29. (sha1_block_fn *)sha1_block_data_order);
  30. }
  31. EXPORT_SYMBOL_GPL(sha1_update_arm);
  32. static int sha1_final(struct shash_desc *desc, u8 *out)
  33. {
  34. sha1_base_do_finalize(desc, (sha1_block_fn *)sha1_block_data_order);
  35. return sha1_base_finish(desc, out);
  36. }
  37. int sha1_finup_arm(struct shash_desc *desc, const u8 *data,
  38. unsigned int len, u8 *out)
  39. {
  40. sha1_base_do_update(desc, data, len,
  41. (sha1_block_fn *)sha1_block_data_order);
  42. return sha1_final(desc, out);
  43. }
  44. EXPORT_SYMBOL_GPL(sha1_finup_arm);
  45. static struct shash_alg alg = {
  46. .digestsize = SHA1_DIGEST_SIZE,
  47. .init = sha1_base_init,
  48. .update = sha1_update_arm,
  49. .final = sha1_final,
  50. .finup = sha1_finup_arm,
  51. .descsize = sizeof(struct sha1_state),
  52. .base = {
  53. .cra_name = "sha1",
  54. .cra_driver_name= "sha1-asm",
  55. .cra_priority = 150,
  56. .cra_blocksize = SHA1_BLOCK_SIZE,
  57. .cra_module = THIS_MODULE,
  58. }
  59. };
  60. static int __init sha1_mod_init(void)
  61. {
  62. return crypto_register_shash(&alg);
  63. }
  64. static void __exit sha1_mod_fini(void)
  65. {
  66. crypto_unregister_shash(&alg);
  67. }
  68. module_init(sha1_mod_init);
  69. module_exit(sha1_mod_fini);
  70. MODULE_LICENSE("GPL");
  71. MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm (ARM)");
  72. MODULE_ALIAS_CRYPTO("sha1");
  73. MODULE_AUTHOR("David McCullough <ucdevel@gmail.com>");