Author

Topic: Please point me to the code that generates new bitcoin addresses. (Read 2125 times)

legendary
Activity: 3472
Merit: 4801
Thank you for taking the time to help me with this.

My goal is to have a short program that I can give 256 random bits to (which I am confident that I can generate by hand) and it will produce a bitcoin address and its private key.  I know how to program but I do not know much about cryptography.  I could try to write the key generation process but I would rather use proven code.  I was thinking about making the entire key pair by hand but then I realized that the hashing algorithm is far too computationally intensive to do by hand (as it should be)

Edit: thanks for the link.  I think that I'm going to have to read a lot more code than I thought I would.  I was hoping for a big ball of mud function that I could just change a little.

According to this discussion I just found:
http://openssl.6102.n7.nabble.com/Question-on-EC-KEY-generate-key-td27218.html

It sounds like you can use openssl and call:

Code:
EC_KEY_set_private_key
http://openssl.sourcearchive.com/documentation/1.0.0e-2/crypto_2ec_2ec_8h_ac71ebd801dd40f9b9c42b61aff685f3d.html#ac71ebd801dd40f9b9c42b61aff685f3d


Followed by:
Code:
EC_POINT_mul
http://openssl.sourcearchive.com/documentation/1.0.0e-2/crypto_2ec_2ec_8h_a5e5532068774ce6da8ca68ac627176a8.html#a5e5532068774ce6da8ca68ac627176a8


Once you have the public key, you can use the information here to generate an address:
https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses
sr. member
Activity: 354
Merit: 250
Thank you for taking the time to help me with this.

My goal is to have a short program that I can give 256 random bits to (which I am confident that I can generate by hand) and it will produce a bitcoin address and its private key.  I know how to program but I do not know much about cryptography.  I could try to write the key generation process but I would rather use proven code.  I was thinking about making the entire key pair by hand but then I realized that the hashing algorithm is far too computationally intensive to do by hand (as it should be)

Edit: thanks for the link.  I think that I'm going to have to read a lot more code than I thought I would.  I was hoping for a big ball of mud function that I could just change a little.

If you're just going to do this a few times use your random bits as a passphrase with one of the web-based address generators saved in offline mode.

http://brainwallet.org/
https://www.bitaddress.org/bitaddress.org-v2.4-SHA1-1d5951f6a04dd5a287ac925da4e626870ee58d60.html
hero member
Activity: 1008
Merit: 531
Thank you for taking the time to help me with this.

My goal is to have a short program that I can give 256 random bits to (which I am confident that I can generate by hand) and it will produce a bitcoin address and its private key.  I know how to program but I do not know much about cryptography.  I could try to write the key generation process but I would rather use proven code.  I was thinking about making the entire key pair by hand but then I realized that the hashing algorithm is far too computationally intensive to do by hand (as it should be)

Edit: thanks for the link.  I think that I'm going to have to read a lot more code than I thought I would.  I was hoping for a big ball of mud function that I could just change a little.
legendary
Activity: 3472
Merit: 4801
It sounds like for some reason you don't want to trust the well reviewed, tested, and industry accepted openssl to generate the keypair.  If that's true, then you probably don't want EC_KEY_generate_key, since that generates the pair (both private and public keys).

If for some reason, you'd rather trust your own ability to generate a random private key with enough entropy, then you might want to look at the section of code that imports private keys and calculates the public keys and/or bitcoin address.  This might be a good place to start:

https://github.com/bitcoin/bitcoin/blob/master/src/rpcdump.cpp#L35
legendary
Activity: 3472
Merit: 4801

That's a bit of a start.  I traced it back a bit, and I'm thinking that this EC_KEY_generate_key might be the function that I am looking for.  Is there an easy way to search across all of the files?  ctrl-f in my browser just searches within the current page.  I could download the whole source but I'd really rather not.

Ok, so:

CPubKey CWallet::GenerateNewKey() in wallet.dat

randomizes the seed with RandAddSeedPerfmon();

then it references key.MakeNewKey(fCompressed);


void CKey::MakeNewKey(bool fCompressed) in key.cpp

references EC_KEY_generate_key(pkey) which is a part of the openssl/ecdsa package as described here:
http://openssl.sourcearchive.com/documentation/1.0.0e-2/crypto_2ec_2ec_8h_a690c3227c776f6b53a004e22d03055da.html#a690c3227c776f6b53a004e22d03055da
hero member
Activity: 1008
Merit: 531

That's a bit of a start.  I traced it back a bit, and I'm thinking that this EC_KEY_generate_key might be the function that I am looking for.  Is there an easy way to search across all of the files?  ctrl-f in my browser just searches within the current page.  I could download the whole source but I'd really rather not.
legendary
Activity: 1441
Merit: 1000
Live and enjoy experiments
legendary
Activity: 3472
Merit: 4801
newbie
Activity: 28
Merit: 0
Here you can find some code in JS.
hero member
Activity: 1008
Merit: 531
I would like to look at the code that creates a random number, then makes a private key from that, then makes the address from that.

I looked here: https://github.com/bitcoin/bitcoin/tree/master/src

I checked in a few likely files and didn't see it.  I realized that I might not recognize it when I see it.  So please point me to the file name and function name.

My goal is to make an offline paper wallet generator where the user generates the random number by hand (by shuffling a deck of cards multiple times).  This way I will not have to trust the random number generator.  I don't want to trust anything except myself.  I will make the source code for my program available.
Jump to: