sha256_s390.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Cryptographic API.
  3. *
  4. * s390 implementation of the SHA256 Secure Hash Algorithm.
  5. *
  6. * s390 Version:
  7. * Copyright IBM Corp. 2005,2007
  8. * Author(s): Jan Glauber (jang@de.ibm.com)
  9. *
  10. * Derived from "crypto/sha256_generic.c"
  11. * and "arch/s390/crypto/sha1_s390.c"
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the Free
  15. * Software Foundation; either version 2 of the License, or (at your option)
  16. * any later version.
  17. *
  18. */
  19. #include <crypto/internal/hash.h>
  20. #include <linux/init.h>
  21. #include <linux/module.h>
  22. #include <crypto/sha.h>
  23. #include "crypt_s390.h"
  24. #include "sha.h"
  25. static int sha256_init(struct shash_desc *desc)
  26. {
  27. struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
  28. sctx->state[0] = SHA256_H0;
  29. sctx->state[1] = SHA256_H1;
  30. sctx->state[2] = SHA256_H2;
  31. sctx->state[3] = SHA256_H3;
  32. sctx->state[4] = SHA256_H4;
  33. sctx->state[5] = SHA256_H5;
  34. sctx->state[6] = SHA256_H6;
  35. sctx->state[7] = SHA256_H7;
  36. sctx->count = 0;
  37. sctx->func = KIMD_SHA_256;
  38. return 0;
  39. }
  40. static struct shash_alg alg = {
  41. .digestsize = SHA256_DIGEST_SIZE,
  42. .init = sha256_init,
  43. .update = s390_sha_update,
  44. .final = s390_sha_final,
  45. .descsize = sizeof(struct s390_sha_ctx),
  46. .base = {
  47. .cra_name = "sha256",
  48. .cra_driver_name= "sha256-s390",
  49. .cra_priority = CRYPT_S390_PRIORITY,
  50. .cra_flags = CRYPTO_ALG_TYPE_SHASH,
  51. .cra_blocksize = SHA256_BLOCK_SIZE,
  52. .cra_module = THIS_MODULE,
  53. }
  54. };
  55. static int sha256_s390_init(void)
  56. {
  57. if (!crypt_s390_func_available(KIMD_SHA_256))
  58. return -EOPNOTSUPP;
  59. return crypto_register_shash(&alg);
  60. }
  61. static void __exit sha256_s390_fini(void)
  62. {
  63. crypto_unregister_shash(&alg);
  64. }
  65. module_init(sha256_s390_init);
  66. module_exit(sha256_s390_fini);
  67. MODULE_ALIAS("sha256");
  68. MODULE_LICENSE("GPL");
  69. MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm");