Hi,
I'm working on a site that will *just* use bitcoin for the means of commerce.
I'm writing the code myself because - hey, it's fun - but also because it is a form of security through obscurity. The less my codebase has in common with other sites the less likely an exploitable flaw elsewhere will work with mine. But mostly I'm doing it because I'm stubborn, I've been into php since php 3.x days and I'm not a fan of most modern coding styles. And too many existing projects in general don't get basic security right (like using prepared statements - I blame MySQL for that, since it didn't support them back when LAMP first became popular)
For tracking customer purchases, I'm going with unique public address, but I'm using a generator rather than random. Specifically -
$series=00;
$salt='gd74dj@#%^1ldidst';
$phrase='I like my cars fast and my women faster';
Idea being to generate a series of keys on non-connected machine, import public addresses into postgresql on web server.
When I start to run low on addresses, increment the series and regenerate.
The salt I need to back up, the phrase I need to remember, and thus I can regenerate from the salt, series, and phrase as needed.
Now generation of the keys -
$salt.=md5($salt); // pad the salt
$stop=65536; //256^2
for($i=0;$i<$stop;$i++) {
$string=$salt . $phrase . $series . int2hex($i);
$hash=hash('ripemd160',$string);
$string=$salt . $hash;
$hash=hash('sha256',$string);
$privateKey=strtoupper($hash);
$publicAddress=genPublicAddress($privateKey);
print($privateKey . "\t" . $publicAddress . "\n\n");
}
int2hex converts an integer to hex with padding 0's as needed 0000 - FFFF
genPublicAddress uses bcmath_Utils and related classes to generate a base58 public address from the generated key.
Right now in testing I am just having it print the results so I can test the results via
http://gobittest.appspot.com/Address but eventually it will insert the private key, series, and public address into a table - idea being I query table for all public addresses associated with a series and make an insert for the web server to use with shopping cart.
Then at end of day / week / whatever I can query web server for public addresses that have confirmed transactions, and take that list to off-line machine with the database of private keys and query for associated private keys, import into a wallet and smile.
Mostly what I'm looking for is criticisms on my generation of private keys. Does that look OK or do I need to do more steps before final sha256 hash?
I think adding the salt to a ripemd160 hash and hashing that is enough that I don't have to worry about someone intentionally creating collisions but I would value the input of others with experience in this arena.
Secondly, I want to verify that a sha256 hash will in fact result in a valid private key. All the docs I read seemed to indicate 64 character hex was the only limitation, but I just want to make sure there aren't some reserved ranges or something I need to watch out for.
Thanks