view randombytes.c @ 8:a1fc155ca80b

Fixed reference-output parameters in key generation functions
author Ivo Smits <Ivo@UCIS.nl>
date Thu, 14 Jul 2011 16:32:23 +0200
parents a139bed53614
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;
	}
}