1

我正在尝试在 P192r1 的素数字段上实现标量乘法。通过使用从java Scalar Multiplication借来的代码,点加法工作得很好

但是关于我从那个链接再次使用代码的点加倍,它没有得到正确的结果。我试图找出错误,但我找不到。有没有人已经解决了这个错误。

 `public static ECPoint doublePoint(ECPoint r) {
        // TODO Auto-generated method stub

 BigInteger ONE = new BigInteger("1");;
 BigInteger TWO = new BigInteger("2");
 BigInteger p = new BigInteger("6277101735386680763835789423207666416083908700390324961279");

        BigInteger slope = (r.getAffineX().pow(2)).multiply(new BigInteger("3"));

        slope = slope.add(new BigInteger("3"));
        slope = slope.multiply((r.getAffineY().multiply(TWO)).modInverse(p));
        BigInteger Xout = slope.pow(2).subtract(r.getAffineX().multiply(new BigInteger("2"))).mod(p);
        BigInteger Yout = (r.getAffineY().negate()).add(slope.multiply(r.getAffineX().subtract(Xout))).mod(p);
        ECPoint out = new ECPoint(Xout, Yout);
        return out;
    }`
4

1 回答 1

2

原代码在这一行加了3

slope = slope.add(new BigInteger("3"));

但它应该是添加a的,所以用这一行替换它

slope = slope.add(a);

a在哪里

static BigInteger a = new BigInteger("6277101735386680763835789423207666416083908700390324961276");

然后你会得到

Doubling is correct

当您运行主要功能时。

于 2013-11-12T09:09:50.733 回答