Skip to content

Commit cd7a2a4

Browse files
authored
Add to legacy SKIP unsupported params with SM2
1 parent 90dac98 commit cd7a2a4

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

ext/openssl/openssl.c

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4299,31 +4299,37 @@ static bool php_openssl_pkey_init_legacy_ec(EC_KEY *eckey, zval *data, bool *is_
42994299
if (!EC_KEY_set_group(eckey, group)) {
43004300
goto clean_exit;
43014301
}
4302+
4303+
/* custom params not supported with SM2, SKIP */
4304+
if (!curve_name_zv ||
4305+
(Z_TYPE_P(curve_name_zv) == IS_STRING &&
4306+
OPENSSL_strcasecmp(Z_STRVAL_P(curve_name_zv), "SM2") != 0)){
4307+
OPENSSL_PKEY_SET_BN(data, d);
4308+
OPENSSL_PKEY_SET_BN(data, x);
4309+
OPENSSL_PKEY_SET_BN(data, y);
43024310

4303-
OPENSSL_PKEY_SET_BN(data, d);
4304-
OPENSSL_PKEY_SET_BN(data, x);
4305-
OPENSSL_PKEY_SET_BN(data, y);
4306-
if (d) {
4307-
*is_private = true;
4308-
if (!EC_KEY_set_private_key(eckey, d)) {
4309-
goto clean_exit;
4310-
}
4311-
4312-
point_q = EC_POINT_new(group);
4313-
if (!point_q || !EC_POINT_mul(group, point_q, d, NULL, NULL, bctx)) {
4314-
goto clean_exit;
4315-
}
4316-
} else if (x && y) {
4317-
/* OpenSSL does not allow setting EC_PUB_X/EC_PUB_Y, so convert to encoded format. */
4318-
point_q = EC_POINT_new(group);
4319-
if (!point_q || !EC_POINT_set_affine_coordinates(group, point_q, x, y, bctx)) {
4320-
goto clean_exit;
4311+
if (d) {
4312+
*is_private = true;
4313+
if (!EC_KEY_set_private_key(eckey, d)) {
4314+
goto clean_exit;
4315+
}
4316+
4317+
point_q = EC_POINT_new(group);
4318+
if (!point_q || !EC_POINT_mul(group, point_q, d, NULL, NULL, bctx)) {
4319+
goto clean_exit;
4320+
}
4321+
} else if (x && y) {
4322+
/* OpenSSL does not allow setting EC_PUB_X/EC_PUB_Y, so convert to encoded format. */
4323+
point_q = EC_POINT_new(group);
4324+
if (!point_q || !EC_POINT_set_affine_coordinates(group, point_q, x, y, bctx)) {
4325+
goto clean_exit;
4326+
}
43214327
}
4322-
}
43234328

4324-
if (point_q != NULL) {
4325-
if (!EC_KEY_set_public_key(eckey, point_q)) {
4326-
goto clean_exit;
4329+
if (point_q != NULL) {
4330+
if (!EC_KEY_set_public_key(eckey, point_q)) {
4331+
goto clean_exit;
4332+
}
43274333
}
43284334
}
43294335

0 commit comments

Comments
 (0)