annotate randombytes.c @ 9:765303f4f2da

Attempt to fix randombytes.c for unpatched NaCl
author Ivo Smits <Ivo@UCIS.nl>
date Thu, 14 Jul 2011 16:49:21 +0200
parents a139bed53614
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
a139bed53614 Fixed some compiler warnings, added support for unpatched nacl library
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
1 #include <time.h>
a139bed53614 Fixed some compiler warnings, added support for unpatched nacl library
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
2
a139bed53614 Fixed some compiler warnings, added support for unpatched nacl library
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
3 void randombytes(unsigned char *x,unsigned long long xlen) {
9
765303f4f2da Attempt to fix randombytes.c for unpatched NaCl
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
4 FILE* fd = fopen("/dev/urandom", "rb");
765303f4f2da Attempt to fix randombytes.c for unpatched NaCl
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
5 if (fd != NULL) {
7
a139bed53614 Fixed some compiler warnings, added support for unpatched nacl library
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
6 fread(x, 1, xlen, fd);
a139bed53614 Fixed some compiler warnings, added support for unpatched nacl library
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
7 fclose(fd);
a139bed53614 Fixed some compiler warnings, added support for unpatched nacl library
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
8 } else {
a139bed53614 Fixed some compiler warnings, added support for unpatched nacl library
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
9 srand(time(NULL));
a139bed53614 Fixed some compiler warnings, added support for unpatched nacl library
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
10 for (int i = 0; i < xlen; i++) x[i] = rand() % 256;
a139bed53614 Fixed some compiler warnings, added support for unpatched nacl library
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
11 }
a139bed53614 Fixed some compiler warnings, added support for unpatched nacl library
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
12 }