Mercurial > hg > php_nacl
diff randombytes.c @ 7:a139bed53614
Fixed some compiler warnings, added support for unpatched nacl library
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Tue, 12 Jul 2011 21:26:46 +0000 |
parents | |
children | 765303f4f2da |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/randombytes.c Tue Jul 12 21:26:46 2011 +0000 @@ -0,0 +1,12 @@ +#include <time.h> + +void randombytes(unsigned char *x,unsigned long long xlen) { + int fd = open("/dev/urandom",O_RDONLY); + if (fd != -1) { + fread(x, 1, xlen, fd); + fclose(fd); + } else { + srand(time(NULL)); + for (int i = 0; i < xlen; i++) x[i] = rand() % 256; + } +}