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
56 if (p.compareTo(c) != 1) {
57 throw new IllegalArgumentException(cName + " is too large");
58 } else if (c.signum() < 0) {
59 throw new IllegalArgumentException(cName + " is negative");
60 }
61 } else if (field instanceof ECFieldF2m) {
62 int m = ((ECFieldF2m)field).getM();
63 if (c.bitLength() > m) {
64 throw new IllegalArgumentException(cName + " is too large");
65 }
66 }
67 }
68
69 /**
70 * Creates an elliptic curve with the specified elliptic field
71 * {@code field} and the coefficients {@code a} and
72 * {@code b}.
73 * @param field the finite field that this elliptic curve is over.
74 * @param a the first coefficient of this elliptic curve.
75 * @param b the second coefficient of this elliptic curve.
76 * @exception NullPointerException if {@code field},
77 * {@code a}, or {@code b} is null.
78 * @exception IllegalArgumentException if {@code a}
79 * or {@code b} is not null and not in {@code field}.
80 */
81 public EllipticCurve(ECField field, BigInteger a,
82 BigInteger b) {
83 this(field, a, b, null);
84 }
85
86 /**
87 * Creates an elliptic curve with the specified elliptic field
88 * {@code field}, the coefficients {@code a} and
89 * {@code b}, and the {@code seed} used for curve generation.
90 * @param field the finite field that this elliptic curve is over.
91 * @param a the first coefficient of this elliptic curve.
92 * @param b the second coefficient of this elliptic curve.
93 * @param seed the bytes used during curve generation for later
94 * validation. Contents of this array are copied to protect against
95 * subsequent modification.
96 * @exception NullPointerException if {@code field},
97 * {@code a}, or {@code b} is null.
98 * @exception IllegalArgumentException if {@code a}
99 * or {@code b} is not null and not in {@code field}.
100 */
101 public EllipticCurve(ECField field, BigInteger a,
102 BigInteger b, byte[] seed) {
103 if (field == null) {
104 throw new NullPointerException("field is null");
105 }
106 if (a == null) {
107 throw new NullPointerException("first coefficient is null");
108 }
109 if (b == null) {
110 throw new NullPointerException("second coefficient is null");
111 }
112 checkValidity(field, a, "first coefficient");
113 checkValidity(field, b, "second coefficient");
114 this.field = field;
115 this.a = a;
116 this.b = b;
117 if (seed != null) {
118 this.seed = seed.clone();
|
1 /*
2 * Copyright (c) 2003, 2019, 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
56 if (p.compareTo(c) != 1) {
57 throw new IllegalArgumentException(cName + " is too large");
58 } else if (c.signum() < 0) {
59 throw new IllegalArgumentException(cName + " is negative");
60 }
61 } else if (field instanceof ECFieldF2m) {
62 int m = ((ECFieldF2m)field).getM();
63 if (c.bitLength() > m) {
64 throw new IllegalArgumentException(cName + " is too large");
65 }
66 }
67 }
68
69 /**
70 * Creates an elliptic curve with the specified elliptic field
71 * {@code field} and the coefficients {@code a} and
72 * {@code b}.
73 * @param field the finite field that this elliptic curve is over.
74 * @param a the first coefficient of this elliptic curve.
75 * @param b the second coefficient of this elliptic curve.
76 * @throws NullPointerException if {@code field},
77 * {@code a}, or {@code b} is null.
78 * @throws IllegalArgumentException if {@code a}
79 * or {@code b} is not null and not in {@code field}.
80 */
81 public EllipticCurve(ECField field, BigInteger a,
82 BigInteger b) {
83 this(field, a, b, null);
84 }
85
86 /**
87 * Creates an elliptic curve with the specified elliptic field
88 * {@code field}, the coefficients {@code a} and
89 * {@code b}, and the {@code seed} used for curve generation.
90 * @param field the finite field that this elliptic curve is over.
91 * @param a the first coefficient of this elliptic curve.
92 * @param b the second coefficient of this elliptic curve.
93 * @param seed the bytes used during curve generation for later
94 * validation. Contents of this array are copied to protect against
95 * subsequent modification.
96 * @throws NullPointerException if {@code field},
97 * {@code a}, or {@code b} is null.
98 * @throws IllegalArgumentException if {@code a}
99 * or {@code b} is not null and not in {@code field}.
100 */
101 public EllipticCurve(ECField field, BigInteger a,
102 BigInteger b, byte[] seed) {
103 if (field == null) {
104 throw new NullPointerException("field is null");
105 }
106 if (a == null) {
107 throw new NullPointerException("first coefficient is null");
108 }
109 if (b == null) {
110 throw new NullPointerException("second coefficient is null");
111 }
112 checkValidity(field, a, "first coefficient");
113 checkValidity(field, b, "second coefficient");
114 this.field = field;
115 this.a = a;
116 this.b = b;
117 if (seed != null) {
118 this.seed = seed.clone();
|