Mercurial > hg > php_nacl
comparison 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 |
comparison
equal
deleted
inserted
replaced
6:ded86f4d6275 | 7:a139bed53614 |
---|---|
1 #include <time.h> | |
2 | |
3 void randombytes(unsigned char *x,unsigned long long xlen) { | |
4 int fd = open("/dev/urandom",O_RDONLY); | |
5 if (fd != -1) { | |
6 fread(x, 1, xlen, fd); | |
7 fclose(fd); | |
8 } else { | |
9 srand(time(NULL)); | |
10 for (int i = 0; i < xlen; i++) x[i] = rand() % 256; | |
11 } | |
12 } |