]> mj.ucw.cz Git - libucw.git/blob - lib/randomkey.c
sign mismatch fixed
[libucw.git] / lib / randomkey.c
1 /*
2  *      Sherlock Library -- Cryptographically Safe Random Key Generator
3  *
4  *      (c) 2002 Martin Mares <mj@ucw.cz>
5  */
6
7 #include "lib/lib.h"
8
9 #include <fcntl.h>
10 #include <unistd.h>
11
12 void
13 randomkey(byte *buf, uns size)
14 {
15   int fd;
16
17   if ((fd = open("/dev/urandom", O_RDONLY, 0)) < 0)
18     die("Unable to open /dev/urandom: %m");
19   if (read(fd, buf, size) != (int) size)
20     die("Error reading /dev/urandom: %m");
21   close(fd);
22 }