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