gost_md.c revision 280304
1238384Sjkim/********************************************************************** 2238384Sjkim * md_gost.c * 3238384Sjkim * Copyright (c) 2005-2006 Cryptocom LTD * 4238384Sjkim * This file is distributed under the same license as OpenSSL * 5238384Sjkim * * 6238384Sjkim * OpenSSL interface to GOST R 34.11-94 hash functions * 7238384Sjkim * Requires OpenSSL 0.9.9 for compilation * 8238384Sjkim **********************************************************************/ 9238384Sjkim#include <string.h> 10238384Sjkim#include "gost_lcl.h" 11238384Sjkim#include "gosthash.h" 12238384Sjkim#include "e_gost_err.h" 13238384Sjkim 14238384Sjkim/* implementation of GOST 34.11 hash function See gost_md.c*/ 15238384Sjkimstatic int gost_digest_init(EVP_MD_CTX *ctx); 16280304Sjkimstatic int gost_digest_update(EVP_MD_CTX *ctx, const void *data, 17280304Sjkim size_t count); 18280304Sjkimstatic int gost_digest_final(EVP_MD_CTX *ctx, unsigned char *md); 19280304Sjkimstatic int gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from); 20238384Sjkimstatic int gost_digest_cleanup(EVP_MD_CTX *ctx); 21238384Sjkim 22280304SjkimEVP_MD digest_gost = { 23280304Sjkim NID_id_GostR3411_94, 24280304Sjkim NID_undef, 25280304Sjkim 32, 26280304Sjkim EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, 27280304Sjkim gost_digest_init, 28280304Sjkim gost_digest_update, 29280304Sjkim gost_digest_final, 30280304Sjkim gost_digest_copy, 31280304Sjkim gost_digest_cleanup, 32280304Sjkim NULL, 33280304Sjkim NULL, 34280304Sjkim {NID_undef, NID_undef, 0, 0, 0}, 35280304Sjkim 32, 36280304Sjkim sizeof(struct ossl_gost_digest_ctx), 37280304Sjkim NULL 38280304Sjkim}; 39238384Sjkim 40280304Sjkimint gost_digest_init(EVP_MD_CTX *ctx) 41280304Sjkim{ 42280304Sjkim struct ossl_gost_digest_ctx *c = ctx->md_data; 43280304Sjkim memset(&(c->dctx), 0, sizeof(gost_hash_ctx)); 44280304Sjkim gost_init(&(c->cctx), &GostR3411_94_CryptoProParamSet); 45280304Sjkim c->dctx.cipher_ctx = &(c->cctx); 46280304Sjkim return 1; 47280304Sjkim} 48238384Sjkim 49280304Sjkimint gost_digest_update(EVP_MD_CTX *ctx, const void *data, size_t count) 50280304Sjkim{ 51280304Sjkim return hash_block((gost_hash_ctx *) ctx->md_data, data, count); 52280304Sjkim} 53238384Sjkim 54280304Sjkimint gost_digest_final(EVP_MD_CTX *ctx, unsigned char *md) 55280304Sjkim{ 56280304Sjkim return finish_hash((gost_hash_ctx *) ctx->md_data, md); 57238384Sjkim 58280304Sjkim} 59238384Sjkim 60280304Sjkimint gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) 61280304Sjkim{ 62280304Sjkim struct ossl_gost_digest_ctx *md_ctx = to->md_data; 63280304Sjkim if (to->md_data && from->md_data) { 64280304Sjkim memcpy(to->md_data, from->md_data, 65280304Sjkim sizeof(struct ossl_gost_digest_ctx)); 66280304Sjkim md_ctx->dctx.cipher_ctx = &(md_ctx->cctx); 67280304Sjkim } 68280304Sjkim return 1; 69280304Sjkim} 70280304Sjkim 71280304Sjkimint gost_digest_cleanup(EVP_MD_CTX *ctx) 72280304Sjkim{ 73280304Sjkim if (ctx->md_data) 74280304Sjkim memset(ctx->md_data, 0, sizeof(struct ossl_gost_digest_ctx)); 75280304Sjkim return 1; 76280304Sjkim} 77