Mercurial > hg > quicktun
diff src/keypair.c @ 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 | 9d449e899402 |
children | dfac56805c77 |
line wrap: on
line diff
--- 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; }