diff options
author | Oren Novotny <oren@novotny.org> | 2018-07-19 20:37:04 -0400 |
---|---|---|
committer | Oren Novotny <oren@novotny.org> | 2018-07-19 20:37:04 -0400 |
commit | 27161159797e4c66157ce82bc19154e132543482 (patch) | |
tree | 9e2b1d951a4e5dba772f6890b285b0e719df4ff7 /crypto/src/asn1 | |
parent | remove unused define (diff) | |
parent | IDEA: Update patent information (diff) | |
download | BouncyCastle.NET-ed25519-27161159797e4c66157ce82bc19154e132543482.tar.xz |
Merge from master
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r-- | crypto/src/asn1/cryptopro/ECGOST3410NamedCurves.cs | 45 | ||||
-rw-r--r-- | crypto/src/asn1/x9/X962NamedCurves.cs | 6 | ||||
-rw-r--r-- | crypto/src/asn1/x9/X9Curve.cs | 76 | ||||
-rw-r--r-- | crypto/src/asn1/x9/X9ECParameters.cs | 27 | ||||
-rw-r--r-- | crypto/src/asn1/x9/X9FieldElement.cs | 2 |
5 files changed, 78 insertions, 78 deletions
diff --git a/crypto/src/asn1/cryptopro/ECGOST3410NamedCurves.cs b/crypto/src/asn1/cryptopro/ECGOST3410NamedCurves.cs index 9c366503d..b61da6b57 100644 --- a/crypto/src/asn1/cryptopro/ECGOST3410NamedCurves.cs +++ b/crypto/src/asn1/cryptopro/ECGOST3410NamedCurves.cs @@ -32,15 +32,14 @@ namespace Org.BouncyCastle.Asn1.CryptoPro mod_p, // p new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639316"), // a new BigInteger("166"), // b - mod_q, - BigInteger.One); + mod_q, BigInteger.One); ECDomainParameters ecParams = new ECDomainParameters( curve, curve.CreatePoint( new BigInteger("1"), // x new BigInteger("64033881142927202683649881450433473985931760268884941288852745803908878638612")), // y - mod_q); + mod_q, BigInteger.One); parameters[CryptoProObjectIdentifiers.GostR3410x2001CryptoProA] = ecParams; @@ -51,15 +50,14 @@ namespace Org.BouncyCastle.Asn1.CryptoPro mod_p, // p new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639316"), new BigInteger("166"), - mod_q, - BigInteger.One); + mod_q, BigInteger.One); ecParams = new ECDomainParameters( curve, curve.CreatePoint( new BigInteger("1"), // x new BigInteger("64033881142927202683649881450433473985931760268884941288852745803908878638612")), // y - mod_q); + mod_q, BigInteger.One); parameters[CryptoProObjectIdentifiers.GostR3410x2001CryptoProXchA] = ecParams; @@ -70,15 +68,14 @@ namespace Org.BouncyCastle.Asn1.CryptoPro mod_p, // p new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564823190"), // a new BigInteger("28091019353058090096996979000309560759124368558014865957655842872397301267595"), // b - mod_q, - BigInteger.One); + mod_q, BigInteger.One); ecParams = new ECDomainParameters( curve, curve.CreatePoint( new BigInteger("1"), // x new BigInteger("28792665814854611296992347458380284135028636778229113005756334730996303888124")), // y - mod_q); // q + mod_q, BigInteger.One); parameters[CryptoProObjectIdentifiers.GostR3410x2001CryptoProB] = ecParams; @@ -89,15 +86,14 @@ namespace Org.BouncyCastle.Asn1.CryptoPro mod_p, // p new BigInteger("70390085352083305199547718019018437841079516630045180471284346843705633502616"), new BigInteger("32858"), - mod_q, - BigInteger.One); + mod_q, BigInteger.One); ecParams = new ECDomainParameters( curve, curve.CreatePoint( new BigInteger("0"), new BigInteger("29818893917731240733471273240314769927240550812383695689146495261604565990247")), - mod_q); + mod_q, BigInteger.One); parameters[CryptoProObjectIdentifiers.GostR3410x2001CryptoProXchB] = ecParams; @@ -107,15 +103,14 @@ namespace Org.BouncyCastle.Asn1.CryptoPro mod_p, // p new BigInteger("70390085352083305199547718019018437841079516630045180471284346843705633502616"), // a new BigInteger("32858"), // b - mod_q, - BigInteger.One); + mod_q, BigInteger.One); ecParams = new ECDomainParameters( curve, curve.CreatePoint( new BigInteger("0"), // x new BigInteger("29818893917731240733471273240314769927240550812383695689146495261604565990247")), // y - mod_q); // q + mod_q, BigInteger.One); parameters[CryptoProObjectIdentifiers.GostR3410x2001CryptoProC] = ecParams; @@ -126,15 +121,14 @@ namespace Org.BouncyCastle.Asn1.CryptoPro mod_p, // p new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639316"), // a new BigInteger("166"), // b - mod_q, - BigInteger.One); + mod_q, BigInteger.One); ecParams = new ECDomainParameters( curve, curve.CreatePoint( new BigInteger("1"), // x new BigInteger("64033881142927202683649881450433473985931760268884941288852745803908878638612")), // y - mod_q); // q + mod_q, BigInteger.One); parameters[RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256_paramSetA] = ecParams; @@ -144,15 +138,14 @@ namespace Org.BouncyCastle.Asn1.CryptoPro mod_p, // p new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDC4",16), // a new BigInteger("E8C2505DEDFC86DDC1BD0B2B6667F1DA34B82574761CB0E879BD081CFD0B6265EE3CB090F30D27614CB4574010DA90DD862EF9D4EBEE4761503190785A71C760",16), // b - mod_q, - BigInteger.One); + mod_q, BigInteger.One); ecParams = new ECDomainParameters( curve, curve.CreatePoint( new BigInteger("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003"), // x new BigInteger("7503CFE87A836AE3A61B8816E25450E6CE5E1C93ACF1ABC1778064FDCBEFA921DF1626BE4FD036E93D75E6A50E3A41E98028FE5FC235F5B889A589CB5215F2A4",16)), // y - mod_q); // q + mod_q, BigInteger.One); parameters[RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512_paramSetA] = ecParams; @@ -162,15 +155,14 @@ namespace Org.BouncyCastle.Asn1.CryptoPro mod_p, // p new BigInteger("8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006C",16), // a new BigInteger("687D1B459DC841457E3E06CF6F5E2517B97C7D614AF138BCBF85DC806C4B289F3E965D2DB1416D217F8B276FAD1AB69C50F78BEE1FA3106EFB8CCBC7C5140116",16), // b - mod_q, - BigInteger.One); + mod_q, BigInteger.One); ecParams = new ECDomainParameters( curve, curve.CreatePoint( new BigInteger("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"), // x new BigInteger("1A8F7EDA389B094C2C071E3647A8940F3C123B697578C213BE6DD9E6C8EC7335DCB228FD1EDF4A39152CBCAAF8C0398828041055F94CEEEC7E21340780FE41BD",16)), // y - mod_q); // q + mod_q, BigInteger.One); parameters[RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512_paramSetB] = ecParams; @@ -180,15 +172,14 @@ namespace Org.BouncyCastle.Asn1.CryptoPro mod_p, // p new BigInteger("DC9203E514A721875485A529D2C722FB187BC8980EB866644DE41C68E143064546E861C0E2C9EDD92ADE71F46FCF50FF2AD97F951FDA9F2A2EB6546F39689BD3",16), // a new BigInteger("B4C4EE28CEBC6C2C8AC12952CF37F16AC7EFB6A9F69F4B57FFDA2E4F0DE5ADE038CBC2FFF719D2C18DE0284B8BFEF3B52B8CC7A5F5BF0A3C8D2319A5312557E1",16), // b - mod_q, - BigInteger.One); + mod_q, BigInteger.One); ecParams = new ECDomainParameters( curve, curve.CreatePoint( new BigInteger("E2E31EDFC23DE7BDEBE241CE593EF5DE2295B7A9CBAEF021D385F7074CEA043AA27272A7AE602BF2A7B9033DB9ED3610C6FB85487EAE97AAC5BC7928C1950148", 16), // x new BigInteger("F5CE40D95B5EB899ABBCCFF5911CB8577939804D6527378B8C108C3D2090FF9BE18E2D33E3021ED2EF32D85822423B6304F726AA854BAE07D0396E9A9ADDC40F",16)), // y - mod_q); // q + mod_q, BigInteger.One); parameters[RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512_paramSetC] = ecParams; diff --git a/crypto/src/asn1/x9/X962NamedCurves.cs b/crypto/src/asn1/x9/X962NamedCurves.cs index 14f7f818a..1609774f1 100644 --- a/crypto/src/asn1/x9/X962NamedCurves.cs +++ b/crypto/src/asn1/x9/X962NamedCurves.cs @@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Asn1.X9 BigInteger h = BigInteger.One; ECCurve cFp192v1 = new FpCurve( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), + new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", 16), new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), n, h); @@ -58,7 +58,7 @@ namespace Org.BouncyCastle.Asn1.X9 BigInteger h = BigInteger.One; ECCurve cFp192v2 = new FpCurve( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), + new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", 16), new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), new BigInteger("cc22d6dfb95c6b25e49c0d6364a4e5980c393aa21668d953", 16), n, h); @@ -85,7 +85,7 @@ namespace Org.BouncyCastle.Asn1.X9 BigInteger h = BigInteger.One; ECCurve cFp192v3 = new FpCurve( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), + new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", 16), new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), new BigInteger("22123dc2395a05caa7423daeccc94760a7d462256bd56916", 16), n, h); diff --git a/crypto/src/asn1/x9/X9Curve.cs b/crypto/src/asn1/x9/X9Curve.cs index f05a946c2..eab94def8 100644 --- a/crypto/src/asn1/x9/X9Curve.cs +++ b/crypto/src/asn1/x9/X9Curve.cs @@ -47,9 +47,19 @@ namespace Org.BouncyCastle.Asn1.X9 } } + [Obsolete("Use constructor including order/cofactor")] public X9Curve( X9FieldID fieldID, Asn1Sequence seq) + : this(fieldID, null, null, seq) + { + } + + public X9Curve( + X9FieldID fieldID, + BigInteger order, + BigInteger cofactor, + Asn1Sequence seq) { if (fieldID == null) throw new ArgumentNullException("fieldID"); @@ -60,47 +70,47 @@ namespace Org.BouncyCastle.Asn1.X9 if (fieldIdentifier.Equals(X9ObjectIdentifiers.PrimeField)) { - BigInteger q = ((DerInteger) fieldID.Parameters).Value; - X9FieldElement x9A = new X9FieldElement(q, (Asn1OctetString) seq[0]); - X9FieldElement x9B = new X9FieldElement(q, (Asn1OctetString) seq[1]); - curve = new FpCurve(q, x9A.Value.ToBigInteger(), x9B.Value.ToBigInteger()); + BigInteger p = ((DerInteger)fieldID.Parameters).Value; + BigInteger A = new BigInteger(1, Asn1OctetString.GetInstance(seq[0]).GetOctets()); + BigInteger B = new BigInteger(1, Asn1OctetString.GetInstance(seq[1]).GetOctets()); + curve = new FpCurve(p, A, B, order, cofactor); } - else + else if (fieldIdentifier.Equals(X9ObjectIdentifiers.CharacteristicTwoField)) { - if (fieldIdentifier.Equals(X9ObjectIdentifiers.CharacteristicTwoField)) + // Characteristic two field + DerSequence parameters = (DerSequence)fieldID.Parameters; + int m = ((DerInteger)parameters[0]).Value.IntValue; + DerObjectIdentifier representation + = (DerObjectIdentifier)parameters[1]; + + int k1 = 0; + int k2 = 0; + int k3 = 0; + if (representation.Equals(X9ObjectIdentifiers.TPBasis)) { - // Characteristic two field - DerSequence parameters = (DerSequence)fieldID.Parameters; - int m = ((DerInteger)parameters[0]).Value.IntValue; - DerObjectIdentifier representation - = (DerObjectIdentifier)parameters[1]; - - int k1 = 0; - int k2 = 0; - int k3 = 0; - if (representation.Equals(X9ObjectIdentifiers.TPBasis)) - { - // Trinomial basis representation - k1 = ((DerInteger)parameters[2]).Value.IntValue; - } - else - { - // Pentanomial basis representation - DerSequence pentanomial = (DerSequence) parameters[2]; - k1 = ((DerInteger) pentanomial[0]).Value.IntValue; - k2 = ((DerInteger) pentanomial[1]).Value.IntValue; - k3 = ((DerInteger) pentanomial[2]).Value.IntValue; - } - X9FieldElement x9A = new X9FieldElement(m, k1, k2, k3, (Asn1OctetString)seq[0]); - X9FieldElement x9B = new X9FieldElement(m, k1, k2, k3, (Asn1OctetString)seq[1]); - // TODO Is it possible to get the order (n) and cofactor(h) too? - curve = new F2mCurve(m, k1, k2, k3, x9A.Value.ToBigInteger(), x9B.Value.ToBigInteger()); + // Trinomial basis representation + k1 = ((DerInteger)parameters[2]).Value.IntValue; } + else + { + // Pentanomial basis representation + DerSequence pentanomial = (DerSequence) parameters[2]; + k1 = ((DerInteger) pentanomial[0]).Value.IntValue; + k2 = ((DerInteger) pentanomial[1]).Value.IntValue; + k3 = ((DerInteger) pentanomial[2]).Value.IntValue; + } + BigInteger A = new BigInteger(1, Asn1OctetString.GetInstance(seq[0]).GetOctets()); + BigInteger B = new BigInteger(1, Asn1OctetString.GetInstance(seq[1]).GetOctets()); + curve = new F2mCurve(m, k1, k2, k3, A, B, order, cofactor); + } + else + { + throw new ArgumentException("This type of ECCurve is not implemented"); } if (seq.Count == 3) { - seed = ((DerBitString) seq[2]).GetBytes(); + seed = ((DerBitString)seq[2]).GetBytes(); } } diff --git a/crypto/src/asn1/x9/X9ECParameters.cs b/crypto/src/asn1/x9/X9ECParameters.cs index 0fa343768..e1b29ca13 100644 --- a/crypto/src/asn1/x9/X9ECParameters.cs +++ b/crypto/src/asn1/x9/X9ECParameters.cs @@ -23,29 +23,32 @@ namespace Org.BouncyCastle.Asn1.X9 public static X9ECParameters GetInstance(Object obj) { if (obj is X9ECParameters) - { return (X9ECParameters)obj; - } - if (obj != null) - { + if (obj != null) return new X9ECParameters(Asn1Sequence.GetInstance(obj)); - } - return null; + return null; } public X9ECParameters( Asn1Sequence seq) { if (!(seq[0] is DerInteger) - || !((DerInteger) seq[0]).Value.Equals(BigInteger.One)) + || !((DerInteger)seq[0]).Value.Equals(BigInteger.One)) { throw new ArgumentException("bad version in X9ECParameters"); } + this.n = ((DerInteger)seq[4]).Value; + + if (seq.Count == 6) + { + this.h = ((DerInteger)seq[5]).Value; + } + X9Curve x9c = new X9Curve( - X9FieldID.GetInstance(seq[1]), + X9FieldID.GetInstance(seq[1]), n, h, Asn1Sequence.GetInstance(seq[2])); this.curve = x9c.Curve; @@ -53,20 +56,14 @@ namespace Org.BouncyCastle.Asn1.X9 if (p is X9ECPoint) { - this.g = ((X9ECPoint)p); + this.g = (X9ECPoint)p; } else { this.g = new X9ECPoint(curve, (Asn1OctetString)p); } - this.n = ((DerInteger)seq[4]).Value; this.seed = x9c.GetSeed(); - - if (seq.Count == 6) - { - this.h = ((DerInteger)seq[5]).Value; - } } public X9ECParameters( diff --git a/crypto/src/asn1/x9/X9FieldElement.cs b/crypto/src/asn1/x9/X9FieldElement.cs index 94bd96b24..222b4cfc8 100644 --- a/crypto/src/asn1/x9/X9FieldElement.cs +++ b/crypto/src/asn1/x9/X9FieldElement.cs @@ -19,6 +19,7 @@ namespace Org.BouncyCastle.Asn1.X9 this.f = f; } + [Obsolete("Will be removed")] public X9FieldElement( BigInteger p, Asn1OctetString s) @@ -26,6 +27,7 @@ namespace Org.BouncyCastle.Asn1.X9 { } + [Obsolete("Will be removed")] public X9FieldElement( int m, int k1, |