我正在尝试在P192r1的素数域上实现标量乘法。通过使用从java Scalar Multiplication
借来的代码,点加法工作正常但是关于点加倍我从该链接再次使用Code的地方,它没有得到正确的结果。我试图找到错误,但我找不到它。有谁已经解决了这个错误。
`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;
}`
答案 0 :(得分:2)
原始代码在此行中添加了3
slope = slope.add(new BigInteger("3"));
但它应该添加a
,因此请用此行替换
slope = slope.add(a);
其中a
是
static BigInteger a = new BigInteger("6277101735386680763835789423207666416083908700390324961276");
然后你会得到
Doubling is correct
运行main函数时。