What kind of random numbers source does getnewaddress in Bitcoin Core API (bitcoind) uses?

2

Is it an internal PRNG? Is it fed from /dev/random or /dev/urandom? How secure is it? If I have a hardware (TRNG) plugged in feeding my /dev/random will this source of entropy get used by bitcoind?

Felipe

Posted 2014-04-19T15:17:45.793

Reputation: 1 511

1Well OpenSSL handles most cryptography things in Bitcoin.Jori 2014-04-19T17:06:23.870

2In this particular case, it's the RAND_bytes call from OpenSSL.Diego Basch 2014-04-19T21:46:07.207

1@DiegoBasch: May I suggest you upgrade your comment to an answer, ideally with a link to the source?pyramids 2014-04-20T19:43:55.503

Answers

3

As others mentioned Bitcoin core uses OpenSSL random sources.

This means that it uses any random source available, like:

  • the operation system, i.e. interrupts
  • random sources of the CPU or the chip set
  • dedicated hardware for entropy generation

So in order to make sure your hardware random generator works with Bitcoin you must make sure it works with OpenSSL.

John L. Jegutanis

Posted 2014-04-19T15:17:45.793

Reputation: 561

3

It uses RAND_bytes from OpenSSL. The relevant call is CKey::MakeNewKey.

getnewaddress is in rpcwallet.cpp. It tries to get a key from the pool, and if the pool is empty it allocates a new one which is populated using RAND_bytes.

Diego Basch

Posted 2014-04-19T15:17:45.793

Reputation: 326