1

According to this answer: https://bitcoin.stackexchange.com/a/63996/100526 When he wants to generate a public key from the private key, he has used K=k*G. but I can't understand it's result. If we assume our private key is (according to the answer) :

0F479245FB19A38A1954C5C7C0EBAB2F9BDFD96A17563EF28A6A4B1A2A764EF4

and according to Secp256k1 G point is:

- Compressed form (prefix 02)
02 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9 59F2815B 16F81798 

 - Uncompressed form (prefix 04)
04 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9 59F2815B 16F81798
483ADA77 26A3C465 5DA4FBFC 0E1108A8 FD17B448 A6855419 9C47D08F FB10D4B8 

So to calculate the public key I used this site: https://www.boxentriq.com/code-breaking/big-number-calculator

I used compressed form and private key: 0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798 * 0F479245FB19A38A1954C5C7C0EBAB2F9BDFD96A17563EF28A6A4B1A2A764EF4

and result is :

25d355ebb23e6ce0fd5463bf40e6da2ccc4e2e8ce654db6a8a8e5a275f0d2266005569112cfda60d14f9b6d0c0218cc072047a3b2fcf97aee95a437b4bb6cce0

but in that answer the result is :

02E8445082A72F29B75CA48748A914DF60622A609CACFCE8ED0E35804560741D29

what's wrong?

1

When talking about math using a curve, when we use terms like addition and multiplication, we don't mean normal additional and multiplication. We are referring to operations on the curve that have properties similar to addition and multiplication. To get the correct results, you have to use the actual operations on the curve, not normal addition and multiplication.

  • Ok thank you,I got it. but in how we calculate it in the computers view? I know about it if we have a point like A and another point like B, with add these two we will have C, and if we reverse c in X line we will have another point. Or about multiplication in the Math view. I want to know how can I write a function that get Private key as input and give us public key as output? All we have in computers like 2*2=4 and I can't find relation between these. – Hamid Naghipour Apr 3 '20 at 9:57
  • 1
    @HamidNaghipour You need a tool that specifically does secp256k1 point addition at least. Then you can do multiplication by repeated addition. For example, you can compute 9*k by adding k to itself (giving 2*k), then adding that result to itself (giving 4*k), then adding that result to itself (giving 8*k), then adding k to that result (giving 9*k). – David Schwartz Apr 3 '20 at 17:51
  • after many researches on this topic, I got it. Now I'm looking a way how to create a function that does point addition. Could you please edit your answer? I want to accept it with these extra information. Thanks a lot. – Hamid Naghipour Apr 4 '20 at 7:13
  • Thank you for your help. I added the answer that I needed it. – Hamid Naghipour Apr 7 '20 at 8:03
  • could you please answer my question: bitcoin.stackexchange.com/questions/95676/… – Hamid Naghipour May 3 '20 at 9:42
1
It was my fault.

G is a point on the Elliptic curve. It means G has a number for X and another one for Y. so uncompressed G in Secp256k1 is G(x,y):

- Uncompressed form (prefix 04)
04 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9 59F2815B 16F81798
483ADA77 26A3C465 5DA4FBFC 0E1108A8 FD17B448 A6855419 9C47D08F FB10D4B8 

X = 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9 59F2815B 16F81798

Y = 483ADA77 26A3C465 5DA4FBFC 0E1108A8 FD17B448 A6855419 9C47D08F FB10D4B8 

And 04 to show this is an uncompressed form of G.

This point is Base point or Generator point that it used in k=K*G.

* is not like * in math like 2*2 = 4. It is a sign to show one of operators on curve.

we have 3 operators on a curve :

-Addition
-Negation
-Doubling

Addition is for add two points. According to we have a point like P1(x1,x2), and another point like Q1(x2,y2), so we can't use 2+2 = 4, we need some other calculation for P+Q. The result of P+Q is another point on the curve that we can call it R.

Doubling is double a point on the curve, and the result of this is a point on the curve too. so P+P=R.

When we say k*G, we want to multiple our private key to a point on the curve.

We need to do these : Convert our private key to binary base.

With a for on all bits we start to check: For each of this bits we do some doublePoint and addPoints. This is a predefined role and we have to follow it.

But how we can calculate a addition of two points?

λ = ( yq – yp ) / ( xq – xp)
xR = λ2 – xp – xq
yR = λ(xp – xR) – yP

With this. first we need to calculate λ, it is our slope.

Then we can calculate our x and y for new point. and the result is our

p+q = R

and what about doubling?:

λ = (3x2) +a / (2y) 
xR = λ2 - 2x 
yR = λ(x - xR) – y

with these, now we can calculate K=k * G.

There are many other tips to calculate Public key from Private key.

This one is a good implementation in PHP: https://github.com/BitcoinPHP/BitcoinECDSA.php/blob/master/src/BitcoinPHP/BitcoinECDSA/BitcoinECDSA.php#L350

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.