1. /*
  2. * @(#)ECParameterSpec.java 1.3 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security.spec;
  8. import java.math.BigInteger;
  9. /**
  10. * This immutable class specifies the set of domain parameters
  11. * used with elliptic curve cryptography (ECC).
  12. *
  13. * @see AlgorithmParameterSpec
  14. *
  15. * @author Valerie Peng
  16. * @version 1.3, 12/19/03
  17. *
  18. * @since 1.5
  19. */
  20. public class ECParameterSpec implements AlgorithmParameterSpec {
  21. private final EllipticCurve curve;
  22. private final ECPoint g;
  23. private final BigInteger n;
  24. private final int h;
  25. /**
  26. * Creates elliptic curve domain parameters based on the
  27. * specified values.
  28. * @param curve the elliptic curve which this parameter
  29. * defines.
  30. * @param g the generator which is also known as the base point.
  31. * @param n the order of the generator <code>g</code>.
  32. * @param h the cofactor.
  33. * @exception NullPointerException if <code>curve</code>,
  34. * <code>g</code>, or <code>n</code> is null.
  35. * @exception IllegalArgumentException if <code>n</code>
  36. * or <code>h</code> is not positive.
  37. */
  38. public ECParameterSpec(EllipticCurve curve, ECPoint g,
  39. BigInteger n, int h) {
  40. if (curve == null) {
  41. throw new NullPointerException("curve is null");
  42. }
  43. if (g == null) {
  44. throw new NullPointerException("g is null");
  45. }
  46. if (n == null) {
  47. throw new NullPointerException("n is null");
  48. }
  49. if (n.signum() != 1) {
  50. throw new IllegalArgumentException("n is not positive");
  51. }
  52. if (h <= 0) {
  53. throw new IllegalArgumentException("h is not positive");
  54. }
  55. this.curve = curve;
  56. this.g = g;
  57. this.n = n;
  58. this.h = h;
  59. }
  60. /**
  61. * Returns the elliptic curve that this parameter defines.
  62. * @return the elliptic curve that this parameter defines.
  63. */
  64. public EllipticCurve getCurve() {
  65. return curve;
  66. }
  67. /**
  68. * Returns the generator which is also known as the base point.
  69. * @return the generator which is also known as the base point.
  70. */
  71. public ECPoint getGenerator() {
  72. return g;
  73. }
  74. /**
  75. * Returns the order of the generator.
  76. * @return the order of the generator.
  77. */
  78. public BigInteger getOrder() {
  79. return n;
  80. }
  81. /**
  82. * Returns the cofactor.
  83. * @return the cofactor.
  84. */
  85. public int getCofactor() {
  86. return h;
  87. }
  88. }