MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetDevURandom

Function GetDevURandom

src/random.cpp:255–271  ·  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

253 * compatible way to get cryptographic randomness on UNIX-ish platforms.
254 */
255static void GetDevURandom(unsigned char *ent32)
256{
257 int f = open("/dev/urandom", O_RDONLY);
258 if (f == -1) {
259 RandFailure();
260 }
261 int have = 0;
262 do {
263 ssize_t n = read(f, ent32 + have, NUM_OS_RANDOM_BYTES - have);
264 if (n <= 0 || n + have > NUM_OS_RANDOM_BYTES) {
265 close(f);
266 RandFailure();
267 }
268 have += n;
269 } while (have < NUM_OS_RANDOM_BYTES);
270 close(f);
271}
272#endif
273
274/** Get 32 bytes of system entropy. */

Callers 1

GetOSRandFunction · 0.85

Calls 1

RandFailureFunction · 0.85

Tested by

no test coverage detected