fix SM2 privatekey decode(PEM format, ECPrivateKey).

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27963)
This commit is contained in:
Alen Yan 2025-07-09 09:23:00 +08:00 committed by Tomas Mraz
parent e7d5398aa1
commit bd172dd0e1
4 changed files with 12 additions and 1 deletions

View File

@ -57,6 +57,7 @@ extern "C" {
# define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
# define PEM_STRING_PARAMETERS "PARAMETERS"
# define PEM_STRING_CMS "CMS"
# define PEM_STRING_SM2PRIVATEKEY "SM2 PRIVATE KEY"
# define PEM_STRING_SM2PARAMETERS "SM2 PARAMETERS"
# define PEM_STRING_ACERT "ATTRIBUTE CERTIFICATE"

View File

@ -151,6 +151,7 @@ static int pem2der_decode(void *vctx, OSSL_CORE_BIO *cin, int selection,
{ PEM_STRING_DSAPARAMS, OSSL_OBJECT_PKEY, "DSA", "type-specific" },
{ PEM_STRING_ECPRIVATEKEY, OSSL_OBJECT_PKEY, "EC", "type-specific" },
{ PEM_STRING_ECPARAMETERS, OSSL_OBJECT_PKEY, "EC", "type-specific" },
{ PEM_STRING_SM2PRIVATEKEY, OSSL_OBJECT_PKEY, "SM2", "type-specific" },
{ PEM_STRING_SM2PARAMETERS, OSSL_OBJECT_PKEY, "SM2", "type-specific" },
{ PEM_STRING_RSA, OSSL_OBJECT_PKEY, "RSA", "type-specific" },
{ PEM_STRING_RSA_PUBLIC, OSSL_OBJECT_PKEY, "RSA", "type-specific" },

View File

@ -18,7 +18,7 @@ setup("test_ec");
plan skip_all => 'EC is not supported in this build' if disabled('ec');
plan tests => 15;
plan tests => 16;
my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
@ -33,6 +33,10 @@ subtest 'EC conversions -- private key' => sub {
tconversion( -type => 'ec', -prefix => 'ec-priv',
-in => srctop_file("test","testec-p256.pem") );
};
subtest 'EC conversions -- private key' => sub {
tconversion( -type => 'ec', -prefix => 'sm2-priv',
-in => srctop_file("test","testec-sm2.pem") );
};
subtest 'EC conversions -- private key PKCS#8' => sub {
tconversion( -type => 'ec', -prefix => 'ec-pkcs8',
-in => srctop_file("test","testec-p256.pem"),

5
test/testec-sm2.pem Normal file
View File

@ -0,0 +1,5 @@
-----BEGIN SM2 PRIVATE KEY-----
MHcCAQEEIKPB7gEYKGAwAkz0MfGwQm0BXclgzvSTxQG9bm4RCAxXoAoGCCqBHM9V
AYItoUQDQgAE+FuibOpfjVfj716O3LglhK4HzjUR82mgn8kTZinQsEafw3FFZzZJ
vwHIGHUsSKxVTRIEs+BICQDBg99OA3VU/Q==
-----END SM2 PRIVATE KEY-----