comparison 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
comparison
equal deleted inserted replaced
7:fd7c60905b13 8:6d86596d8884
24 or implied, of Ivo Smits.*/ 24 or implied, of Ivo Smits.*/
25 25
26 #include "common.c" 26 #include "common.c"
27 #include "crypto_box.h" 27 #include "crypto_box.h"
28 #include <time.h> 28 #include <time.h>
29 #include <fcntl.h>
29 30
30 int main() { 31 int main() {
31 print_header(); 32 print_header();
32 33
33 unsigned char cpublickey[crypto_box_PUBLICKEYBYTES]; 34 unsigned char cpublickey[crypto_box_PUBLICKEYBYTES];
34 unsigned char csecretkey[crypto_box_SECRETKEYBYTES]; 35 unsigned char csecretkey[crypto_box_SECRETKEYBYTES];
35 int i; 36 int i;
37
38 fprintf(stderr, "Please feed 32 bytes of random data to stdin.\n");
39 fprintf(stderr, "Example (slow but secure): ./quicktun.keypair < /dev/random\n");
40 fprintf(stderr, "Example (fast but insecure): ./quicktun.keypair < /dev/urandom\n");
36 41
37 crypto_box_keypair(cpublickey, csecretkey); 42 crypto_box_keypair(cpublickey, csecretkey);
38 43
39 printf("SECRET: "); 44 printf("SECRET: ");
40 for (i = 0; i < crypto_box_SECRETKEYBYTES; i++) printf("%02x", csecretkey[i]); 45 for (i = 0; i < crypto_box_SECRETKEYBYTES; i++) printf("%02x", csecretkey[i]);
45 printf("\n"); 50 printf("\n");
46 51
47 return 0; 52 return 0;
48 } 53 }
49 54
50 void randombytes(char* bytes) { 55 int randombytes(char* bytes) {
51 char* b; 56 int len = fread(bytes, 1, crypto_box_SECRETKEYBYTES, stdin);
57 if (len < crypto_box_SECRETKEYBYTES) return errorexitp("Error or end of file on STDIN");
58 /* char* b;
52 srand(time(NULL)); 59 srand(time(NULL));
53 for (b = bytes; b < bytes + crypto_box_SECRETKEYBYTES; b++) *b = rand() % 255; 60 for (b = bytes; b < bytes + crypto_box_SECRETKEYBYTES; b++) *b = rand() % 255;*/
61 return 0;
54 } 62 }