comparison src/keypair.c @ 24:dfac56805c77

Fixed support for shared NaCl library, explicitly refer to cryptographic primitives
author Ivo Smits <Ivo@UCIS.nl>
date Mon, 28 Feb 2011 19:28:18 +0100
parents 6d86596d8884
children fa53d1c54886
comparison
equal deleted inserted replaced
23:bd4259de8459 24:dfac56805c77
22 The views and conclusions contained in the software and documentation are those of the 22 The views and conclusions contained in the software and documentation are those of the
23 authors and should not be interpreted as representing official policies, either expressed 23 authors and should not be interpreted as representing official policies, either expressed
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_curve25519xsalsa20poly1305.h"
28 #include "crypto_scalarmult_curve25519.h"
28 #include <time.h> 29 #include <time.h>
29 #include <fcntl.h> 30 #include <fcntl.h>
30 31
31 int main() { 32 int main() {
32 print_header(); 33 print_header();
33 34
34 unsigned char cpublickey[crypto_box_PUBLICKEYBYTES]; 35 unsigned char cpublickey[crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES];
35 unsigned char csecretkey[crypto_box_SECRETKEYBYTES]; 36 unsigned char csecretkey[crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES];
36 int i; 37 int i;
37 38
38 fprintf(stderr, "Please feed 32 bytes of random data to stdin.\n"); 39 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 (slow but secure): quicktun.keypair < /dev/random\n");
40 fprintf(stderr, "Example (fast but insecure): ./quicktun.keypair < /dev/urandom\n"); 41 fprintf(stderr, "Example (fast but insecure): quicktun.keypair < /dev/urandom\n");
41 42
42 crypto_box_keypair(cpublickey, csecretkey); 43 int len = fread(csecretkey, 1, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES, stdin);
44 if (len < crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) return errorexitp("Error or end of file on STDIN");
45 /* char* b;
46 srand(time(NULL));
47 for (b = csecretkey; b < csecretkey + crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES; b++) *b = rand() % 255;*/
48
49 crypto_scalarmult_curve25519_base(cpublickey, csecretkey);
43 50
44 printf("SECRET: "); 51 printf("SECRET: ");
45 for (i = 0; i < crypto_box_SECRETKEYBYTES; i++) printf("%02x", csecretkey[i]); 52 for (i = 0; i < crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES; i++) printf("%02x", csecretkey[i]);
46 printf("\n"); 53 printf("\n");
47 54
48 printf("PUBLIC: "); 55 printf("PUBLIC: ");
49 for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) printf("%02x", cpublickey[i]); 56 for (i = 0; i < crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES; i++) printf("%02x", cpublickey[i]);
50 printf("\n"); 57 printf("\n");
51 58
52 return 0; 59 return 0;
53 } 60 }
54
55 int randombytes(char* bytes) {
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;
59 srand(time(NULL));
60 for (b = bytes; b < bytes + crypto_box_SECRETKEYBYTES; b++) *b = rand() % 255;*/
61 return 0;
62 }