diff options
author | irungentoo <irungentoo@gmail.com> | 2015-07-27 15:23:32 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-07-27 15:23:32 -0400 |
commit | fa5df6aa1797d3184c77b41178df5c1317bcf4ee (patch) | |
tree | de781332982aa26c6846fb4e9bef735efe79e58b | |
parent | 5def57afcf0413f3eee92f29aeef0153db5d2e0c (diff) |
client_id -> public_key
-rw-r--r-- | toxcore/DHT.c | 22 | ||||
-rw-r--r-- | toxcore/DHT.h | 13 |
2 files changed, 18 insertions, 17 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 12789098..5bff504a 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -97,15 +97,15 @@ int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2) | |||
97 | * If shared key is already in shared_keys, copy it to shared_key. | 97 | * If shared key is already in shared_keys, copy it to shared_key. |
98 | * else generate it into shared_key and copy it to shared_keys | 98 | * else generate it into shared_key and copy it to shared_keys |
99 | */ | 99 | */ |
100 | void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t *secret_key, const uint8_t *client_id) | 100 | void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t *secret_key, const uint8_t *public_key) |
101 | { | 101 | { |
102 | uint32_t i, num = ~0, curr = 0; | 102 | uint32_t i, num = ~0, curr = 0; |
103 | 103 | ||
104 | for (i = 0; i < MAX_KEYS_PER_SLOT; ++i) { | 104 | for (i = 0; i < MAX_KEYS_PER_SLOT; ++i) { |
105 | int index = client_id[30] * MAX_KEYS_PER_SLOT + i; | 105 | int index = public_key[30] * MAX_KEYS_PER_SLOT + i; |
106 | 106 | ||
107 | if (shared_keys->keys[index].stored) { | 107 | if (shared_keys->keys[index].stored) { |
108 | if (memcmp(client_id, shared_keys->keys[index].client_id, CLIENT_ID_SIZE) == 0) { | 108 | if (memcmp(public_key, shared_keys->keys[index].public_key, CLIENT_ID_SIZE) == 0) { |
109 | memcpy(shared_key, shared_keys->keys[index].shared_key, crypto_box_BEFORENMBYTES); | 109 | memcpy(shared_key, shared_keys->keys[index].shared_key, crypto_box_BEFORENMBYTES); |
110 | ++shared_keys->keys[index].times_requested; | 110 | ++shared_keys->keys[index].times_requested; |
111 | shared_keys->keys[index].time_last_requested = unix_time(); | 111 | shared_keys->keys[index].time_last_requested = unix_time(); |
@@ -129,31 +129,31 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t | |||
129 | } | 129 | } |
130 | } | 130 | } |
131 | 131 | ||
132 | encrypt_precompute(client_id, secret_key, shared_key); | 132 | encrypt_precompute(public_key, secret_key, shared_key); |
133 | 133 | ||
134 | if (num != (uint32_t)~0) { | 134 | if (num != (uint32_t)~0) { |
135 | shared_keys->keys[curr].stored = 1; | 135 | shared_keys->keys[curr].stored = 1; |
136 | shared_keys->keys[curr].times_requested = 1; | 136 | shared_keys->keys[curr].times_requested = 1; |
137 | memcpy(shared_keys->keys[curr].client_id, client_id, CLIENT_ID_SIZE); | 137 | memcpy(shared_keys->keys[curr].public_key, public_key, CLIENT_ID_SIZE); |
138 | memcpy(shared_keys->keys[curr].shared_key, shared_key, crypto_box_BEFORENMBYTES); | 138 | memcpy(shared_keys->keys[curr].shared_key, shared_key, crypto_box_BEFORENMBYTES); |
139 | shared_keys->keys[curr].time_last_requested = unix_time(); | 139 | shared_keys->keys[curr].time_last_requested = unix_time(); |
140 | } | 140 | } |
141 | } | 141 | } |
142 | 142 | ||
143 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key | 143 | /* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key |
144 | * for packets that we receive. | 144 | * for packets that we receive. |
145 | */ | 145 | */ |
146 | void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *client_id) | 146 | void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key) |
147 | { | 147 | { |
148 | get_shared_key(&dht->shared_keys_recv, shared_key, dht->self_secret_key, client_id); | 148 | get_shared_key(&dht->shared_keys_recv, shared_key, dht->self_secret_key, public_key); |
149 | } | 149 | } |
150 | 150 | ||
151 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key | 151 | /* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key |
152 | * for packets that we send. | 152 | * for packets that we send. |
153 | */ | 153 | */ |
154 | void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *client_id) | 154 | void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key) |
155 | { | 155 | { |
156 | get_shared_key(&dht->shared_keys_sent, shared_key, dht->self_secret_key, client_id); | 156 | get_shared_key(&dht->shared_keys_sent, shared_key, dht->self_secret_key, public_key); |
157 | } | 157 | } |
158 | 158 | ||
159 | void to_net_family(IP *ip) | 159 | void to_net_family(IP *ip) |
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 933bdcaf..af0adeab 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -182,7 +182,7 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed | |||
182 | #define KEYS_TIMEOUT 600 | 182 | #define KEYS_TIMEOUT 600 |
183 | typedef struct { | 183 | typedef struct { |
184 | struct { | 184 | struct { |
185 | uint8_t client_id[CLIENT_ID_SIZE]; | 185 | uint8_t public_key[CLIENT_ID_SIZE]; |
186 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; | 186 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; |
187 | uint32_t times_requested; | 187 | uint32_t times_requested; |
188 | uint8_t stored; /* 0 if not, 1 if is */ | 188 | uint8_t stored; /* 0 if not, 1 if is */ |
@@ -241,17 +241,18 @@ typedef struct { | |||
241 | * If shared key is already in shared_keys, copy it to shared_key. | 241 | * If shared key is already in shared_keys, copy it to shared_key. |
242 | * else generate it into shared_key and copy it to shared_keys | 242 | * else generate it into shared_key and copy it to shared_keys |
243 | */ | 243 | */ |
244 | void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t *secret_key, const uint8_t *client_id); | 244 | void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t *secret_key, |
245 | const uint8_t *public_key); | ||
245 | 246 | ||
246 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key | 247 | /* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key |
247 | * for packets that we receive. | 248 | * for packets that we receive. |
248 | */ | 249 | */ |
249 | void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *client_id); | 250 | void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key); |
250 | 251 | ||
251 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key | 252 | /* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key |
252 | * for packets that we send. | 253 | * for packets that we send. |
253 | */ | 254 | */ |
254 | void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *client_id); | 255 | void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key); |
255 | 256 | ||
256 | void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id); | 257 | void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id); |
257 | 258 | ||