From 47171162217fbd9a1b854da8d0bfed115326afa0 Mon Sep 17 00:00:00 2001 From: xicilion Date: Tue, 23 Jul 2024 22:50:53 +0800 Subject: [PATCH] openssl, refactor: fix bug in ossl_sm2_compute_z_digest function. --- openssl/src/crypto/sm2/sm2_sign.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openssl/src/crypto/sm2/sm2_sign.c b/openssl/src/crypto/sm2/sm2_sign.c index 9ddf889ed..3eac8c549 100644 --- a/openssl/src/crypto/sm2/sm2_sign.c +++ b/openssl/src/crypto/sm2/sm2_sign.c @@ -23,7 +23,7 @@ int ossl_sm2_compute_z_digest(uint8_t *out, const EVP_MD *digest, const uint8_t *id, - const size_t id_len, + size_t id_len, const EC_KEY *key) { int rc = 0; @@ -80,6 +80,11 @@ int ossl_sm2_compute_z_digest(uint8_t *out, /* Z = h(ENTL || ID || a || b || xG || yG || xA || yA) */ + if (id == NULL) { + id = (const uint8_t *)SM2_DEFAULT_USERID; + id_len = strlen(SM2_DEFAULT_USERID); + } + if (id_len >= (UINT16_MAX / 8)) { /* too large */ ERR_raise(ERR_LIB_SM2, SM2_R_ID_TOO_LARGE);