1 /*
2 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
32 *
33 * @see AlgorithmParameterSpec
34 *
35 * @author Valerie Peng
36 *
37 * @since 1.5
38 */
39 public class ECParameterSpec implements AlgorithmParameterSpec {
40
41 private final EllipticCurve curve;
42 private final ECPoint g;
43 private final BigInteger n;
44 private final int h;
45
46 /**
47 * Creates elliptic curve domain parameters based on the
48 * specified values.
49 * @param curve the elliptic curve which this parameter
50 * defines.
51 * @param g the generator which is also known as the base point.
52 * @param n the order of the generator <code>g</code>.
53 * @param h the cofactor.
54 * @exception NullPointerException if <code>curve</code>,
55 * <code>g</code>, or <code>n</code> is null.
56 * @exception IllegalArgumentException if <code>n</code>
57 * or <code>h</code> is not positive.
58 */
59 public ECParameterSpec(EllipticCurve curve, ECPoint g,
60 BigInteger n, int h) {
61 if (curve == null) {
62 throw new NullPointerException("curve is null");
63 }
64 if (g == null) {
65 throw new NullPointerException("g is null");
66 }
67 if (n == null) {
68 throw new NullPointerException("n is null");
69 }
70 if (n.signum() != 1) {
71 throw new IllegalArgumentException("n is not positive");
72 }
73 if (h <= 0) {
74 throw new IllegalArgumentException("h is not positive");
75 }
76 this.curve = curve;
77 this.g = g;
|
1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
32 *
33 * @see AlgorithmParameterSpec
34 *
35 * @author Valerie Peng
36 *
37 * @since 1.5
38 */
39 public class ECParameterSpec implements AlgorithmParameterSpec {
40
41 private final EllipticCurve curve;
42 private final ECPoint g;
43 private final BigInteger n;
44 private final int h;
45
46 /**
47 * Creates elliptic curve domain parameters based on the
48 * specified values.
49 * @param curve the elliptic curve which this parameter
50 * defines.
51 * @param g the generator which is also known as the base point.
52 * @param n the order of the generator {@code g}.
53 * @param h the cofactor.
54 * @exception NullPointerException if {@code curve},
55 * {@code g}, or {@code n} is null.
56 * @exception IllegalArgumentException if {@code n}
57 * or {@code h} is not positive.
58 */
59 public ECParameterSpec(EllipticCurve curve, ECPoint g,
60 BigInteger n, int h) {
61 if (curve == null) {
62 throw new NullPointerException("curve is null");
63 }
64 if (g == null) {
65 throw new NullPointerException("g is null");
66 }
67 if (n == null) {
68 throw new NullPointerException("n is null");
69 }
70 if (n.signum() != 1) {
71 throw new IllegalArgumentException("n is not positive");
72 }
73 if (h <= 0) {
74 throw new IllegalArgumentException("h is not positive");
75 }
76 this.curve = curve;
77 this.g = g;
|