Mercurial > hg > quicktun
changeset 8:6d86596d8884
Fixed BSD support, improved randombytes/secret key generation
author | ivo <Ivo@UCIS.nl> |
---|---|
date | Thu, 14 Oct 2010 02:15:55 +0200 |
parents | fd7c60905b13 |
children | 640f620a55cf |
files | src/common.c src/keypair.c |
diffstat | 2 files changed, 12 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/common.c Wed Oct 13 21:07:44 2010 +0200 +++ b/src/common.c Thu Oct 14 02:15:55 2010 +0200 @@ -31,11 +31,11 @@ #include <netinet/in.h> #endif #include <sys/ioctl.h> -#include <net/if.h> #include <sys/socket.h> #include <poll.h> #include <netdb.h> #include <stdlib.h> +#include <net/if.h> #ifdef linux #include <linux/if_tun.h> #include <linux/if_ether.h>
--- a/src/keypair.c Wed Oct 13 21:07:44 2010 +0200 +++ b/src/keypair.c Thu Oct 14 02:15:55 2010 +0200 @@ -26,6 +26,7 @@ #include "common.c" #include "crypto_box.h" #include <time.h> +#include <fcntl.h> int main() { print_header(); @@ -34,6 +35,10 @@ unsigned char csecretkey[crypto_box_SECRETKEYBYTES]; int i; + fprintf(stderr, "Please feed 32 bytes of random data to stdin.\n"); + fprintf(stderr, "Example (slow but secure): ./quicktun.keypair < /dev/random\n"); + fprintf(stderr, "Example (fast but insecure): ./quicktun.keypair < /dev/urandom\n"); + crypto_box_keypair(cpublickey, csecretkey); printf("SECRET: "); @@ -47,8 +52,11 @@ return 0; } -void randombytes(char* bytes) { - char* b; +int randombytes(char* bytes) { + int len = fread(bytes, 1, crypto_box_SECRETKEYBYTES, stdin); + if (len < crypto_box_SECRETKEYBYTES) return errorexitp("Error or end of file on STDIN"); +/* char* b; srand(time(NULL)); - for (b = bytes; b < bytes + crypto_box_SECRETKEYBYTES; b++) *b = rand() % 255; + for (b = bytes; b < bytes + crypto_box_SECRETKEYBYTES; b++) *b = rand() % 255;*/ + return 0; }