view 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
line wrap: on
line source

#include <time.h>

void randombytes(unsigned char *x,unsigned long long xlen) {
	FILE* fd = fopen("/dev/urandom", "rb");
	if (fd != NULL) {
		fread(x, 1, xlen, fd);
		fclose(fd);
	} else {
		srand(time(NULL));
		for (int i = 0; i < xlen; i++) x[i] = rand() % 256;
	}
}