summaryrefslogtreecommitdiff
path: root/toxdns
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-12-19 02:47:42 +0000
committeriphydf <iphydf@users.noreply.github.com>2016-12-22 10:26:59 +0000
commitce29c8e7ec91d95167b2dea3aee9fd1ae1aac254 (patch)
treea288df55c44e8edf816e6abbde19a70faef73394 /toxdns
parent7122d2e862e028a730478d88cd61557fbed16ebf (diff)
Wrap all sodium/nacl functions in crypto_core.c.
Diffstat (limited to 'toxdns')
-rw-r--r--toxdns/toxdns.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/toxdns/toxdns.c b/toxdns/toxdns.c
index 01380772..3f010118 100644
--- a/toxdns/toxdns.c
+++ b/toxdns/toxdns.c
@@ -50,10 +50,10 @@ static const char base32[32] = {
50} 50}
51 51
52typedef struct { 52typedef struct {
53 uint8_t temp_pk[crypto_box_PUBLICKEYBYTES]; 53 uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE];
54 uint8_t temp_sk[crypto_box_SECRETKEYBYTES]; 54 uint8_t temp_sk[CRYPTO_SECRET_KEY_SIZE];
55 uint8_t server_public_key[crypto_box_PUBLICKEYBYTES]; 55 uint8_t server_public_key[CRYPTO_PUBLIC_KEY_SIZE];
56 uint8_t shared_key[crypto_box_KEYBYTES]; 56 uint8_t shared_key[CRYPTO_SYMMETRIC_KEY_SIZE];
57 uint32_t nonce; 57 uint32_t nonce;
58 uint32_t nonce_start; 58 uint32_t nonce_start;
59} DNS_Object; 59} DNS_Object;
@@ -61,7 +61,7 @@ typedef struct {
61static void dns_new_temp_keys(DNS_Object *d) 61static void dns_new_temp_keys(DNS_Object *d)
62{ 62{
63 d->nonce = d->nonce_start = random_int(); 63 d->nonce = d->nonce_start = random_int();
64 crypto_box_keypair(d->temp_pk, d->temp_sk); 64 crypto_new_keypair(d->temp_pk, d->temp_sk);
65 encrypt_precompute(d->server_public_key, d->temp_sk, d->shared_key); 65 encrypt_precompute(d->server_public_key, d->temp_sk, d->shared_key);
66} 66}
67 67
@@ -78,7 +78,7 @@ void *tox_dns3_new(uint8_t *server_public_key)
78 return NULL; 78 return NULL;
79 } 79 }
80 80
81 memcpy(d->server_public_key, server_public_key, crypto_box_PUBLICKEYBYTES); 81 memcpy(d->server_public_key, server_public_key, CRYPTO_PUBLIC_KEY_SIZE);
82 dns_new_temp_keys(d); 82 dns_new_temp_keys(d);
83 return d; 83 return d;
84} 84}
@@ -107,7 +107,7 @@ int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string
107 uint8_t *name, uint8_t name_len) 107 uint8_t *name, uint8_t name_len)
108{ 108{
109#define DOT_INTERVAL (6 * 5) 109#define DOT_INTERVAL (6 * 5)
110 int base = (sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + name_len + crypto_box_MACBYTES); 110 int base = (sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + name_len + CRYPTO_MAC_SIZE);
111 int end_len = ((base * 8) / 5) + (base / DOT_INTERVAL) + !!(base % 5); 111 int end_len = ((base * 8) / 5) + (base / DOT_INTERVAL) + !!(base % 5);
112 end_len -= !(base % DOT_INTERVAL); 112 end_len -= !(base % DOT_INTERVAL);
113 113
@@ -117,18 +117,18 @@ int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string
117 117
118 DNS_Object *d = (DNS_Object *)dns3_object; 118 DNS_Object *d = (DNS_Object *)dns3_object;
119 uint8_t buffer[1024]; 119 uint8_t buffer[1024];
120 uint8_t nonce[crypto_box_NONCEBYTES] = {0}; 120 uint8_t nonce[CRYPTO_NONCE_SIZE] = {0};
121 memcpy(nonce, &d->nonce, sizeof(uint32_t)); 121 memcpy(nonce, &d->nonce, sizeof(uint32_t));
122 memcpy(buffer, &d->nonce, sizeof(uint32_t)); 122 memcpy(buffer, &d->nonce, sizeof(uint32_t));
123 memcpy(buffer + sizeof(uint32_t), d->temp_pk, crypto_box_PUBLICKEYBYTES); 123 memcpy(buffer + sizeof(uint32_t), d->temp_pk, CRYPTO_PUBLIC_KEY_SIZE);
124 int len = encrypt_data_symmetric(d->shared_key, nonce, name, name_len, 124 int len = encrypt_data_symmetric(d->shared_key, nonce, name, name_len,
125 buffer + sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES); 125 buffer + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE);
126 126
127 if (len == -1) { 127 if (len == -1) {
128 return -1; 128 return -1;
129 } 129 }
130 130
131 int total_len = len + sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES; 131 int total_len = len + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE;
132 uint8_t *buff = buffer, *old_str = string; 132 uint8_t *buff = buffer, *old_str = string;
133 buffer[total_len] = 0; 133 buffer[total_len] = 0;
134 uint8_t bits = 0; 134 uint8_t bits = 0;
@@ -212,8 +212,13 @@ int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record,
212 return -1; 212 return -1;
213 } 213 }
214 214
215 /*if (id_record_len > 255 || id_record_len <= (sizeof(uint32_t) + crypto_box_MACBYTES)) 215#if 0
216 return -1;*/ 216
217 if (id_record_len > 255 || id_record_len <= (sizeof(uint32_t) + CRYPTO_MAC_SIZE)) {
218 return -1;
219 }
220
221#endif
217 222
218 uint8_t id_record_null[id_record_len + 1]; 223 uint8_t id_record_null[id_record_len + 1];
219 memcpy(id_record_null, id_record, id_record_len); 224 memcpy(id_record_null, id_record, id_record_len);
@@ -225,7 +230,7 @@ int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record,
225 return -1; 230 return -1;
226 } 231 }
227 232
228 uint8_t nonce[crypto_box_NONCEBYTES] = {0}; 233 uint8_t nonce[CRYPTO_NONCE_SIZE] = {0};
229 memcpy(nonce, &request_id, sizeof(uint32_t)); 234 memcpy(nonce, &request_id, sizeof(uint32_t));
230 nonce[sizeof(uint32_t)] = 1; 235 nonce[sizeof(uint32_t)] = 1;
231 int len = decrypt_data_symmetric(d->shared_key, nonce, data, length, tox_id); 236 int len = decrypt_data_symmetric(d->shared_key, nonce, data, length, tox_id);