]>
iEval git - authen-passphrase-scrypt.git/blob - scrypt-1.2.1/libcperciva/util/entropy.c
13 * XXX We obtain random bytes from the operating system by opening
14 * XXX /dev/urandom and reading them from that device; this works on
15 * XXX modern UNIX-like operating systems but not on systems like
16 * XXX win32 where there is no concept of /dev/urandom.
20 * entropy_read(buf, buflen):
21 * Fill the given buffer with random bytes provided by the operating system.
24 entropy_read(uint8_t * buf
, size_t buflen
)
29 /* Sanity-check the buffer size. */
30 if (buflen
> SSIZE_MAX
) {
31 warn0("Programmer error: "
32 "Trying to read insane amount of random data: %zu",
37 /* Open /dev/urandom. */
38 if ((fd
= open("/dev/urandom", O_RDONLY
)) == -1) {
39 warnp("open(/dev/urandom)");
43 /* Read bytes until we have filled the buffer. */
45 if ((lenread
= read(fd
, buf
, buflen
)) == -1) {
46 warnp("read(/dev/urandom)");
50 /* The random device should never EOF. */
52 warn0("EOF on /dev/urandom?");
56 /* We've filled a portion of the buffer. */
57 buf
+= (size_t)lenread
;
58 buflen
-= (size_t)lenread
;
61 /* Close the device. */
62 while (close(fd
) == -1) {
64 warnp("close(/dev/urandom)");
This page took 0.043732 seconds and 4 git commands to generate.