]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
fix SM2 privatekey decode(PEM format, ECPrivateKey).
authorAlen Yan <yzpgryx@163.com>
Wed, 9 Jul 2025 01:23:00 +0000 (09:23 +0800)
committerTomas Mraz <tomas@openssl.org>
Fri, 25 Jul 2025 07:51:00 +0000 (09:51 +0200)
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27963)

include/openssl/pem.h
providers/implementations/encode_decode/decode_pem2der.c
test/recipes/15-test_ec.t
test/testec-sm2.pem [new file with mode: 0644]

index 94424e6c209eb9acfc882c388234e6c6800940a8..de1b6581f28f63293c464c06ee71c63c4d80e3f9 100644 (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"
 
index abea679fe19af3e02ba7410cf0b1b83332c4b406..a38c71883dd14c967c9d3adbcda011e211570c4a 100644 (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" },
index c953fad9f1ec4f8d935375853355c001c7fb8434..2b6c9781dd0af65a46a1e73b37551b5f8e268481 100644 (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"),
diff --git a/test/testec-sm2.pem b/test/testec-sm2.pem
new file mode 100644 (file)
index 0000000..30e2561
--- /dev/null
@@ -0,0 +1,5 @@
+-----BEGIN SM2 PRIVATE KEY-----
+MHcCAQEEIKPB7gEYKGAwAkz0MfGwQm0BXclgzvSTxQG9bm4RCAxXoAoGCCqBHM9V
+AYItoUQDQgAE+FuibOpfjVfj716O3LglhK4HzjUR82mgn8kTZinQsEafw3FFZzZJ
+vwHIGHUsSKxVTRIEs+BICQDBg99OA3VU/Q==
+-----END SM2 PRIVATE KEY-----