我正在尝试实现基于以下伪代码的ECDSA标量乘法的double和add方法:
Algorithm 1 (Double-and-add)
input P
Q ← P
for i from l−2 to 0 do
Q ← 2Q
if i = 1 then Q ← Q + P
output Q
这是我的java代码:
public static ECPoint ScalarMulti(BigInteger ks, ECPoint G) {
String k = ks.toString(2);
ECPoint q = new ECPoint(zero, zero);
q = G;
for (int i = k.length() - 2; i >= 0; i--) {
q = DoublePoint(q);
if (k.substring(i, i + 1).equals("1")) {
q = Pointaddition(q, G);
}
}
return q;
}
}
但是签名验证总是失败(我确信其他代码没有错误),这里的问题是什么?伪代码是否正确?如果是,我的代码出了什么问题?
答案 0 :(得分:0)
由于缺少您提供的代码,因此它是实现您的算法的最佳Java代码。您的代码包含逻辑错误。
public static ECPoint ScalarMulti(BigInteger ks) {
ECPoint p = new ECPoint(zero, zero);
ECPoint q = p;
for (BigInteger i = obj.subtract(new BigInteger("2")); //initialization
i.compareTo(new BigInteger("0")) >= 0; // comparision
i = i.subtract(new BigInteger("1"))) { // increment
q = DoublePoint(q);
if (i.compareTo(new BigInteger("1")) {
q = Pointaddition(p, q);
}
}
return q;
}