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