Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/12628)
/* The caller can assume that this removes any secret data from the context */
int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *isize)
{
- int ret;
+ int ret, sz;
size_t size = 0;
- size_t mdsize = EVP_MD_size(ctx->digest);
+ size_t mdsize = 0;
- if (ctx->digest == NULL || ctx->digest->prov == NULL)
+ if (ctx->digest == NULL)
+ return 0;
+
+ sz = EVP_MD_size(ctx->digest);
+ if (sz < 0)
+ return 0;
+ mdsize = sz;
+ if (ctx->digest->prov == NULL)
goto legacy;
if (ctx->digest->dfinal == NULL) {