KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > security > spec > ECFieldFp


1 /*
2  * @(#)ECFieldFp.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
9 import java.math.BigInteger JavaDoc;
10 import java.util.Arrays JavaDoc;
11
12 /**
13  * This immutable class defines an elliptic curve (EC) prime
14  * finite field.
15  *
16  * @see ECField
17  *
18  * @author Valerie Peng
19  * @version 1.3, 12/19/03
20  *
21  * @since 1.5
22  */

23 public class ECFieldFp implements ECField JavaDoc {
24
25     private BigInteger JavaDoc p;
26
27     /**
28      * Creates an elliptic curve prime finite field
29      * with the specified prime <code>p</code>.
30      * @param p the prime.
31      * @exception NullPointerException if <code>p</code> is null.
32      * @exception IllegalArgumentException if <code>p</code>
33      * is not positive.
34      */

35     public ECFieldFp(BigInteger JavaDoc p) {
36     if (p.signum() != 1) {
37         throw new IllegalArgumentException JavaDoc("p is not positive");
38     }
39     this.p = p;
40     }
41
42     /**
43      * Returns the field size in bits which is size of prime p
44      * for this prime finite field.
45      * @return the field size in bits.
46      */

47     public int getFieldSize() {
48     return p.bitLength();
49     };
50
51     /**
52      * Returns the prime <code>p</code> of this prime finite field.
53      * @return the prime.
54      */

55     public BigInteger JavaDoc getP() {
56     return p;
57     }
58     
59     /**
60      * Compares this prime finite field for equality with the
61      * specified object.
62      * @param obj the object to be compared.
63      * @return true if <code>obj</code> is an instance
64      * of ECFieldFp and the prime value match, false otherwise.
65      */

66     public boolean equals(Object JavaDoc obj) {
67     if (this == obj) return true;
68     if (obj instanceof ECFieldFp JavaDoc) {
69         return (p.equals(((ECFieldFp JavaDoc)obj).p));
70     }
71     return false;
72     }
73      
74     /**
75      * Returns a hash code value for this prime finite field.
76      * @return a hash code value.
77      */

78     public int hashCode() {
79     return p.hashCode();
80     }
81 }
82
Popular Tags