| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | using Renci.SshNet.Security.Org.BouncyCastle.Security; |
| | | 4 | | using Renci.SshNet.Security.Org.BouncyCastle.Utilities; |
| | | 5 | | |
| | | 6 | | namespace Renci.SshNet.Security.Org.BouncyCastle.Crypto.Parameters |
| | | 7 | | { |
| | | 8 | | internal abstract class ECKeyParameters |
| | | 9 | | : AsymmetricKeyParameter |
| | | 10 | | { |
| | 1 | 11 | | private static readonly string[] algorithms = { "EC", "ECDH" }; |
| | | 12 | | |
| | | 13 | | private readonly string algorithm; |
| | | 14 | | private readonly ECDomainParameters parameters; |
| | | 15 | | |
| | | 16 | | protected ECKeyParameters( |
| | | 17 | | string algorithm, |
| | | 18 | | bool isPrivate, |
| | | 19 | | ECDomainParameters parameters) |
| | 27 | 20 | | : base(isPrivate) |
| | 27 | 21 | | { |
| | 27 | 22 | | if (algorithm == null) |
| | 0 | 23 | | throw new ArgumentNullException("algorithm"); |
| | 27 | 24 | | if (parameters == null) |
| | 0 | 25 | | throw new ArgumentNullException("parameters"); |
| | | 26 | | |
| | 27 | 27 | | this.algorithm = VerifyAlgorithmName(algorithm); |
| | 27 | 28 | | this.parameters = parameters; |
| | 27 | 29 | | } |
| | | 30 | | |
| | | 31 | | public string AlgorithmName |
| | | 32 | | { |
| | 0 | 33 | | get { return algorithm; } |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | public ECDomainParameters Parameters |
| | | 37 | | { |
| | 108 | 38 | | get { return parameters; } |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | public override bool Equals( |
| | | 42 | | object obj) |
| | 0 | 43 | | { |
| | 0 | 44 | | if (obj == this) |
| | 0 | 45 | | return true; |
| | | 46 | | |
| | 0 | 47 | | ECDomainParameters other = obj as ECDomainParameters; |
| | | 48 | | |
| | 0 | 49 | | if (other == null) |
| | 0 | 50 | | return false; |
| | | 51 | | |
| | 0 | 52 | | return Equals(other); |
| | 0 | 53 | | } |
| | | 54 | | |
| | | 55 | | protected bool Equals( |
| | | 56 | | ECKeyParameters other) |
| | 0 | 57 | | { |
| | 0 | 58 | | return parameters.Equals(other.parameters) && base.Equals(other); |
| | 0 | 59 | | } |
| | | 60 | | |
| | | 61 | | public override int GetHashCode() |
| | 0 | 62 | | { |
| | 0 | 63 | | return parameters.GetHashCode() ^ base.GetHashCode(); |
| | 0 | 64 | | } |
| | | 65 | | |
| | | 66 | | internal ECKeyGenerationParameters CreateKeyGenerationParameters( |
| | | 67 | | SecureRandom random) |
| | 0 | 68 | | { |
| | 0 | 69 | | return new ECKeyGenerationParameters(parameters, random); |
| | 0 | 70 | | } |
| | | 71 | | |
| | | 72 | | internal static string VerifyAlgorithmName(string algorithm) |
| | 36 | 73 | | { |
| | 36 | 74 | | if (Array.IndexOf(algorithms, algorithm, 0, algorithms.Length) < 0) |
| | 0 | 75 | | throw new ArgumentException("unrecognised algorithm: " + algorithm, "algorithm"); |
| | 36 | 76 | | return algorithm.ToUpper(); |
| | 36 | 77 | | } |
| | | 78 | | } |
| | | 79 | | } |