X-Git-Url: http://www.wagner.pp.ru/gitweb/?p=openssl-gost%2Fengine.git;a=blobdiff_plain;f=gost_omac_acpkm.c;h=8a3c841ad269feb43b297ae38c7123c7bf630eb5;hp=cec683fb34637a393fa09049f490cd3c78eafa89;hb=HEAD;hpb=27d1f87c77844f58e13805c0c4bed3d373f1ee07 diff --git a/gost_omac_acpkm.c b/gost_omac_acpkm.c index cec683f..8a3c841 100644 --- a/gost_omac_acpkm.c +++ b/gost_omac_acpkm.c @@ -98,7 +98,7 @@ static void CMAC_ACPKM_CTX_free(CMAC_ACPKM_CTX *ctx) OPENSSL_free(ctx); } -int CMAC_ACPKM_CTX_copy(CMAC_ACPKM_CTX *out, const CMAC_ACPKM_CTX *in) +static int CMAC_ACPKM_CTX_copy(CMAC_ACPKM_CTX *out, const CMAC_ACPKM_CTX *in) { int bl; if (in->nlast_block == -1) @@ -249,6 +249,7 @@ static int CMAC_ACPKM_Update(CMAC_ACPKM_CTX *ctx, const void *in, size_t dlen) } +/* Return value is propagated to EVP_DigestFinal_ex */ static int CMAC_ACPKM_Final(CMAC_ACPKM_CTX *ctx, unsigned char *out, size_t *poutlen) { @@ -257,6 +258,10 @@ static int CMAC_ACPKM_Final(CMAC_ACPKM_CTX *ctx, unsigned char *out, if (ctx->nlast_block == -1) return 0; bl = EVP_CIPHER_CTX_block_size(ctx->cctx); + if (bl != 8 && bl != 16) { + GOSTerr(GOST_F_OMAC_ACPKM_IMIT_FINAL, GOST_R_INVALID_MAC_PARAMS); + return 0; + } *poutlen = (size_t) bl; if (!out) return 1; @@ -341,16 +346,17 @@ int omac_acpkm_imit_final(EVP_MD_CTX *ctx, unsigned char *md) OMAC_ACPKM_CTX *c = EVP_MD_CTX_md_data(ctx); unsigned char mac[MAX_GOST_OMAC_ACPKM_SIZE]; size_t mac_size = sizeof(mac); + int ret; if (!c->key_set) { GOSTerr(GOST_F_OMAC_ACPKM_IMIT_FINAL, GOST_R_MAC_KEY_NOT_SET); return 0; } - CMAC_ACPKM_Final(c->cmac_ctx, mac, &mac_size); + ret = CMAC_ACPKM_Final(c->cmac_ctx, mac, &mac_size); memcpy(md, mac, c->dgst_size); - return 1; + return ret; } static int omac_acpkm_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) @@ -372,10 +378,11 @@ static int omac_acpkm_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) } return 1; } - if (c_to->cmac_ctx == c_from->cmac_ctx) { + if ((c_to->cmac_ctx == c_from->cmac_ctx) || (c_to->cmac_ctx == NULL)) { c_to->cmac_ctx = CMAC_ACPKM_CTX_new(); } - return CMAC_ACPKM_CTX_copy(c_to->cmac_ctx, c_from->cmac_ctx); + + return (c_to->cmac_ctx) ? CMAC_ACPKM_CTX_copy(c_to->cmac_ctx, c_from->cmac_ctx) : 0; } /* Clean up imit ctx */