2
0

gost_md.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**********************************************************************
  2. * md_gost.c *
  3. * Copyright (c) 2005-2006 Cryptocom LTD *
  4. * This file is distributed under the same license as OpenSSL *
  5. * *
  6. * OpenSSL interface to GOST R 34.11-94 hash functions *
  7. * Requires OpenSSL 0.9.9 for compilation *
  8. **********************************************************************/
  9. #include <string.h>
  10. #include "gost_lcl.h"
  11. #include "gosthash.h"
  12. #include "e_gost_err.h"
  13. /* implementation of GOST 34.11 hash function See gost_md.c*/
  14. static int gost_digest_init(EVP_MD_CTX *ctx);
  15. static int gost_digest_update(EVP_MD_CTX *ctx, const void *data,
  16. size_t count);
  17. static int gost_digest_final(EVP_MD_CTX *ctx, unsigned char *md);
  18. static int gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from);
  19. static int gost_digest_cleanup(EVP_MD_CTX *ctx);
  20. EVP_MD digest_gost = {
  21. NID_id_GostR3411_94,
  22. NID_undef,
  23. 32,
  24. EVP_MD_FLAG_PKEY_METHOD_SIGNATURE,
  25. gost_digest_init,
  26. gost_digest_update,
  27. gost_digest_final,
  28. gost_digest_copy,
  29. gost_digest_cleanup,
  30. NULL,
  31. NULL,
  32. {NID_undef, NID_undef, 0, 0, 0},
  33. 32,
  34. sizeof(struct ossl_gost_digest_ctx),
  35. NULL
  36. };
  37. int gost_digest_init(EVP_MD_CTX *ctx)
  38. {
  39. struct ossl_gost_digest_ctx *c = ctx->md_data;
  40. memset(&(c->dctx), 0, sizeof(gost_hash_ctx));
  41. gost_init(&(c->cctx), &GostR3411_94_CryptoProParamSet);
  42. c->dctx.cipher_ctx = &(c->cctx);
  43. return 1;
  44. }
  45. int gost_digest_update(EVP_MD_CTX *ctx, const void *data, size_t count)
  46. {
  47. return hash_block((gost_hash_ctx *) ctx->md_data, data, count);
  48. }
  49. int gost_digest_final(EVP_MD_CTX *ctx, unsigned char *md)
  50. {
  51. return finish_hash((gost_hash_ctx *) ctx->md_data, md);
  52. }
  53. int gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
  54. {
  55. struct ossl_gost_digest_ctx *md_ctx = to->md_data;
  56. if (to->md_data && from->md_data) {
  57. memcpy(to->md_data, from->md_data,
  58. sizeof(struct ossl_gost_digest_ctx));
  59. md_ctx->dctx.cipher_ctx = &(md_ctx->cctx);
  60. }
  61. return 1;
  62. }
  63. int gost_digest_cleanup(EVP_MD_CTX *ctx)
  64. {
  65. if (ctx->md_data)
  66. memset(ctx->md_data, 0, sizeof(struct ossl_gost_digest_ctx));
  67. return 1;
  68. }