|
Lines 302-319
Link Here
|
| 302 |
return -1; |
302 |
return -1; |
| 303 |
} |
303 |
} |
| 304 |
|
304 |
|
| 305 |
void |
305 |
#ifndef HAVE_ARC4RANDOM_BUF |
| 306 |
GenerateRandomData(int len, char *buf) |
306 |
|
|
|
307 |
static void |
| 308 |
emulate_getrandom_buf ( |
| 309 |
char *auth, |
| 310 |
int len |
| 311 |
) |
| 307 |
{ |
312 |
{ |
| 308 |
#ifdef HAVE_ARC4RANDOM_BUF |
|
|
| 309 |
arc4random_buf(buf, len); |
| 310 |
#else |
| 311 |
int fd; |
313 |
int fd; |
| 312 |
|
314 |
|
| 313 |
fd = open("/dev/urandom", O_RDONLY); |
315 |
fd = open("/dev/urandom", O_RDONLY); |
| 314 |
read(fd, buf, len); |
316 |
read(fd, buf, len); |
| 315 |
close(fd); |
317 |
close(fd); |
| 316 |
#endif |
318 |
} |
|
|
319 |
|
| 320 |
static void |
| 321 |
arc4random_buf ( |
| 322 |
char *auth, |
| 323 |
int len |
| 324 |
) |
| 325 |
{ |
| 326 |
int ret; |
| 327 |
|
| 328 |
#if HAVE_GETENTROPY |
| 329 |
/* weak emulation of arc4random through the entropy libc */ |
| 330 |
ret = getentropy (auth, len); |
| 331 |
if (ret == 0) |
| 332 |
return; |
| 333 |
#endif /* HAVE_GETENTROPY */ |
| 334 |
|
| 335 |
emulate_getrandom_buf (auth, len); |
| 336 |
} |
| 337 |
#endif /* !defined(HAVE_ARC4RANDOM_BUF) */ |
| 338 |
|
| 339 |
void |
| 340 |
GenerateRandomData(int len, char *buf) |
| 341 |
{ |
| 342 |
arc4random_buf(buf, len); |
| 317 |
} |
343 |
} |
| 318 |
|
344 |
|
| 319 |
#endif /* XCSECURITY */ |
345 |
#endif /* XCSECURITY */ |