楕円加算機

package x3_1;

import java.math.BigInteger;
import java.security.spec.ECPoint;

//this is an adder for addition in the point of elictip carve 
//elictip curve is set for y^3=x^2+Ax+B

public class Elictip_Adder {
	static BigInteger A, B, p;

	static BigInteger x1, x2, y1, y2;

	static BigInteger lamda;

	static BigInteger x3, y3;

	static ECPoint Q;

	static BigInteger[] returnPoint = new BigInteger[2];

	public static ECPoint ECpointAdder(BigInteger A, BigInteger B, BigInteger p,ECPoint P1,
			ECPoint P2) {
		setA(A);
		setB(B);
		setP(p);
		setX1(P1.getAffineX());
		setX2(P2.getAffineX());
		setY1(P1.getAffineY());
		setY2(P2.getAffineY());

		addPoint();
		Q = new ECPoint(x3, y3);
		return Q;
	}

	public static BigInteger[] pointAdder(BigInteger A, BigInteger B,
			BigInteger x1, BigInteger x2, BigInteger y1, BigInteger y2) {
		setA(A);
		setB(B);
		setX1(x1);
		setX2(x2);
		setY1(y1);
		setY2(y2);

		addPoint();
		return returnPoint;
	}

	public static BigInteger[] addPoint() {
		if (!x1.equals(x2)) {
			// x1!=x2
			lamda = (y2.subtract(y1)).multiply((x2.subtract(x1)).modInverse(p));
			// lamda=(y2-y1)/(x2-x1)
			x3 = (lamda.multiply(lamda)).subtract(x1.add(x2)).mod(p);
			// x3=lamuda^2-x1-x2
			y3 = lamda.multiply(x1.subtract(x3)).subtract(y1).mod(p);
			// y2=lamda(x1-x3)-y1
		} else if (!y1.equals(y2)) {
			// x1=x2,y1!=y2 -> P1+P2=infinite. return 0;
			x3 = new BigInteger("0");
			y3 = x3;
		} else if (!y1.equals(new BigInteger("0"))) {
			// P1=P2,y1!=0
			lamda = (x1.multiply(x1.multiply(new BigInteger("3")))
					.add(new BigInteger(A.toString()))).multiply((y1.add(y1)).modInverse(p));
			System.out.println("lamda :" + lamda);
			// lamda=(3x1^2+A)/2y1
			x3 = lamda.multiply(lamda).subtract(
					x1.multiply(new BigInteger("2"))).mod(p);
			// x3=lamda^2-2x1
			y3 = lamda.multiply(x1.subtract(x3)).subtract(y1).mod(p);
			// y3=lamda(x1-x3)-y1
		} else {
			// P1=P2,y1=0 -> P1+P2=infinite. return 0;
			x3 = new BigInteger("0");
			y3 = x3;
		}

		returnPoint[0] = x3;
		returnPoint[1] = y3;
		return returnPoint;
	}

	public static BigInteger getA() {
		return A;
	}

	public static void setA(BigInteger a) {
		A = a;
	}

	public static BigInteger getB() {
		return B;
	}

	public static void setB(BigInteger b) {
		B = b;
	}

	public static BigInteger getLamda() {
		return lamda;
	}

	public static BigInteger[] getReturnPoint() {
		return returnPoint;
	}

	public static BigInteger getX1() {
		return x1;
	}

	public static void setX1(BigInteger x1) {
		Elictip_Adder.x1 = x1;
	}

	public static BigInteger getX2() {
		return x2;
	}

	public static void setX2(BigInteger x2) {
		Elictip_Adder.x2 = x2;
	}

	public static BigInteger getX3() {
		return x3;
	}

	public static BigInteger getY1() {
		return y1;
	}

	public static void setY1(BigInteger y1) {
		Elictip_Adder.y1 = y1;
	}

	public static BigInteger getY2() {
		return y2;
	}

	public static void setY2(BigInteger y2) {
		Elictip_Adder.y2 = y2;
	}

	public static BigInteger getY3() {
		return y3;
	}

	public static BigInteger getP() {
		return p;
	}

	public static void setP(BigInteger p) {
		Elictip_Adder.p = p;
	}
}