MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetDevURandom

Function GetDevURandom

src/random.cpp:266–282  ·  view source on GitHub ↗

Fallback: get 32 bytes of system entropy from /dev/urandom. The most * compatible way to get cryptographic randomness on UNIX-ish platforms. */

Source from the content-addressed store, hash-verified

264 * compatible way to get cryptographic randomness on UNIX-ish platforms.
265 */
266[[maybe_unused]] void GetDevURandom(unsigned char *ent32)
267{
268 int f = open("/dev/urandom", O_RDONLY);
269 if (f == -1) {
270 RandFailure();
271 }
272 int have = 0;
273 do {
274 ssize_t n = read(f, ent32 + have, NUM_OS_RANDOM_BYTES - have);
275 if (n <= 0 || n + have > NUM_OS_RANDOM_BYTES) {
276 close(f);
277 RandFailure();
278 }
279 have += n;
280 } while (have < NUM_OS_RANDOM_BYTES);
281 close(f);
282}
283#endif
284
285/** Get 32 bytes of system entropy. */

Callers 1

GetOSRandFunction · 0.85

Calls 1

RandFailureFunction · 0.85

Tested by

no test coverage detected