diff options
-rw-r--r-- | auto_tests/tox_test.c | 4 | ||||
-rw-r--r-- | toxcore/Messenger.c | 10 | ||||
-rw-r--r-- | toxcore/crypto_core.h | 1 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 12 | ||||
-rw-r--r-- | toxcore/net_crypto.h | 6 |
5 files changed, 19 insertions, 14 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 142a178f..40022b0a 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c | |||
@@ -332,6 +332,7 @@ START_TEST(test_one) | |||
332 | tox_self_set_name(tox1, name, sizeof(name), 0); | 332 | tox_self_set_name(tox1, name, sizeof(name), 0); |
333 | ck_assert_msg(tox_self_get_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH"); | 333 | ck_assert_msg(tox_self_get_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH"); |
334 | 334 | ||
335 | tox_self_get_address(tox1, address); | ||
335 | size_t save_size = tox_get_savedata_size(tox1); | 336 | size_t save_size = tox_get_savedata_size(tox1); |
336 | uint8_t data[save_size]; | 337 | uint8_t data[save_size]; |
337 | tox_get_savedata(tox1, data); | 338 | tox_get_savedata(tox1, data); |
@@ -344,6 +345,9 @@ START_TEST(test_one) | |||
344 | 345 | ||
345 | ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size."); | 346 | ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size."); |
346 | 347 | ||
348 | uint8_t address2[TOX_ADDRESS_SIZE]; | ||
349 | tox_self_get_address(tox2, address2); | ||
350 | ck_assert_msg(memcmp(address2, address, TOX_ADDRESS_SIZE) == 0, "Wrong address."); | ||
347 | uint8_t new_name[TOX_MAX_NAME_LENGTH] = { 0 }; | 351 | uint8_t new_name[TOX_MAX_NAME_LENGTH] = { 0 }; |
348 | tox_self_get_name(tox2, new_name); | 352 | tox_self_get_name(tox2, new_name); |
349 | ck_assert_msg(memcmp(name, new_name, TOX_MAX_NAME_LENGTH) == 0, "Wrong name"); | 353 | ck_assert_msg(memcmp(name, new_name, TOX_MAX_NAME_LENGTH) == 0, "Wrong name"); |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 6294aa9c..dc0e605a 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -2636,13 +2636,11 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3 | |||
2636 | case MESSENGER_STATE_TYPE_NOSPAMKEYS: | 2636 | case MESSENGER_STATE_TYPE_NOSPAMKEYS: |
2637 | if (length == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t)) { | 2637 | if (length == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t)) { |
2638 | set_nospam(&(m->fr), *(uint32_t *)data); | 2638 | set_nospam(&(m->fr), *(uint32_t *)data); |
2639 | load_keys(m->net_crypto, &data[sizeof(uint32_t)]); | 2639 | load_secret_key(m->net_crypto, (&data[sizeof(uint32_t)]) + crypto_box_PUBLICKEYBYTES); |
2640 | #ifdef ENABLE_ASSOC_DHT | ||
2641 | |||
2642 | if (m->dht->assoc) | ||
2643 | Assoc_self_client_id_changed(m->dht->assoc, m->net_crypto->self_public_key); | ||
2644 | 2640 | ||
2645 | #endif | 2641 | if (memcmp((&data[sizeof(uint32_t)]), m->net_crypto->self_public_key, crypto_box_PUBLICKEYBYTES) != 0) { |
2642 | return -1; | ||
2643 | } | ||
2646 | } else | 2644 | } else |
2647 | return -1; /* critical */ | 2645 | return -1; /* critical */ |
2648 | 2646 | ||
diff --git a/toxcore/crypto_core.h b/toxcore/crypto_core.h index d7306a8a..eefb1d90 100644 --- a/toxcore/crypto_core.h +++ b/toxcore/crypto_core.h | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <crypto_hash_sha512.h> | 35 | #include <crypto_hash_sha512.h> |
36 | #include <crypto_verify_16.h> | 36 | #include <crypto_verify_16.h> |
37 | #include <crypto_verify_32.h> | 37 | #include <crypto_verify_32.h> |
38 | #include <crypto_scalarmult_curve25519.h> | ||
38 | #define crypto_box_MACBYTES (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES) | 39 | #define crypto_box_MACBYTES (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES) |
39 | #endif | 40 | #endif |
40 | 41 | ||
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 762f5ebb..6d4f6a9b 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -2359,6 +2359,8 @@ void new_keys(Net_Crypto *c) | |||
2359 | 2359 | ||
2360 | /* Save the public and private keys to the keys array. | 2360 | /* Save the public and private keys to the keys array. |
2361 | * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES. | 2361 | * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES. |
2362 | * | ||
2363 | * TODO: Save only secret key. | ||
2362 | */ | 2364 | */ |
2363 | void save_keys(const Net_Crypto *c, uint8_t *keys) | 2365 | void save_keys(const Net_Crypto *c, uint8_t *keys) |
2364 | { | 2366 | { |
@@ -2366,13 +2368,13 @@ void save_keys(const Net_Crypto *c, uint8_t *keys) | |||
2366 | memcpy(keys + crypto_box_PUBLICKEYBYTES, c->self_secret_key, crypto_box_SECRETKEYBYTES); | 2368 | memcpy(keys + crypto_box_PUBLICKEYBYTES, c->self_secret_key, crypto_box_SECRETKEYBYTES); |
2367 | } | 2369 | } |
2368 | 2370 | ||
2369 | /* Load the public and private keys from the keys array. | 2371 | /* Load the secret key. |
2370 | * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES. | 2372 | * Length must be crypto_box_SECRETKEYBYTES. |
2371 | */ | 2373 | */ |
2372 | void load_keys(Net_Crypto *c, const uint8_t *keys) | 2374 | void load_secret_key(Net_Crypto *c, const uint8_t *sk) |
2373 | { | 2375 | { |
2374 | memcpy(c->self_public_key, keys, crypto_box_PUBLICKEYBYTES); | 2376 | memcpy(c->self_secret_key, sk, crypto_box_SECRETKEYBYTES); |
2375 | memcpy(c->self_secret_key, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES); | 2377 | crypto_scalarmult_curve25519_base(c->self_public_key, c->self_secret_key); |
2376 | } | 2378 | } |
2377 | 2379 | ||
2378 | /* Run this to (re)initialize net_crypto. | 2380 | /* Run this to (re)initialize net_crypto. |
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index c9e6d23a..56f43cc4 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -384,10 +384,10 @@ void new_keys(Net_Crypto *c); | |||
384 | */ | 384 | */ |
385 | void save_keys(const Net_Crypto *c, uint8_t *keys); | 385 | void save_keys(const Net_Crypto *c, uint8_t *keys); |
386 | 386 | ||
387 | /* Load the public and private keys from the keys array. | 387 | /* Load the secret key. |
388 | * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES. | 388 | * Length must be crypto_box_SECRETKEYBYTES. |
389 | */ | 389 | */ |
390 | void load_keys(Net_Crypto *c, const uint8_t *keys); | 390 | void load_secret_key(Net_Crypto *c, const uint8_t *sk); |
391 | 391 | ||
392 | /* Create new instance of Net_Crypto. | 392 | /* Create new instance of Net_Crypto. |
393 | * Sets all the global connection variables to their default values. | 393 | * Sets all the global connection variables to their default values. |