summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorNeil Horman <nhorman@openssl.org>2024-03-18 14:59:32 -0400
committerTomas Mraz <tomas@openssl.org>2024-04-09 20:38:58 +0200
commitd6a8adeccdb8188517c5a84d35b79ef826176472 (patch)
treedca68d3d5df758414252b154f53e4becdd03af89 /crypto
parentbeb82177ddcd4b536544ceec92bb53f4d85d8e91 (diff)
Add check for public key presence on sm2 signing
SM2 requires that the public EC_POINT be present in a key when signing. If its not there we crash on a NULL pointer. Add a check to ensure that its present, and raise an error if its not Reviewed-by: Paul Yang <kaishen.yy@antfin.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23887)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/sm2/sm2_sign.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/crypto/sm2/sm2_sign.c b/crypto/sm2/sm2_sign.c
index 1b3ca94d6e..1ffbb171fa 100644
--- a/crypto/sm2/sm2_sign.c
+++ b/crypto/sm2/sm2_sign.c
@@ -28,6 +28,7 @@ int ossl_sm2_compute_z_digest(uint8_t *out,
{
int rc = 0;
const EC_GROUP *group = EC_KEY_get0_group(key);
+ const EC_POINT *pubkey = EC_KEY_get0_public_key(key);
BN_CTX *ctx = NULL;
EVP_MD_CTX *hash = NULL;
BIGNUM *p = NULL;
@@ -42,6 +43,12 @@ int ossl_sm2_compute_z_digest(uint8_t *out,
uint16_t entl = 0;
uint8_t e_byte = 0;
+ /* SM2 Signatures require a public key, check for it */
+ if (pubkey == NULL) {
+ ERR_raise(ERR_LIB_SM2, ERR_R_PASSED_NULL_PARAMETER);
+ goto done;
+ }
+
hash = EVP_MD_CTX_new();
if (hash == NULL) {
ERR_raise(ERR_LIB_SM2, ERR_R_EVP_LIB);
@@ -119,7 +126,7 @@ int ossl_sm2_compute_z_digest(uint8_t *out,
|| BN_bn2binpad(yG, buf, p_bytes) < 0
|| !EVP_DigestUpdate(hash, buf, p_bytes)
|| !EC_POINT_get_affine_coordinates(group,
- EC_KEY_get0_public_key(key),
+ pubkey,
xA, yA, ctx)
|| BN_bn2binpad(xA, buf, p_bytes) < 0
|| !EVP_DigestUpdate(hash, buf, p_bytes)