1 /* 2 * Copyright (c) 2018, 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 23 * questions. 24 */ 25 package sun.security.ec.point; 26 27 import sun.security.util.math.ImmutableIntegerModuloP; 28 29 import java.util.Objects; 30 31 /** 32 * Elliptic curve point represented using affine coordinates (x, y). This class 33 * is not part of the sun.security.ec.point.Point hierarchy because it is not 34 * used to hold intermediate values during point arithmetic, and so it does not 35 * have a mutable form. 36 */ 37 public class AffinePoint { 38 39 private final ImmutableIntegerModuloP x; 40 private final ImmutableIntegerModuloP y; 41 42 public AffinePoint(ImmutableIntegerModuloP x, ImmutableIntegerModuloP y) { 43 this.x = x; 44 this.y = y; 45 } 46 47 public ImmutableIntegerModuloP getX() { 48 return x; 49 } 50 51 public ImmutableIntegerModuloP getY() { 52 return y; 53 } 54 55 @Override 56 public boolean equals(Object obj) { 57 if (!(obj instanceof AffinePoint)) { 58 return false; 59 } 60 AffinePoint p = (AffinePoint) obj; 61 boolean xEquals = x.asBigInteger().equals(p.x.asBigInteger()); 62 boolean yEquals = y.asBigInteger().equals(p.y.asBigInteger()); 63 return xEquals && yEquals; 64 } 65 66 @Override 67 public int hashCode() { 68 return Objects.hash(x, y); 69 } 70 71 @Override 72 public String toString() { 73 return "(" + x.asBigInteger().toString() + "," + 74 y.asBigInteger().toString() + ")"; 75 } 76 }