Pergunta

I am trying to implement a scalar multiplication over a prime field for P192r1. Point addition works fine by using the code borrowed from java Scalar Multiplication

But concerning Point doubling where I used Code again from that link, it does not come to the right result. I tried to find the mistake but I couldn't find it. Has anyone already solved this mistake.

 `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;
    }`
Foi útil?

Solução

The original code added 3 in this line

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

But it should be adding a, so replace it with this line

slope = slope.add(a);

where a is

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

Then you'll get

Doubling is correct

when you run main function.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top