21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

if (errno = = EINTR) continue;<br />

perror("spc_rand could not read from /dev/urandom");<br />

exit(-1);<br />

}<br />

where += r;<br />

nbytes -= r;<br />

}<br />

return buf;<br />

}<br />

unsigned char *spc_keygen(unsigned char *buf, size_t nbytes) {<br />

ssize_t r;<br />

unsigned char *where = buf;<br />

if (spc_devrand_fd = = -1 && spc_devrand_fd_noblock = = -1 && spc_devurand_fd = = -1)<br />

spc_rand_init( );<br />

while (nbytes) {<br />

if ((r = read(spc_devrand_fd_noblock, where, nbytes)) = = -1) {<br />

if (errno = = EINTR) continue;<br />

if (errno = = EAGAIN) break;<br />

perror("spc_rand could not read from /dev/random");<br />

exit(-1);<br />

}<br />

where += r;<br />

nbytes -= r;<br />

}<br />

spc_rand(where, nbytes);<br />

return buf;<br />

}<br />

unsigned char *spc_entropy(unsigned char *buf, size_t nbytes) {<br />

ssize_t r;<br />

unsigned char *where = buf;<br />

if (spc_devrand_fd = = -1 && spc_devrand_fd_noblock = = -1 && spc_devurand_fd = = -1)<br />

spc_rand_init( );<br />

while (nbytes) {<br />

if ((r = read(spc_devrand_fd, (void *)where, nbytes)) = = -1) {<br />

if (errno = = EINTR) continue;<br />

perror("spc_rand could not read from /dev/random");<br />

exit(-1);<br />

}<br />

where += r;<br />

nbytes -= r;<br />

}<br />

return buf;<br />

}<br />

See Also<br />

Recipes 11.2, 11.5, 11.8, 11.19, 11.20, 11.22, 11.23<br />

Using the Standard Unix Randomness Infrastructure | 579<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!