sha1_s390.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Cryptographic API.
  3. *
  4. * s390 implementation of the SHA1 Secure Hash Algorithm.
  5. *
  6. * Derived from cryptoapi implementation, adapted for in-place
  7. * scatterlist interface. Originally based on the public domain
  8. * implementation written by Steve Reid.
  9. *
  10. * s390 Version:
  11. * Copyright IBM Corp. 2003,2007
  12. * Author(s): Thomas Spatzier
  13. * Jan Glauber (jan.glauber@de.ibm.com)
  14. *
  15. * Derived from "crypto/sha1_generic.c"
  16. * Copyright (c) Alan Smithee.
  17. * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
  18. * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
  19. *
  20. * This program is free software; you can redistribute it and/or modify it
  21. * under the terms of the GNU General Public License as published by the Free
  22. * Software Foundation; either version 2 of the License, or (at your option)
  23. * any later version.
  24. *
  25. */
  26. #include <crypto/internal/hash.h>
  27. #include <linux/init.h>
  28. #include <linux/module.h>
  29. #include <crypto/sha.h>
  30. #include "crypt_s390.h"
  31. #include "sha.h"
  32. static int sha1_init(struct shash_desc *desc)
  33. {
  34. struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
  35. sctx->state[0] = SHA1_H0;
  36. sctx->state[1] = SHA1_H1;
  37. sctx->state[2] = SHA1_H2;
  38. sctx->state[3] = SHA1_H3;
  39. sctx->state[4] = SHA1_H4;
  40. sctx->count = 0;
  41. sctx->func = KIMD_SHA_1;
  42. return 0;
  43. }
  44. static struct shash_alg alg = {
  45. .digestsize = SHA1_DIGEST_SIZE,
  46. .init = sha1_init,
  47. .update = s390_sha_update,
  48. .final = s390_sha_final,
  49. .descsize = sizeof(struct s390_sha_ctx),
  50. .base = {
  51. .cra_name = "sha1",
  52. .cra_driver_name= "sha1-s390",
  53. .cra_priority = CRYPT_S390_PRIORITY,
  54. .cra_flags = CRYPTO_ALG_TYPE_SHASH,
  55. .cra_blocksize = SHA1_BLOCK_SIZE,
  56. .cra_module = THIS_MODULE,
  57. }
  58. };
  59. static int __init sha1_s390_init(void)
  60. {
  61. if (!crypt_s390_func_available(KIMD_SHA_1))
  62. return -EOPNOTSUPP;
  63. return crypto_register_shash(&alg);
  64. }
  65. static void __exit sha1_s390_fini(void)
  66. {
  67. crypto_unregister_shash(&alg);
  68. }
  69. module_init(sha1_s390_init);
  70. module_exit(sha1_s390_fini);
  71. MODULE_ALIAS("sha1");
  72. MODULE_LICENSE("GPL");
  73. MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");