From: Jiasheng Jiang Date: Mon, 25 Mar 2024 14:16:51 +0000 (+0000) Subject: Break the if statement up into 2 if statements X-Git-Tag: openssl-3.4.0-alpha1~789 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b6f307721db97d9bd7ca5ad4abf12b90ef581cd;p=thirdparty%2Fopenssl.git Break the if statement up into 2 if statements Break the if statement up into 2 if statements to avoid call EVP_MD_get_size() twice. Signed-off-by: Jiasheng Jiang Reviewed-by: Tomas Mraz Reviewed-by: Todd Short Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/23959) --- diff --git a/providers/implementations/signature/sm2_sig.c b/providers/implementations/signature/sm2_sig.c index 6b8936b9594..346172abc08 100644 --- a/providers/implementations/signature/sm2_sig.c +++ b/providers/implementations/signature/sm2_sig.c @@ -310,11 +310,13 @@ int sm2sig_digest_verify_final(void *vpsm2ctx, const unsigned char *sig, PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; unsigned char digest[EVP_MAX_MD_SIZE]; unsigned int dlen = 0; + int md_size; - if (psm2ctx == NULL - || psm2ctx->mdctx == NULL - || EVP_MD_get_size(psm2ctx->md) <= 0 - || EVP_MD_get_size(psm2ctx->md) > (int)sizeof(digest)) + if (psm2ctx == NULL || psm2ctx->mdctx == NULL) + return 0; + + md_size = EVP_MD_get_size(psm2ctx->md); + if (md_size <= 0 || md_size > (int)sizeof(digest)) return 0; if (!(sm2sig_compute_z_digest(psm2ctx)