summary refs log tree commit diff
path: root/crypto/src/security
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2019-06-01 18:58:01 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2019-06-01 18:58:01 +0700
commit17dbcd1de2147c407f30f84d29ac6e223baf5d73 (patch)
tree95a935970c10b2d180a0aae388d60b431ed745ce /crypto/src/security
parentMerge branch 'rastrup-patch-4' (diff)
downloadBouncyCastle.NET-ed25519-17dbcd1de2147c407f30f84d29ac6e223baf5d73.tar.xz
Support SM2 in SignerUtilities
- including support for non-standard SHA256withSM2
Diffstat (limited to 'crypto/src/security')
-rw-r--r--crypto/src/security/SignerUtilities.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/crypto/src/security/SignerUtilities.cs b/crypto/src/security/SignerUtilities.cs
index ae8d21f0a..93d20a697 100644
--- a/crypto/src/security/SignerUtilities.cs
+++ b/crypto/src/security/SignerUtilities.cs
@@ -7,6 +7,7 @@ using Org.BouncyCastle.Asn1.Bsi;
 using Org.BouncyCastle.Asn1.CryptoPro;
 using Org.BouncyCastle.Asn1.Eac;
 using Org.BouncyCastle.Asn1.EdEC;
+using Org.BouncyCastle.Asn1.GM;
 using Org.BouncyCastle.Asn1.Nist;
 using Org.BouncyCastle.Asn1.Oiw;
 using Org.BouncyCastle.Asn1.Pkcs;
@@ -344,6 +345,11 @@ namespace Org.BouncyCastle.Security
             algorithms[EdECObjectIdentifiers.id_Ed448.Id] = "Ed448";
             algorithms["ED448PH"] = "Ed448ph";
 
+            algorithms["SHA256WITHSM2"] = "SHA256withSM2";
+            algorithms[GMObjectIdentifiers.sm2sign_with_sha256.Id] = "SHA256withSM2";
+            algorithms["SM3WITHSM2"] = "SM3withSM2";
+            algorithms[GMObjectIdentifiers.sm2sign_with_sm3.Id] = "SM3withSM2";
+
             oids["MD2withRSA"] = PkcsObjectIdentifiers.MD2WithRsaEncryption;
             oids["MD4withRSA"] = PkcsObjectIdentifiers.MD4WithRsaEncryption;
             oids["MD5withRSA"] = PkcsObjectIdentifiers.MD5WithRsaEncryption;
@@ -392,6 +398,9 @@ namespace Org.BouncyCastle.Security
 
             oids["Ed25519"] = EdECObjectIdentifiers.id_Ed25519;
             oids["Ed448"] = EdECObjectIdentifiers.id_Ed448;
+
+            oids["SHA256withSM2"] = GMObjectIdentifiers.sm2sign_with_sha256;
+            oids["SM3withSM2"] = GMObjectIdentifiers.sm2sign_with_sm3;
         }
 
         /// <summary>
@@ -570,6 +579,13 @@ namespace Org.BouncyCastle.Security
                 return new DsaDigestSigner(new ECNRSigner(), digest);
             }
 
+            if (Platform.EndsWith(mechanism, "withSM2"))
+            {
+                string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
+                IDigest digest = DigestUtilities.GetDigest(digestName);
+                return new SM2Signer(digest);
+            }
+
             if (mechanism.Equals("GOST3410"))
             {
                 return new Gost3410DigestSigner(new Gost3410Signer(), new Gost3411Digest());