]> git.meshlink.io Git - meshlink/commitdiff
Re-add accidentily removed randomize() from crypto.c.
authorGuus Sliepen <guus@meshlink.io>
Sun, 25 May 2014 19:14:34 +0000 (21:14 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sun, 25 May 2014 19:14:34 +0000 (21:14 +0200)
src/crypto.c

index 2e2fa5386555c02b1e8c5632ee597c6c52bd513d..e3797f8d79d04a0c8e8341786693e2fcc365979a 100644 (file)
@@ -41,6 +41,20 @@ void crypto_exit(void) {
        close(random_fd);
 }
 
+void randomize(void *out, size_t outlen) {
+       while(outlen) {
+               size_t len = read(random_fd, out, outlen);
+               if(len <= 0) {
+                       if(errno == EAGAIN || errno == EINTR)
+                               continue;
+                       fprintf(stderr, "Could not read random numbers: %s\n", strerror(errno));
+                       abort();
+               }
+               out += len;
+               outlen -= len;
+       }
+}
+
 #else
 
 #include <wincrypt.h>