Fallback: get 32 bytes of system entropy from /dev/urandom. The most * compatible way to get cryptographic randomness on UNIX-ish platforms. */
| 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. */ |
no test coverage detected