Load only secret key from tox save, not public key.

Calculate public key from it.
This commit is contained in:
irungentoo 2015-05-21 20:39:47 -04:00
parent 7315ad08dd
commit 2ba076ac5c
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
5 changed files with 19 additions and 14 deletions

View File

@ -332,6 +332,7 @@ START_TEST(test_one)
tox_self_set_name(tox1, name, sizeof(name), 0); tox_self_set_name(tox1, name, sizeof(name), 0);
ck_assert_msg(tox_self_get_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH"); ck_assert_msg(tox_self_get_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH");
tox_self_get_address(tox1, address);
size_t save_size = tox_get_savedata_size(tox1); size_t save_size = tox_get_savedata_size(tox1);
uint8_t data[save_size]; uint8_t data[save_size];
tox_get_savedata(tox1, data); tox_get_savedata(tox1, data);
@ -344,6 +345,9 @@ START_TEST(test_one)
ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size."); ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size.");
uint8_t address2[TOX_ADDRESS_SIZE];
tox_self_get_address(tox2, address2);
ck_assert_msg(memcmp(address2, address, TOX_ADDRESS_SIZE) == 0, "Wrong address.");
uint8_t new_name[TOX_MAX_NAME_LENGTH] = { 0 }; uint8_t new_name[TOX_MAX_NAME_LENGTH] = { 0 };
tox_self_get_name(tox2, new_name); tox_self_get_name(tox2, new_name);
ck_assert_msg(memcmp(name, new_name, TOX_MAX_NAME_LENGTH) == 0, "Wrong name"); ck_assert_msg(memcmp(name, new_name, TOX_MAX_NAME_LENGTH) == 0, "Wrong name");

View File

@ -2636,13 +2636,11 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
case MESSENGER_STATE_TYPE_NOSPAMKEYS: case MESSENGER_STATE_TYPE_NOSPAMKEYS:
if (length == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t)) { if (length == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t)) {
set_nospam(&(m->fr), *(uint32_t *)data); set_nospam(&(m->fr), *(uint32_t *)data);
load_keys(m->net_crypto, &data[sizeof(uint32_t)]); load_secret_key(m->net_crypto, (&data[sizeof(uint32_t)]) + crypto_box_PUBLICKEYBYTES);
#ifdef ENABLE_ASSOC_DHT
if (m->dht->assoc) if (memcmp((&data[sizeof(uint32_t)]), m->net_crypto->self_public_key, crypto_box_PUBLICKEYBYTES) != 0) {
Assoc_self_client_id_changed(m->dht->assoc, m->net_crypto->self_public_key); return -1;
}
#endif
} else } else
return -1; /* critical */ return -1; /* critical */

View File

@ -35,6 +35,7 @@
#include <crypto_hash_sha512.h> #include <crypto_hash_sha512.h>
#include <crypto_verify_16.h> #include <crypto_verify_16.h>
#include <crypto_verify_32.h> #include <crypto_verify_32.h>
#include <crypto_scalarmult_curve25519.h>
#define crypto_box_MACBYTES (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES) #define crypto_box_MACBYTES (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES)
#endif #endif

View File

@ -2359,6 +2359,8 @@ void new_keys(Net_Crypto *c)
/* Save the public and private keys to the keys array. /* Save the public and private keys to the keys array.
* Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES. * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES.
*
* TODO: Save only secret key.
*/ */
void save_keys(const Net_Crypto *c, uint8_t *keys) void save_keys(const Net_Crypto *c, uint8_t *keys)
{ {
@ -2366,13 +2368,13 @@ void save_keys(const Net_Crypto *c, uint8_t *keys)
memcpy(keys + crypto_box_PUBLICKEYBYTES, c->self_secret_key, crypto_box_SECRETKEYBYTES); memcpy(keys + crypto_box_PUBLICKEYBYTES, c->self_secret_key, crypto_box_SECRETKEYBYTES);
} }
/* Load the public and private keys from the keys array. /* Load the secret key.
* Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES. * Length must be crypto_box_SECRETKEYBYTES.
*/ */
void load_keys(Net_Crypto *c, const uint8_t *keys) void load_secret_key(Net_Crypto *c, const uint8_t *sk)
{ {
memcpy(c->self_public_key, keys, crypto_box_PUBLICKEYBYTES); memcpy(c->self_secret_key, sk, crypto_box_SECRETKEYBYTES);
memcpy(c->self_secret_key, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES); crypto_scalarmult_curve25519_base(c->self_public_key, c->self_secret_key);
} }
/* Run this to (re)initialize net_crypto. /* Run this to (re)initialize net_crypto.

View File

@ -384,10 +384,10 @@ void new_keys(Net_Crypto *c);
*/ */
void save_keys(const Net_Crypto *c, uint8_t *keys); void save_keys(const Net_Crypto *c, uint8_t *keys);
/* Load the public and private keys from the keys array. /* Load the secret key.
* Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES. * Length must be crypto_box_SECRETKEYBYTES.
*/ */
void load_keys(Net_Crypto *c, const uint8_t *keys); void load_secret_key(Net_Crypto *c, const uint8_t *sk);
/* Create new instance of Net_Crypto. /* Create new instance of Net_Crypto.
* Sets all the global connection variables to their default values. * Sets all the global connection variables to their default values.