X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gost_omac.c;h=e78fd9d7c5de76e3e7b00c80e7a18a1e5b26eeb9;hb=75796d263c62a57a330f596d4a03d9ed22ec9f74;hp=af6eb2a9e9e6e9cf2260754db5c7b147b2c912d8;hpb=636dd0c1f36872f0abcb4f8a465e837929ed19d1;p=openssl-gost%2Fengine.git diff --git a/gost_omac.c b/gost_omac.c index af6eb2a..e78fd9d 100644 --- a/gost_omac.c +++ b/gost_omac.c @@ -7,6 +7,8 @@ #include "e_gost_err.h" #include "gost_lcl.h" +#define min(a,b) (((a) < (b)) ? (a) : (b)) + typedef struct omac_ctx { CMAC_CTX *cmac_ctx; size_t dgst_size; @@ -71,7 +73,8 @@ int omac_imit_final(EVP_MD_CTX *ctx, unsigned char *md) CMAC_Final(c->cmac_ctx, mac, &mac_size); - memcpy(md, mac, c->dgst_size); + int md_size = EVP_MD_meth_get_result_size(EVP_MD_CTX_md(ctx)); + memcpy(md, mac, min(md_size, c->dgst_size)); return 1; } @@ -89,6 +92,13 @@ int omac_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) { return 0; } + if (!c_from->cmac_ctx) { + if (c_to->cmac_ctx) { + CMAC_CTX_free(c_to->cmac_ctx); + c_to->cmac_ctx = NULL; + } + return 1; + } if (c_to->cmac_ctx == c_from->cmac_ctx) { c_to->cmac_ctx = CMAC_CTX_new();