gpt4 book ai didi

encryption - 雅可比坐标中的椭圆曲线相加

转载 作者:行者123 更新时间:2023-12-02 04:56:33 26 4
gpt4 key购买 nike

我尝试在素域上的椭圆曲线上添加两个点,将这些点从仿射/仿射坐标转换,但没有得到正确的结果(我正在测试的曲线有 a=0)。任何人都可以看到有什么问题吗?

// 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));

最佳答案

CodesInChaos 说:

The division can't be right. You need to compute the multiplicative inverse modulo FIELD. This operation is quite expensive, and should only be performed once at the end of a scalar multiplication, not after each doubling/addition. Use z^{-1} = ModPow(z, FIELD-2, FIELD).

关于encryption - 雅可比坐标中的椭圆曲线相加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21463018/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com