Post
Topic
Board Beginners & Help
Merits 6 from 3 users
Re: What is Elliptic Curve Cryptography? Understand how is it related to Bitcoin.
by
webtricks
on 19/03/2020, 16:15:45 UTC
⭐ Merited by Welsh (4) ,pooya87 (1) ,Heisenberg_Hunter (1)

3. Let's say, our Binary representation have 256 characters then we have to apply ECMultiply formula 256 times. ECMultiply involves applying ECDouble on G point and then if the binary character is 1, apply ECAdd formula on the resulting value. Else if binary character is 0, ignore ECAdd and move to next character.
this part doesn't sound right to me. there are different methods of calculating point multiplication, this method you are describing sounds like the Double and Add method in reverse in all of these methods you start from zero (or point at infinity) double the result and add G instead of doubling G and adding result.
from Wikipedia (P is generator):
Code:
  Q ← 0
  for i from m down to 0 do
     Q ← point_double(Q)
     if di = 1 then
         Q ← point_add(Q, P)
  return Q

There are actually two ways you can apply double and add method. You have already mentioned one above i.e. when index is decreasing. However, there is another when index is increasing. The other one from the same Wikipedia (P is generator):

Code:
  N ← P
  Q ← 0
  for i from 0 to m do
     if di = 1 then
         Q ← point_add(Q, N)
     N ← point_double(N)
  return Q

This formula is also starting from index number 0 but my formula is absolutely correct because in first step Q is 0 so point_add(Q,N) will return N. So the return value of Q after first iteration will be N while the return value of N will be double N. In next iteration (when index is 1), the values which will go in point_add will be:

Q ← point_add(N, point_double(N)).

This is similar if we omit first iteration and double N (generator point) before starting the loop.

Now compare with my formula which I posted in other thread (I remember you objected this issue there too):

Code:
const ECMultiply = (genPoint, pvtKey) => {
        const scalarBinary = BigInt('0x'+pvtKey).toString(2);
        let GP = genPoint;

        for (let i=1; i < scalarBinary.length; i++) {
            GP = ECDouble(GP)
            if (scalarBinary[i] === '1') {
                GP = ECAdd(GP, genPoint);
            }
        }
        return GP;
    }

I hope it is clear now.