author | jboes |
Fri, 20 Sep 2019 11:07:52 +0100 | |
changeset 58242 | 94bb65cb37d3 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, 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 |
import java.util.Arrays; |
|
29 |
||
30 |
/** |
|
31 |
* This immutable class defines an elliptic curve (EC) prime |
|
32 |
* finite field. |
|
33 |
* |
|
34 |
* @see ECField |
|
35 |
* |
|
36 |
* @author Valerie Peng |
|
37 |
* |
|
38 |
* @since 1.5 |
|
39 |
*/ |
|
40 |
public class ECFieldFp implements ECField { |
|
41 |
||
42 |
private BigInteger p; |
|
43 |
||
44 |
/** |
|
45 |
* Creates an elliptic curve prime finite field |
|
18552
005e115dc6ee
8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents:
5506
diff
changeset
|
46 |
* with the specified prime {@code p}. |
2 | 47 |
* @param p the prime. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
47216
diff
changeset
|
48 |
* @throws NullPointerException if {@code p} is null. |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
47216
diff
changeset
|
49 |
* @throws IllegalArgumentException if {@code p} |
2 | 50 |
* is not positive. |
51 |
*/ |
|
52 |
public ECFieldFp(BigInteger p) { |
|
53 |
if (p.signum() != 1) { |
|
54 |
throw new IllegalArgumentException("p is not positive"); |
|
55 |
} |
|
56 |
this.p = p; |
|
57 |
} |
|
58 |
||
59 |
/** |
|
60 |
* Returns the field size in bits which is size of prime p |
|
61 |
* for this prime finite field. |
|
62 |
* @return the field size in bits. |
|
63 |
*/ |
|
64 |
public int getFieldSize() { |
|
65 |
return p.bitLength(); |
|
66 |
}; |
|
67 |
||
68 |
/** |
|
18552
005e115dc6ee
8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents:
5506
diff
changeset
|
69 |
* Returns the prime {@code p} of this prime finite field. |
2 | 70 |
* @return the prime. |
71 |
*/ |
|
72 |
public BigInteger getP() { |
|
73 |
return p; |
|
74 |
} |
|
75 |
||
76 |
/** |
|
77 |
* Compares this prime finite field for equality with the |
|
78 |
* specified object. |
|
79 |
* @param obj the object to be compared. |
|
18552
005e115dc6ee
8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents:
5506
diff
changeset
|
80 |
* @return true if {@code obj} is an instance |
2 | 81 |
* of ECFieldFp and the prime value match, false otherwise. |
82 |
*/ |
|
83 |
public boolean equals(Object obj) { |
|
84 |
if (this == obj) return true; |
|
85 |
if (obj instanceof ECFieldFp) { |
|
86 |
return (p.equals(((ECFieldFp)obj).p)); |
|
87 |
} |
|
88 |
return false; |
|
89 |
} |
|
90 |
||
91 |
/** |
|
92 |
* Returns a hash code value for this prime finite field. |
|
93 |
* @return a hash code value. |
|
94 |
*/ |
|
95 |
public int hashCode() { |
|
96 |
return p.hashCode(); |
|
97 |
} |
|
98 |
} |