Title: get address from private key Post by: gimme_bottles on December 08, 2011, 11:30:13 PM hey,
i am searching for a documentation describing the process of calculation the corresponding bitcoin address from a private key. does anyone has a link to such a document? gimme_bottles Title: Re: get address from private key Post by: MelMan2002 on December 08, 2011, 11:41:43 PM https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses
Title: Re: get address from private key Post by: gimme_bottles on December 08, 2011, 11:57:01 PM i read that article, but i don't get how to get the address from a private key, i only see the generation process of a bitcoin address.
Title: Re: get address from private key Post by: casascius on December 09, 2011, 12:21:57 AM i read that article, but i don't get how to get the address from a private key, i only see the generation process of a bitcoin address. From the private key, you get the public key. From the public key, you can get the address, based on the steps in the article. Are you wondering how to get the public key from the private key? Title: Re: get address from private key Post by: gimme_bottles on December 09, 2011, 08:17:01 AM Are you wondering how to get the public key from the private key? yes, i am missing that step :) Title: Re: get address from private key Post by: casascius on December 09, 2011, 08:32:46 AM Are you wondering how to get the public key from the private key? yes, i am missing that step :) You multiply the private key by the constant G. You can find G at https://en.bitcoin.it/wiki/Secp256k1. G is an elliptic curve point - not a simple number. So there is special math that redefines what "multiplying" is. A point times a number equals another point. You may or may not need to care about the intricate details of that math. If you are simply trying to write a program and are using crypto code from somewhere else, you simply call the already-defined "point multiply" function and get the answer. The answer comes as two numbers - X and Y - because it's a point on a sort of graph - and then you can plug them in to the instructions you see that explain how to go from a public key to a Bitcoin address. Title: Re: get address from private key Post by: gimme_bottles on December 10, 2011, 01:08:54 AM so, based on your help and openssl i hacked some code to calculate the address out of a randomly generated private key.
sadly it doesn't work as expected. this is my code, the reverse of the string in the base58-encoding function is still missing: Code: #include <stdio.h> my output looks the following, i also print some debug information: Code: Private Key: 1809c5d482b97ec84dd7e94cc4cbed460fd878025b52b1011970a3626e64eda8 all outputs are in HEX-format, except for the encoded address, that you have to reverse in your minds :) when i use bitcointools.appspot.com (http://bitcointools.appspot.com) to get the address from my private key, the result is different to mine... any suggestions? Title: Re: get address from private key Post by: casascius on December 10, 2011, 01:55:44 AM I looked not at your code, but your numbers.
The calculation from private key to public key is wrong. Why, I don't know. Private key 1809c5d482b97ec84dd7e94cc4cbed460fd878025b52b1011970a3626e64eda8 (I am assuming this is big-endian, like it usually is) shoudl have public key 04 AE 64 14 8F B6 68 4D 51 CF 03 C5 60 D7 36 28 2E 86 54 FB 54 D2 21 0D 67 4A F1 32 B1 ED 2D 2E 87 D0 B1 05 D0 97 5D C7 5C 31 91 CF 7E 64 ED FB 06 98 AF 85 7A 4A 0A BF 45 D0 06 01 00 9C 9E B8 8A which is 04 X = AE 64 14 8F B6 68 4D 51 CF 03 C5 60 D7 36 28 2E 86 54 FB 54 D2 21 0D 67 4A F1 32 B1 ED 2D 2E 87 Y = D0 B1 05 D0 97 5D C7 5C 31 91 CF 7E 64 ED FB 06 98 AF 85 7A 4A 0A BF 45 D0 06 01 00 9C 9E B8 8A calculated by a known working utility. Title: Re: get address from private key Post by: gimme_bottles on December 10, 2011, 02:16:07 AM yes, it is all big endian.
thanks for your example, it is great to have some values to work with :) Title: Re: get address from private key Post by: ByteCoin on December 10, 2011, 04:58:54 AM Code: printf("X: "); /* print both r and s for debug reasons */ There's a reason why the things you're printing out and calling X and Y are really called r and s. That's because r and s have nothing to do with elliptic curve coordinates. Read the wikipedia article for ECDSA for the details. Generating an address from a public key does not require ECDSA_do_sign or do_verify so you can get rid of that code. The coordinates are likely to be stored in the public key structure in some fashion. ByteCoin |