init commit
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
using System.Collections;
|
||||
using Org.BouncyCastle.Asn1.X9;
|
||||
using Org.BouncyCastle.Math;
|
||||
using Org.BouncyCastle.Math.EC;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
using Org.BouncyCastle.Utilities.Collections;
|
||||
using Org.BouncyCastle.Utilities.Encoders;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.GM;
|
||||
|
||||
public sealed class GMNamedCurves
|
||||
{
|
||||
internal class SM2P256V1Holder : X9ECParametersHolder
|
||||
{
|
||||
internal static readonly X9ECParametersHolder Instance = new SM2P256V1Holder();
|
||||
|
||||
private SM2P256V1Holder()
|
||||
{
|
||||
}
|
||||
|
||||
protected override X9ECParameters CreateParameters()
|
||||
{
|
||||
BigInteger q = FromHex("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF");
|
||||
BigInteger a = FromHex("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC");
|
||||
BigInteger b = FromHex("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93");
|
||||
byte[] seed = null;
|
||||
BigInteger bigInteger = FromHex("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123");
|
||||
BigInteger one = BigInteger.One;
|
||||
ECCurve eCCurve = ConfigureCurve(new FpCurve(q, a, b, bigInteger, one));
|
||||
X9ECPoint g = new X9ECPoint(eCCurve, Hex.Decode("0432C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0"));
|
||||
return new X9ECParameters(eCCurve, g, bigInteger, one, seed);
|
||||
}
|
||||
}
|
||||
|
||||
internal class WapiP192V1Holder : X9ECParametersHolder
|
||||
{
|
||||
internal static readonly X9ECParametersHolder Instance = new WapiP192V1Holder();
|
||||
|
||||
private WapiP192V1Holder()
|
||||
{
|
||||
}
|
||||
|
||||
protected override X9ECParameters CreateParameters()
|
||||
{
|
||||
BigInteger q = FromHex("BDB6F4FE3E8B1D9E0DA8C0D46F4C318CEFE4AFE3B6B8551F");
|
||||
BigInteger a = FromHex("BB8E5E8FBC115E139FE6A814FE48AAA6F0ADA1AA5DF91985");
|
||||
BigInteger b = FromHex("1854BEBDC31B21B7AEFC80AB0ECD10D5B1B3308E6DBF11C1");
|
||||
byte[] seed = null;
|
||||
BigInteger bigInteger = FromHex("BDB6F4FE3E8B1D9E0DA8C0D40FC962195DFAE76F56564677");
|
||||
BigInteger one = BigInteger.One;
|
||||
ECCurve eCCurve = ConfigureCurve(new FpCurve(q, a, b, bigInteger, one));
|
||||
X9ECPoint g = new X9ECPoint(eCCurve, Hex.Decode("044AD5F7048DE709AD51236DE65E4D4B482C836DC6E410664002BB3A02D4AAADACAE24817A4CA3A1B014B5270432DB27D2"));
|
||||
return new X9ECParameters(eCCurve, g, bigInteger, one, seed);
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly IDictionary objIds;
|
||||
|
||||
private static readonly IDictionary curves;
|
||||
|
||||
private static readonly IDictionary names;
|
||||
|
||||
public static IEnumerable Names => new EnumerableProxy(names.Values);
|
||||
|
||||
private GMNamedCurves()
|
||||
{
|
||||
}
|
||||
|
||||
private static ECCurve ConfigureCurve(ECCurve curve)
|
||||
{
|
||||
return curve;
|
||||
}
|
||||
|
||||
private static BigInteger FromHex(string hex)
|
||||
{
|
||||
return new BigInteger(1, Hex.Decode(hex));
|
||||
}
|
||||
|
||||
private static void DefineCurve(string name, DerObjectIdentifier oid, X9ECParametersHolder holder)
|
||||
{
|
||||
objIds.Add(Platform.ToUpperInvariant(name), oid);
|
||||
names.Add(oid, name);
|
||||
curves.Add(oid, holder);
|
||||
}
|
||||
|
||||
static GMNamedCurves()
|
||||
{
|
||||
objIds = Platform.CreateHashtable();
|
||||
curves = Platform.CreateHashtable();
|
||||
names = Platform.CreateHashtable();
|
||||
DefineCurve("wapip192v1", GMObjectIdentifiers.wapip192v1, WapiP192V1Holder.Instance);
|
||||
DefineCurve("sm2p256v1", GMObjectIdentifiers.sm2p256v1, SM2P256V1Holder.Instance);
|
||||
}
|
||||
|
||||
public static X9ECParameters GetByName(string name)
|
||||
{
|
||||
DerObjectIdentifier oid = GetOid(name);
|
||||
if (oid != null)
|
||||
{
|
||||
return GetByOid(oid);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static X9ECParameters GetByOid(DerObjectIdentifier oid)
|
||||
{
|
||||
return ((X9ECParametersHolder)curves[oid])?.Parameters;
|
||||
}
|
||||
|
||||
public static DerObjectIdentifier GetOid(string name)
|
||||
{
|
||||
return (DerObjectIdentifier)objIds[Platform.ToUpperInvariant(name)];
|
||||
}
|
||||
|
||||
public static string GetName(DerObjectIdentifier oid)
|
||||
{
|
||||
return (string)names[oid];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
namespace Org.BouncyCastle.Asn1.GM;
|
||||
|
||||
public abstract class GMObjectIdentifiers
|
||||
{
|
||||
public static readonly DerObjectIdentifier sm_scheme = new DerObjectIdentifier("1.2.156.10197.1");
|
||||
|
||||
public static readonly DerObjectIdentifier sm6_ecb = sm_scheme.Branch("101.1");
|
||||
|
||||
public static readonly DerObjectIdentifier sm6_cbc = sm_scheme.Branch("101.2");
|
||||
|
||||
public static readonly DerObjectIdentifier sm6_ofb128 = sm_scheme.Branch("101.3");
|
||||
|
||||
public static readonly DerObjectIdentifier sm6_cfb128 = sm_scheme.Branch("101.4");
|
||||
|
||||
public static readonly DerObjectIdentifier sm1_ecb = sm_scheme.Branch("102.1");
|
||||
|
||||
public static readonly DerObjectIdentifier sm1_cbc = sm_scheme.Branch("102.2");
|
||||
|
||||
public static readonly DerObjectIdentifier sm1_ofb128 = sm_scheme.Branch("102.3");
|
||||
|
||||
public static readonly DerObjectIdentifier sm1_cfb128 = sm_scheme.Branch("102.4");
|
||||
|
||||
public static readonly DerObjectIdentifier sm1_cfb1 = sm_scheme.Branch("102.5");
|
||||
|
||||
public static readonly DerObjectIdentifier sm1_cfb8 = sm_scheme.Branch("102.6");
|
||||
|
||||
public static readonly DerObjectIdentifier ssf33_ecb = sm_scheme.Branch("103.1");
|
||||
|
||||
public static readonly DerObjectIdentifier ssf33_cbc = sm_scheme.Branch("103.2");
|
||||
|
||||
public static readonly DerObjectIdentifier ssf33_ofb128 = sm_scheme.Branch("103.3");
|
||||
|
||||
public static readonly DerObjectIdentifier ssf33_cfb128 = sm_scheme.Branch("103.4");
|
||||
|
||||
public static readonly DerObjectIdentifier ssf33_cfb1 = sm_scheme.Branch("103.5");
|
||||
|
||||
public static readonly DerObjectIdentifier ssf33_cfb8 = sm_scheme.Branch("103.6");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_ecb = sm_scheme.Branch("104.1");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_cbc = sm_scheme.Branch("104.2");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_ofb128 = sm_scheme.Branch("104.3");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_cfb128 = sm_scheme.Branch("104.4");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_cfb1 = sm_scheme.Branch("104.5");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_cfb8 = sm_scheme.Branch("104.6");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_ctr = sm_scheme.Branch("104.7");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_gcm = sm_scheme.Branch("104.8");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_ccm = sm_scheme.Branch("104.9");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_xts = sm_scheme.Branch("104.10");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_wrap = sm_scheme.Branch("104.11");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_wrap_pad = sm_scheme.Branch("104.12");
|
||||
|
||||
public static readonly DerObjectIdentifier sms4_ocb = sm_scheme.Branch("104.100");
|
||||
|
||||
public static readonly DerObjectIdentifier sm5 = sm_scheme.Branch("201");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2p256v1 = sm_scheme.Branch("301");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2sign = sm_scheme.Branch("301.1");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2exchange = sm_scheme.Branch("301.2");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt = sm_scheme.Branch("301.3");
|
||||
|
||||
public static readonly DerObjectIdentifier wapip192v1 = sm_scheme.Branch("301.101");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_recommendedParameters = sm2encrypt.Branch("1");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_specifiedParameters = sm2encrypt.Branch("2");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_with_sm3 = sm2encrypt.Branch("2.1");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_with_sha1 = sm2encrypt.Branch("2.2");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_with_sha224 = sm2encrypt.Branch("2.3");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_with_sha256 = sm2encrypt.Branch("2.4");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_with_sha384 = sm2encrypt.Branch("2.5");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_with_sha512 = sm2encrypt.Branch("2.6");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_with_rmd160 = sm2encrypt.Branch("2.7");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_with_whirlpool = sm2encrypt.Branch("2.8");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_with_blake2b512 = sm2encrypt.Branch("2.9");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_with_blake2s256 = sm2encrypt.Branch("2.10");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2encrypt_with_md5 = sm2encrypt.Branch("2.11");
|
||||
|
||||
public static readonly DerObjectIdentifier id_sm9PublicKey = sm_scheme.Branch("302");
|
||||
|
||||
public static readonly DerObjectIdentifier sm9sign = sm_scheme.Branch("302.1");
|
||||
|
||||
public static readonly DerObjectIdentifier sm9keyagreement = sm_scheme.Branch("302.2");
|
||||
|
||||
public static readonly DerObjectIdentifier sm9encrypt = sm_scheme.Branch("302.3");
|
||||
|
||||
public static readonly DerObjectIdentifier sm3 = sm_scheme.Branch("401");
|
||||
|
||||
public static readonly DerObjectIdentifier hmac_sm3 = sm3.Branch("2");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2sign_with_sm3 = sm_scheme.Branch("501");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2sign_with_sha1 = sm_scheme.Branch("502");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2sign_with_sha256 = sm_scheme.Branch("503");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2sign_with_sha512 = sm_scheme.Branch("504");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2sign_with_sha224 = sm_scheme.Branch("505");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2sign_with_sha384 = sm_scheme.Branch("506");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2sign_with_rmd160 = sm_scheme.Branch("507");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2sign_with_whirlpool = sm_scheme.Branch("520");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2sign_with_blake2b512 = sm_scheme.Branch("521");
|
||||
|
||||
public static readonly DerObjectIdentifier sm2sign_with_blake2s256 = sm_scheme.Branch("522");
|
||||
}
|
||||
Reference in New Issue
Block a user