gost_md.c revision 296341
177298Sobrien/********************************************************************** 277298Sobrien * md_gost.c * 378828Sobrien * Copyright (c) 2005-2006 Cryptocom LTD * 478828Sobrien * This file is distributed under the same license as OpenSSL * 5130561Sobrien * * 678828Sobrien * OpenSSL interface to GOST R 34.11-94 hash functions * 778828Sobrien * Requires OpenSSL 0.9.9 for compilation * 878828Sobrien **********************************************************************/ 978828Sobrien#include <string.h> 1078828Sobrien#include "gost_lcl.h" 1178828Sobrien#include "gosthash.h" 1278828Sobrien#include "e_gost_err.h" 1378828Sobrien 1478828Sobrien/* implementation of GOST 34.11 hash function See gost_md.c*/ 1578828Sobrienstatic int gost_digest_init(EVP_MD_CTX *ctx); 1678828Sobrienstatic int gost_digest_update(EVP_MD_CTX *ctx, const void *data, 1778828Sobrien size_t count); 1878828Sobrienstatic int gost_digest_final(EVP_MD_CTX *ctx, unsigned char *md); 1978828Sobrienstatic int gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from); 2077298Sobrienstatic int gost_digest_cleanup(EVP_MD_CTX *ctx); 2177298Sobrien 2277298SobrienEVP_MD digest_gost = { 2389857Sobrien NID_id_GostR3411_94, 2489857Sobrien NID_undef, 2577298Sobrien 32, 2677298Sobrien EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, 2789857Sobrien gost_digest_init, 2889857Sobrien gost_digest_update, 2989857Sobrien gost_digest_final, 3089857Sobrien gost_digest_copy, 3189857Sobrien gost_digest_cleanup, 3289857Sobrien NULL, 3389857Sobrien NULL, 3489857Sobrien {NID_undef, NID_undef, 0, 0, 0}, 3589857Sobrien 32, 3689857Sobrien sizeof(struct ossl_gost_digest_ctx), 3789857Sobrien NULL 3877298Sobrien}; 3977298Sobrien 4077298Sobrienint gost_digest_init(EVP_MD_CTX *ctx) 4177298Sobrien{ 4277298Sobrien struct ossl_gost_digest_ctx *c = ctx->md_data; 4377298Sobrien memset(&(c->dctx), 0, sizeof(gost_hash_ctx)); 4477298Sobrien gost_init(&(c->cctx), &GostR3411_94_CryptoProParamSet); 4577298Sobrien c->dctx.cipher_ctx = &(c->cctx); 4677298Sobrien return 1; 4777298Sobrien} 4877298Sobrien 4977298Sobrienint gost_digest_update(EVP_MD_CTX *ctx, const void *data, size_t count) 5077298Sobrien{ 5177298Sobrien return hash_block((gost_hash_ctx *) ctx->md_data, data, count); 5277298Sobrien} 5377298Sobrien 5477298Sobrienint gost_digest_final(EVP_MD_CTX *ctx, unsigned char *md) 5577298Sobrien{ 5677298Sobrien return finish_hash((gost_hash_ctx *) ctx->md_data, md); 5777298Sobrien 5877298Sobrien} 5977298Sobrien 60130561Sobrienint gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) 61130561Sobrien{ 62130561Sobrien struct ossl_gost_digest_ctx *md_ctx = to->md_data; 63130561Sobrien if (to->md_data && from->md_data) { 64130561Sobrien memcpy(to->md_data, from->md_data, 65130561Sobrien sizeof(struct ossl_gost_digest_ctx)); 66130561Sobrien md_ctx->dctx.cipher_ctx = &(md_ctx->cctx); 67130561Sobrien } 6877298Sobrien return 1; 6977298Sobrien} 7077298Sobrien 7177298Sobrienint gost_digest_cleanup(EVP_MD_CTX *ctx) 7277298Sobrien{ 7377298Sobrien if (ctx->md_data) 7477298Sobrien memset(ctx->md_data, 0, sizeof(struct ossl_gost_digest_ctx)); 7577298Sobrien return 1; 7677298Sobrien} 7777298Sobrien