sha1_glue.c 2.4 KB

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