简体   繁体   English

在Java中使用double和add方法实现点乘法

[英]Point multiplication implementation using double and add method in java

I'm trying to implement the double and add method of scalar multiplication of ECDSA based on the pseudo code below: 我正在尝试基于以下伪代码实现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

And here is my java code: 这是我的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;
}

} }

But the signature verification is always failed (I am sure there are no mistakes in other codes), what is the problem here? 但是签名验证总是失败的(我确定其他代码没有错误),这是什么问题? Is the pseudo code correct? 伪代码正确吗? If it is, what's wrong with my code? 如果是,我的代码有什么问题?

Due to the lack of code you provided it is the best java code possible to implement your algorithm. 由于您提供的代码不足,因此是实现算法的最佳Java代码。 Your code was containing logical errors. 您的代码包含逻辑错误。

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM