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?

Hamid Naghipour
  • 208
  • 1
  • 9
  • 1
    Read [this](https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication). You have to multiply key by the **point** G which is a special process to make it irreversible. – Coding Enthusiast Apr 03 '20 at 07:43
  • @CodingEnthusiast : I know it. So I wrote in my question. private key * G. Is this wrong way to multiply those like two hex numbers? – Hamid Naghipour Apr 03 '20 at 07:59
  • 1
    @Hamid You have clearly not read it. G is not a number, and the multiplication here is nothing like big integer multiplication. It's an elliptic curve point, and you need elliptic curve multiplication. – Pieter Wuille Apr 03 '20 at 08:11
  • @PieterWuille Thank you. Could you please give me a good resource that explaining this clearly? I was totally confused :( – Hamid Naghipour Apr 03 '20 at 08:19
  • 1
    The entire article CodingEnthousiast linked to is about elliptic curve multiplication. It's not a simple operation. – Pieter Wuille Apr 03 '20 at 08:21
  • @PieterWuille As a developer I wanted to create a function for this to calculate public key from private key and I thought it's like 2 * 2 = 4. As you told it's not like this. Is there any online tools that we give it private key and it calculate K=k*G ? – Hamid Naghipour Apr 03 '20 at 08:27
  • 1
    As a developer, see https://bitcoin.stackexchange.com/questions/25024/how-do-you-get-a-bitcoin-public-key-from-a-private-key . For an online tool, google online calculator secp256k1 key -> https://paulmillr.com/ecc/ which gives the specified result for your example. – dave_thompson_085 Apr 03 '20 at 08:58
  • 2
    Does this answer your question? [How do you get a Bitcoin Public Key from a Private Key](https://bitcoin.stackexchange.com/questions/25024/how-do-you-get-a-bitcoin-public-key-from-a-private-key) – Pieter Wuille Apr 03 '20 at 09:12
  • @PieterWuille, Thank you for your help. I added an answer to clear about k=k*g. – Hamid Naghipour Apr 07 '20 at 07:45
  • @dave_thompson_085 Thank you for you help. I read all your links and I added an answer to fix my fault. – Hamid Naghipour Apr 07 '20 at 07:48
  • @CodingEnthusiast Thank you for you help, I lost this page and it was the lost ring. I added an answer to fix my fault. – Hamid Naghipour Apr 07 '20 at 07:49

2 Answers2

2

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.

David Schwartz
  • 51,308
  • 6
  • 106
  • 177
  • 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 03 '20 at 09: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 03 '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 04 '20 at 07:13
  • Thank you for your help. I added the answer that I needed it. – Hamid Naghipour Apr 07 '20 at 08:03
  • could you please answer my question: https://bitcoin.stackexchange.com/questions/95676/how-to-getheaders-from-blockchain – Hamid Naghipour May 03 '20 at 09: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

Hamid Naghipour
  • 208
  • 1
  • 9