Mercurial > hg > quicktun
comparison src/randombytes.c @ 64:fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
author | Ivo Smits <Ivo@UFO-Net.nl> |
---|---|
date | Sat, 07 Jan 2017 18:07:27 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
63:fa4983c5f7ea | 64:fa53d1c54886 |
---|---|
1 /* | |
2 randombytes/devurandom.h version 20080713 | |
3 D. J. Bernstein | |
4 Public domain. | |
5 */ | |
6 | |
7 #include <sys/types.h> | |
8 #include <sys/stat.h> | |
9 #include <fcntl.h> | |
10 #include <unistd.h> | |
11 | |
12 static int fd = -1; | |
13 | |
14 void randombytes(unsigned char *x,unsigned long long xlen) { | |
15 int i; | |
16 | |
17 if (fd == -1) { | |
18 for (;;) { | |
19 fd = open("/dev/urandom",O_RDONLY); | |
20 if (fd != -1) break; | |
21 sleep(1); | |
22 } | |
23 } | |
24 | |
25 while (xlen > 0) { | |
26 if (xlen < 1048576) i = xlen; else i = 1048576; | |
27 | |
28 i = read(fd,x,i); | |
29 if (i < 1) { | |
30 sleep(1); | |
31 continue; | |
32 } | |
33 | |
34 x += i; | |
35 xlen -= i; | |
36 } | |
37 } |