3
我嘗試在素數場上的橢圓曲線上添加兩個點,將這些點從仿射/仿射座標轉換,但無法設法得到正確的結果(我正在測試的曲線有一個= 0)。任何人都可以看到有什麼問題?Jacobian座標中的橢圓曲線加法
// From Affine
BigInteger X1=P.x;
BigInteger Y1=P.y;
BigInteger Z1=BigInteger.ONE;
BigInteger X2=Q.x;
BigInteger Y2=Q.y;
BigInteger Z2=BigInteger.ONE;
// Point addition in Jacobian coordinates for a=0
// see http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#addition-add-2007-bl
BigInteger Z1Z1 = Z1.multiply(Z1);
BigInteger Z2Z2 = Z2.multiply(Z2);
BigInteger U1 = X1.multiply(Z2Z2);
BigInteger U2 = X2.multiply(Z1Z1);
BigInteger S1 = Y1.multiply(Z2).multiply(Z2Z2);
BigInteger S2 = Y2.multiply(Z1).multiply(Z1Z1);
BigInteger H = U2.subtract(U1);
BigInteger I = H.add(H).multiply(H.add(H));
BigInteger J = H.multiply(I);
BigInteger r = S2.subtract(S1).add(S2.subtract(S1));
BigInteger V = U1.multiply(I);
BigInteger X3 = r.multiply(r).subtract(J).subtract(V.add(V)).mod(FIELD);
BigInteger Y3 = r.multiply(V.subtract(X3)).subtract(S1.add(S1).multiply(J)).mod(FIELD);
BigInteger Z3 = Z1.add(Z2).multiply(Z1.add(Z2)).subtract(Z1Z1).subtract(Z2Z2).multiply(H).mod(FIELD);
//To affine
BigInteger Z3Z3 = Z3.multiply(Z3);
BigInteger Z3Z3Z3 = Z3Z3.multiply(Z3);
return new Point(X3.divide(Z3Z3),Y3.divide(Z3Z3Z3));
驗證...'BigInteger.ONE == 1',是否正確?所以'Z1Z1 = Z1^2 = 1 = Z2Z2 = Z2^2 = 1' ...然後'U1 = X1','U2 = X2','S1 = Y1',等等......我錯過了什麼? – abiessu
該部門不對。您需要計算乘法反模「FIELD」。這種操作非常昂貴,並且應該只在標量乘法結束時執行一次,而不是在每次加倍/加法之後執行一次。使用'z^{ - 1} = ModPow(z,FIELD-2,FIELD)' – CodesInChaos
是的,BigIntegerOne == 1.事實上,乘法逆應該用來代替除法。接得好。我會嘗試一下並報告會發生什麼。 – user1454590