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:41:52 +0200
commit06fbcb6eec57fe3690a1932d81d23fcae3a9a954 (patch)
treeb63a88a583dd7c79a56b2cceb4a4341e4fbf9846 /crypto
parentc24f54510092cd1ef92a8a4d7a26c6422ad62aea (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) (cherry picked from commit d6a8adeccdb8188517c5a84d35b79ef826176472)
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 b4932e3127..9ddf889ede 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)