projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add AES-256-GCM support to SPTPS.
[tinc]
/
src
/
random.c
diff --git
a/src/random.c
b/src/random.c
index
fad7173
..
f2e898f
100644
(file)
--- a/
src/random.c
+++ b/
src/random.c
@@
-2,12
+2,12
@@
#include "random.h"
#include "random.h"
-#ifndef HAVE_GET
RANDOM
+#ifndef HAVE_GET
ENTROPY
static int random_fd = -1;
#endif
void random_init(void) {
static int random_fd = -1;
#endif
void random_init(void) {
-#ifndef HAVE_GET
RANDOM
+#ifndef HAVE_GET
ENTROPY
random_fd = open("/dev/urandom", O_RDONLY);
if(random_fd < 0) {
random_fd = open("/dev/urandom", O_RDONLY);
if(random_fd < 0) {
@@
-23,7
+23,7
@@
void random_init(void) {
}
void random_exit(void) {
}
void random_exit(void) {
-#ifndef HAVE_GET
RANDOM
+#ifndef HAVE_GET
ENTROPY
close(random_fd);
#endif
}
close(random_fd);
#endif
}
@@
-32,8
+32,9
@@
void randomize(void *vout, size_t outlen) {
uint8_t *out = vout;
while(outlen) {
uint8_t *out = vout;
while(outlen) {
-#ifdef HAVE_GETRANDOM
- ssize_t len = getrandom(out, outlen, 0);
+#ifdef HAVE_GETENTROPY
+ int reqlen = (int) MIN(256, outlen);
+ int len = !getentropy(out, reqlen) ? reqlen : -1;
#else
ssize_t len = read(random_fd, out, outlen);
#endif
#else
ssize_t len = read(random_fd, out, outlen);
#endif