spesmilo/libbitcoin — pull request #15 by shunyata (2013-08-13 01:16:48+00:00)
Title: Bugfix regarding leading 00 bytes not being counted by BN_num_bytes

This pull request fixes a crash that can be reproduced with the stuff at this gist:

https://gist.github.com/shunyata/26870059063dc3eb7047

I was trying to generate many addresses and got a crash! I think this assertion is too strong, since if `secexp` begins with one or more null bytes, those bytes will not be counted by BN_num_bytes.

```
crash: deterministic_wallet.cpp:191: libbitcoin::secret_parameter libbitcoin::deterministic_wallet::generate_secret(size_t, bool) const: Assertion `((BN_num_bits(secexp)+7)/8) == secret.size()' failed.
```

The seed was taken from `examples/determ.cpp`. I tried to generate the same chain of addresses with brainwallet.org's electrum wallet implementation, and found that the culprit was a private key that begins with a 0x00 byte. This is the one at index 10 which I am generating directly in the POC in the gist I linked.