ECParameterSpec.java revision e6bf3e8dfa2804891a82075cb469b736321b4827
1package org.bouncycastle.jce.spec; 2 3import org.bouncycastle.math.ec.ECCurve; 4import org.bouncycastle.math.ec.ECPoint; 5 6import java.math.BigInteger; 7import java.security.spec.AlgorithmParameterSpec; 8 9/** 10 * basic domain parameters for an Elliptic Curve public or private key. 11 */ 12public class ECParameterSpec 13 implements AlgorithmParameterSpec 14{ 15 private ECCurve curve; 16 private byte[] seed; 17 private ECPoint G; 18 private BigInteger n; 19 private BigInteger h; 20 21 public ECParameterSpec( 22 ECCurve curve, 23 ECPoint G, 24 BigInteger n) 25 { 26 this.curve = curve; 27 this.G = G; 28 this.n = n; 29 this.h = BigInteger.valueOf(1); 30 this.seed = null; 31 } 32 33 public ECParameterSpec( 34 ECCurve curve, 35 ECPoint G, 36 BigInteger n, 37 BigInteger h) 38 { 39 this.curve = curve; 40 this.G = G; 41 this.n = n; 42 this.h = h; 43 this.seed = null; 44 } 45 46 public ECParameterSpec( 47 ECCurve curve, 48 ECPoint G, 49 BigInteger n, 50 BigInteger h, 51 byte[] seed) 52 { 53 this.curve = curve; 54 this.G = G; 55 this.n = n; 56 this.h = h; 57 this.seed = seed; 58 } 59 60 /** 61 * return the curve along which the base point lies. 62 * @return the curve 63 */ 64 public ECCurve getCurve() 65 { 66 return curve; 67 } 68 69 /** 70 * return the base point we are using for these domain parameters. 71 * @return the base point. 72 */ 73 public ECPoint getG() 74 { 75 return G; 76 } 77 78 /** 79 * return the order N of G 80 * @return the order 81 */ 82 public BigInteger getN() 83 { 84 return n; 85 } 86 87 /** 88 * return the cofactor H to the order of G. 89 * @return the cofactor 90 */ 91 public BigInteger getH() 92 { 93 return h; 94 } 95 96 /** 97 * return the seed used to generate this curve (if available). 98 * @return the random seed 99 */ 100 public byte[] getSeed() 101 { 102 return seed; 103 } 104 105 public boolean equals(Object o) 106 { 107 if (!(o instanceof ECParameterSpec)) 108 { 109 return false; 110 } 111 112 ECParameterSpec other = (ECParameterSpec)o; 113 114 return this.getCurve().equals(other.getCurve()) && this.getG().equals(other.getG()); 115 } 116 117 public int hashCode() 118 { 119 return this.getCurve().hashCode() ^ this.getG().hashCode(); 120 } 121} 122