Title: Please point me to the code that generates new bitcoin addresses. Post by: hello_good_sir on May 07, 2013, 08:56:54 PM 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. Title: Re: Please point me to the code that generates new bitcoin addresses. Post by: bukaj on May 07, 2013, 09:03:10 PM Here (https://github.com/brainwallet/brainwallet.github.com) you can find some code in JS.
Title: Re: Please point me to the code that generates new bitcoin addresses. Post by: DannyHamilton on May 07, 2013, 09:26:29 PM Is this what you're looking for?
https://github.com/bitcoin/bitcoin/blob/master/src/wallet.cpp#L30 Title: Re: Please point me to the code that generates new bitcoin addresses. Post by: bitcool on May 07, 2013, 09:38:24 PM https://github.com/bitcoin/bitcoin/blob/master/src/util.cpp#L147 (https://github.com/bitcoin/bitcoin/blob/master/src/util.cpp#L147)
Title: Re: Please point me to the code that generates new bitcoin addresses. Post by: hello_good_sir on May 07, 2013, 10:07:37 PM Is this what you're looking for? https://github.com/bitcoin/bitcoin/blob/master/src/wallet.cpp#L30 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. Title: Re: Please point me to the code that generates new bitcoin addresses. Post by: DannyHamilton on May 07, 2013, 10:18:08 PM Is this what you're looking for? https://github.com/bitcoin/bitcoin/blob/master/src/wallet.cpp#L30 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 Title: Re: Please point me to the code that generates new bitcoin addresses. Post by: DannyHamilton on May 07, 2013, 10:24:05 PM 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 Title: Re: Please point me to the code that generates new bitcoin addresses. Post by: hello_good_sir on May 07, 2013, 11:49:50 PM 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. Title: Re: Please point me to the code that generates new bitcoin addresses. Post by: calian on May 08, 2013, 12:02:19 AM 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 Title: Re: Please point me to the code that generates new bitcoin addresses. Post by: DannyHamilton on May 08, 2013, 01:36:54 AM 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 Followed by: Code: EC_POINT_mul 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 |