# HG changeset patch # User ivo # Date 1287015355 -7200 # Node ID 6d86596d8884c063022b0f2838c466ba991da478 # Parent fd7c60905b139f1bcf55136edf4142b6648f279a Fixed BSD support, improved randombytes/secret key generation diff -r fd7c60905b13 -r 6d86596d8884 src/common.c --- 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 #endif #include -#include #include #include #include #include +#include #ifdef linux #include #include diff -r fd7c60905b13 -r 6d86596d8884 src/keypair.c --- 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 +#include 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; }