]> mj.ucw.cz Git - moe.git/blob - ucw/randomkey.c
Adapted to reflect changes in libucw.
[moe.git] / ucw / randomkey.c
1 /*
2  *      UCW Library -- Cryptographically Safe Random Key Generator
3  *
4  *      (c) 2002 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include "ucw/lib.h"
11
12 #include <fcntl.h>
13 #include <unistd.h>
14
15 void
16 randomkey(byte *buf, uns size)
17 {
18   int fd;
19
20   if ((fd = open("/dev/urandom", O_RDONLY, 0)) < 0)
21     die("Unable to open /dev/urandom: %m");
22   if (read(fd, buf, size) != (int) size)
23     die("Error reading /dev/urandom: %m");
24   close(fd);
25 }