2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
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
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
package java.security.spec;
|
|
26 |
|
|
27 |
import java.math.BigInteger;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* This immutable class specifies the set of domain parameters
|
|
31 |
* used with elliptic curve cryptography (ECC).
|
|
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;
|
|
78 |
this.n = n;
|
|
79 |
this.h = h;
|
|
80 |
}
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Returns the elliptic curve that this parameter defines.
|
|
84 |
* @return the elliptic curve that this parameter defines.
|
|
85 |
*/
|
|
86 |
public EllipticCurve getCurve() {
|
|
87 |
return curve;
|
|
88 |
}
|
|
89 |
|
|
90 |
/**
|
|
91 |
* Returns the generator which is also known as the base point.
|
|
92 |
* @return the generator which is also known as the base point.
|
|
93 |
*/
|
|
94 |
public ECPoint getGenerator() {
|
|
95 |
return g;
|
|
96 |
}
|
|
97 |
|
|
98 |
/**
|
|
99 |
* Returns the order of the generator.
|
|
100 |
* @return the order of the generator.
|
|
101 |
*/
|
|
102 |
public BigInteger getOrder() {
|
|
103 |
return n;
|
|
104 |
}
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Returns the cofactor.
|
|
108 |
* @return the cofactor.
|
|
109 |
*/
|
|
110 |
public int getCofactor() {
|
|
111 |
return h;
|
|
112 |
}
|
|
113 |
}
|