]> git.ipfire.org Git - thirdparty/openssl.git/blame - engines/ccgost/gost_md.c
1. Changes for s_client.c to make it return non-zero exit code in case
[thirdparty/openssl.git] / engines / ccgost / gost_md.c
CommitLineData
a04549cc
DSH
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>
926c41bd 10#include "gost_lcl.h"
a04549cc
DSH
11#include "gosthash.h"
12#include "e_gost_err.h"
13
14/* implementation of GOST 34.11 hash function See gost_md.c*/
15static int gost_digest_init(EVP_MD_CTX *ctx);
16static int gost_digest_update(EVP_MD_CTX *ctx, const void *data, size_t count);
17static int gost_digest_final(EVP_MD_CTX *ctx,unsigned char *md);
18static int gost_digest_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from);
19static int gost_digest_cleanup(EVP_MD_CTX *ctx);
20
21EVP_MD digest_gost=
926c41bd
DSH
22 {
23 NID_id_GostR3411_94,
24 NID_undef,
25 32,
26 EVP_MD_FLAG_PKEY_METHOD_SIGNATURE,
27 gost_digest_init,
28 gost_digest_update,
29 gost_digest_final,
30 gost_digest_copy,
31 gost_digest_cleanup,
32 NULL,
33 NULL,
34 {NID_undef,NID_undef,0,0,0},
35 32,
36 sizeof(struct ossl_gost_digest_ctx ),
37 NULL
38 };
a04549cc
DSH
39
40int gost_digest_init(EVP_MD_CTX *ctx)
926c41bd 41 {
a04549cc
DSH
42 struct ossl_gost_digest_ctx *c = ctx->md_data;
43 memset(&(c->dctx),0,sizeof(gost_hash_ctx));
44 gost_init(&(c->cctx),&GostR3411_94_CryptoProParamSet);
45 c->dctx.cipher_ctx= &(c->cctx);
46 return 1;
926c41bd 47 }
a04549cc
DSH
48
49int gost_digest_update(EVP_MD_CTX *ctx,const void *data,size_t count)
926c41bd 50 {
a04549cc 51 return hash_block((gost_hash_ctx *)ctx->md_data,data,count);
926c41bd 52 }
a04549cc
DSH
53
54int gost_digest_final(EVP_MD_CTX *ctx,unsigned char *md)
926c41bd 55 {
a04549cc
DSH
56 return finish_hash((gost_hash_ctx *)ctx->md_data,md);
57
926c41bd 58 }
a04549cc
DSH
59
60int gost_digest_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from)
926c41bd 61 {
0e1dba93
DSH
62 struct ossl_gost_digest_ctx *md_ctx=to->md_data;
63 if (to->md_data && from->md_data) {
64 memcpy(to->md_data,from->md_data,sizeof(struct ossl_gost_digest_ctx));
65 md_ctx->dctx.cipher_ctx=&(md_ctx->cctx);
66 }
926c41bd
DSH
67 return 1;
68 }
a04549cc 69
926c41bd
DSH
70int gost_digest_cleanup(EVP_MD_CTX *ctx)
71 {
a4346646 72 if (ctx->md_data)
a04549cc
DSH
73 memset(ctx->md_data,0,sizeof(struct ossl_gost_digest_ctx));
74 return 1;
926c41bd 75 }