view 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 source

#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;
	}
}