summaryrefslogtreecommitdiff
path: root/other/DHT_bootstrap.c
diff options
context:
space:
mode:
Diffstat (limited to 'other/DHT_bootstrap.c')
-rw-r--r--other/DHT_bootstrap.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c
index 9ae22caa..eedb03f5 100644
--- a/other/DHT_bootstrap.c
+++ b/other/DHT_bootstrap.c
@@ -36,9 +36,41 @@ unsigned char * hex_string_to_bin(char hex_string[])
36 return val; 36 return val;
37} 37}
38 38
39void manage_keys()
40{
41 const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
42 uint8_t keys[KEYS_SIZE];
43
44 FILE *keys_file = fopen("key", "r");
45 if (keys_file != NULL) {
46 //if file was opened successfully -- load keys
47 size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file);
48 if (read_size != KEYS_SIZE) {
49 printf("Error while reading the key file\nExiting.\n");
50 exit(1);
51 } else {
52 printf("Keys loaded successfully\n");
53 }
54 load_keys(keys);
55 } else {
56 //otherwise save new keys
57 new_keys();
58 save_keys(keys);
59 keys_file = fopen("key", "w");
60 if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) {
61 printf("Error while writing the key file.\nExiting.\n");
62 exit(1);
63 } else {
64 printf("Keys saved successfully\n");
65 }
66 }
67
68 fclose(keys_file);
69}
70
39int main(int argc, char *argv[]) 71int main(int argc, char *argv[])
40{ 72{
41 new_keys(); 73 manage_keys();
42 printf("Public key: "); 74 printf("Public key: ");
43 uint32_t i; 75 uint32_t i;
44 for(i = 0; i < 32; i++) 76 for(i = 0; i < 32; i++)