KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)ECPoint.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
11 /**
12  * This immutable class represents a point on an elliptic curve (EC)
13  * in affine coordinates. Other coordinate systems can
14  * extend this class to represent this point in other
15  * coordinates.
16  *
17  * @author Valerie Peng
18  * @version 1.3, 12/19/03
19  *
20  * @since 1.5
21  */

22 public class ECPoint {
23
24     private final BigInteger JavaDoc x;
25     private final BigInteger JavaDoc y;
26
27     /**
28      * This defines the point at infinity.
29      */

30     public static final ECPoint JavaDoc POINT_INFINITY = new ECPoint JavaDoc();
31
32     // private constructor for constructing point at infinity
33
private ECPoint() {
34     this.x = null;
35     this.y = null;
36     }
37
38     /**
39      * Creates an ECPoint from the specified affine x-coordinate
40      * <code>x</code> and affine y-coordinate <code>y</code>.
41      * @param x the affine x-coordinate.
42      * @param y the affine y-coordinate.
43      * @exception NullPointerException if <code>x</code> or
44      * <code>y</code> is null.
45      */

46     public ECPoint(BigInteger JavaDoc x, BigInteger JavaDoc y) {
47     if ((x==null) || (y==null)) {
48         throw new NullPointerException JavaDoc("affine coordinate x or y is null");
49     }
50     this.x = x;
51     this.y = y;
52     }
53
54     /**
55      * Returns the affine x-coordinate <code>x</code>.
56      * Note: POINT_INFINITY has a null affine x-coordinate.
57      * @return the affine x-coordinate.
58      */

59     public BigInteger JavaDoc getAffineX() {
60     return x;
61     }
62
63     /**
64      * Returns the affine y-coordinate <code>y</code>.
65      * Note: POINT_INFINITY has a null affine y-coordinate.
66      * @return the affine y-coordinate.
67      */

68     public BigInteger JavaDoc getAffineY() {
69     return y;
70     }
71
72     /**
73      * Compares this elliptic curve point for equality with
74      * the specified object.
75      * @param obj the object to be compared.
76      * @return true if <code>obj</code> is an instance of
77      * ECPoint and the affine coordinates match, false otherwise.
78      */

79     public boolean equals(Object JavaDoc obj) {
80     if (this == obj) return true;
81     if (this == POINT_INFINITY) return false;
82     if (obj instanceof ECPoint JavaDoc) {
83         return ((x.equals(((ECPoint JavaDoc)obj).x)) &&
84             (y.equals(((ECPoint JavaDoc)obj).y)));
85     }
86     return false;
87     }
88
89     /**
90      * Returns a hash code value for this elliptic curve point.
91      * @return a hash code value.
92      */

93     public int hashCode() {
94     if (this == POINT_INFINITY) return 0;
95     return x.hashCode() << 5 + y.hashCode();
96     }
97 }
98
Popular Tags