| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | using Renci.SshNet.Security.Org.BouncyCastle.Math; |
| | | 4 | | using Renci.SshNet.Security.Org.BouncyCastle.Math.EC; |
| | | 5 | | using Renci.SshNet.Security.Org.BouncyCastle.Utilities; |
| | | 6 | | |
| | | 7 | | namespace Renci.SshNet.Security.Org.BouncyCastle.Crypto.Parameters |
| | | 8 | | { |
| | | 9 | | internal class ECDomainParameters |
| | | 10 | | { |
| | | 11 | | internal ECCurve curve; |
| | | 12 | | internal byte[] seed; |
| | | 13 | | internal ECPoint g; |
| | | 14 | | internal BigInteger n; |
| | | 15 | | internal BigInteger h; |
| | | 16 | | internal BigInteger hInv; |
| | | 17 | | |
| | 9 | 18 | | public ECDomainParameters( |
| | 9 | 19 | | ECCurve curve, |
| | 9 | 20 | | ECPoint g, |
| | 9 | 21 | | BigInteger n, |
| | 9 | 22 | | BigInteger h, |
| | 9 | 23 | | byte[] seed) |
| | 9 | 24 | | { |
| | 9 | 25 | | if (curve == null) |
| | 0 | 26 | | throw new ArgumentNullException("curve"); |
| | 9 | 27 | | if (g == null) |
| | 0 | 28 | | throw new ArgumentNullException("g"); |
| | 9 | 29 | | if (n == null) |
| | 0 | 30 | | throw new ArgumentNullException("n"); |
| | | 31 | | // we can't check for h == null here as h is optional in X9.62 as it is not required for ECDSA |
| | | 32 | | |
| | 9 | 33 | | this.curve = curve; |
| | 9 | 34 | | this.g = Validate(curve, g); |
| | 9 | 35 | | this.n = n; |
| | 9 | 36 | | this.h = h; |
| | 9 | 37 | | this.seed = Arrays.Clone(seed); |
| | 9 | 38 | | } |
| | | 39 | | |
| | | 40 | | public ECCurve Curve |
| | | 41 | | { |
| | 108 | 42 | | get { return curve; } |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | public ECPoint G |
| | | 46 | | { |
| | 27 | 47 | | get { return g; } |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | public BigInteger N |
| | | 51 | | { |
| | 81 | 52 | | get { return n; } |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | public BigInteger H |
| | | 56 | | { |
| | 27 | 57 | | get { return h; } |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | public BigInteger HInv |
| | | 61 | | { |
| | | 62 | | get |
| | 0 | 63 | | { |
| | 0 | 64 | | lock (this) |
| | 0 | 65 | | { |
| | 0 | 66 | | if (hInv == null) |
| | 0 | 67 | | { |
| | 0 | 68 | | hInv = h.ModInverse(n); |
| | 0 | 69 | | } |
| | 0 | 70 | | return hInv; |
| | | 71 | | } |
| | 0 | 72 | | } |
| | | 73 | | } |
| | | 74 | | |
| | | 75 | | internal static ECPoint Validate(ECCurve c, ECPoint q) |
| | 27 | 76 | | { |
| | 27 | 77 | | if (q == null) |
| | 0 | 78 | | throw new ArgumentException("Point has null value", "q"); |
| | | 79 | | |
| | 27 | 80 | | q = ECAlgorithms.ImportPoint(c, q).Normalize(); |
| | | 81 | | |
| | 27 | 82 | | if (q.IsInfinity) |
| | 0 | 83 | | throw new ArgumentException("Point at infinity", "q"); |
| | | 84 | | |
| | 27 | 85 | | if (!q.IsValid()) |
| | 0 | 86 | | throw new ArgumentException("Point not on curve", "q"); |
| | | 87 | | |
| | 27 | 88 | | return q; |
| | 27 | 89 | | } |
| | | 90 | | } |
| | | 91 | | } |