Fallback: get 32 bytes of system entropy from /dev/urandom. The most * compatible way to get cryptographic randomness on UNIX-ish platforms. */
| 181 | * compatible way to get cryptographic randomness on UNIX-ish platforms. |
| 182 | */ |
| 183 | static void GetDevURandom(unsigned char *ent32) |
| 184 | { |
| 185 | int f = open("/dev/urandom", O_RDONLY); |
| 186 | if (f == -1) { |
| 187 | RandFailure(); |
| 188 | } |
| 189 | int have = 0; |
| 190 | do { |
| 191 | ssize_t n = read(f, ent32 + have, NUM_OS_RANDOM_BYTES - have); |
| 192 | if (n <= 0 || n + have > NUM_OS_RANDOM_BYTES) { |
| 193 | close(f); |
| 194 | RandFailure(); |
| 195 | } |
| 196 | have += n; |
| 197 | } while (have < NUM_OS_RANDOM_BYTES); |
| 198 | close(f); |
| 199 | } |
| 200 | #endif |
| 201 | |
| 202 | /** Get 32 bytes of system entropy. */ |
no test coverage detected