sha1_s390.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 <linux/cpufeature.h>
  30. #include <crypto/sha.h>
  31. #include <asm/cpacf.h>
  32. #include "sha.h"
  33. static int sha1_init(struct shash_desc *desc)
  34. {
  35. struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
  36. sctx->state[0] = SHA1_H0;
  37. sctx->state[1] = SHA1_H1;
  38. sctx->state[2] = SHA1_H2;
  39. sctx->state[3] = SHA1_H3;
  40. sctx->state[4] = SHA1_H4;
  41. sctx->count = 0;
  42. sctx->func = CPACF_KIMD_SHA_1;
  43. return 0;
  44. }
  45. static int sha1_export(struct shash_desc *desc, void *out)
  46. {
  47. struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
  48. struct sha1_state *octx = out;
  49. octx->count = sctx->count;
  50. memcpy(octx->state, sctx->state, sizeof(octx->state));
  51. memcpy(octx->buffer, sctx->buf, sizeof(octx->buffer));
  52. return 0;
  53. }
  54. static int sha1_import(struct shash_desc *desc, const void *in)
  55. {
  56. struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
  57. const struct sha1_state *ictx = in;
  58. sctx->count = ictx->count;
  59. memcpy(sctx->state, ictx->state, sizeof(ictx->state));
  60. memcpy(sctx->buf, ictx->buffer, sizeof(ictx->buffer));
  61. sctx->func = CPACF_KIMD_SHA_1;
  62. return 0;
  63. }
  64. static struct shash_alg alg = {
  65. .digestsize = SHA1_DIGEST_SIZE,
  66. .init = sha1_init,
  67. .update = s390_sha_update,
  68. .final = s390_sha_final,
  69. .export = sha1_export,
  70. .import = sha1_import,
  71. .descsize = sizeof(struct s390_sha_ctx),
  72. .statesize = sizeof(struct sha1_state),
  73. .base = {
  74. .cra_name = "sha1",
  75. .cra_driver_name= "sha1-s390",
  76. .cra_priority = 300,
  77. .cra_flags = CRYPTO_ALG_TYPE_SHASH,
  78. .cra_blocksize = SHA1_BLOCK_SIZE,
  79. .cra_module = THIS_MODULE,
  80. }
  81. };
  82. static int __init sha1_s390_init(void)
  83. {
  84. if (!cpacf_query_func(CPACF_KIMD, CPACF_KIMD_SHA_1))
  85. return -EOPNOTSUPP;
  86. return crypto_register_shash(&alg);
  87. }
  88. static void __exit sha1_s390_fini(void)
  89. {
  90. crypto_unregister_shash(&alg);
  91. }
  92. module_cpu_feature_match(MSA, sha1_s390_init);
  93. module_exit(sha1_s390_fini);
  94. MODULE_ALIAS_CRYPTO("sha1");
  95. MODULE_LICENSE("GPL");
  96. MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");