gost_md.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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, size_t count);
  16. static int gost_digest_final(EVP_MD_CTX *ctx,unsigned char *md);
  17. static int gost_digest_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from);
  18. static int gost_digest_cleanup(EVP_MD_CTX *ctx);
  19. EVP_MD digest_gost=
  20. {
  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,sizeof(struct ossl_gost_digest_ctx));
  58. md_ctx->dctx.cipher_ctx=&(md_ctx->cctx);
  59. }
  60. return 1;
  61. }
  62. int gost_digest_cleanup(EVP_MD_CTX *ctx)
  63. {
  64. if (ctx->md_data)
  65. memset(ctx->md_data,0,sizeof(struct ossl_gost_digest_ctx));
  66. return 1;
  67. }