mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Load only secret key from tox save, not public key.
Calculate public key from it.
This commit is contained in:
parent
7315ad08dd
commit
2ba076ac5c
|
@ -332,6 +332,7 @@ START_TEST(test_one)
|
|||
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");
|
||||
|
||||
tox_self_get_address(tox1, address);
|
||||
size_t save_size = tox_get_savedata_size(tox1);
|
||||
uint8_t data[save_size];
|
||||
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.");
|
||||
|
||||
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 };
|
||||
tox_self_get_name(tox2, new_name);
|
||||
ck_assert_msg(memcmp(name, new_name, TOX_MAX_NAME_LENGTH) == 0, "Wrong name");
|
||||
|
|
|
@ -2636,13 +2636,11 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
|
|||
case MESSENGER_STATE_TYPE_NOSPAMKEYS:
|
||||
if (length == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t)) {
|
||||
set_nospam(&(m->fr), *(uint32_t *)data);
|
||||
load_keys(m->net_crypto, &data[sizeof(uint32_t)]);
|
||||
#ifdef ENABLE_ASSOC_DHT
|
||||
load_secret_key(m->net_crypto, (&data[sizeof(uint32_t)]) + crypto_box_PUBLICKEYBYTES);
|
||||
|
||||
if (m->dht->assoc)
|
||||
Assoc_self_client_id_changed(m->dht->assoc, m->net_crypto->self_public_key);
|
||||
|
||||
#endif
|
||||
if (memcmp((&data[sizeof(uint32_t)]), m->net_crypto->self_public_key, crypto_box_PUBLICKEYBYTES) != 0) {
|
||||
return -1;
|
||||
}
|
||||
} else
|
||||
return -1; /* critical */
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <crypto_hash_sha512.h>
|
||||
#include <crypto_verify_16.h>
|
||||
#include <crypto_verify_32.h>
|
||||
#include <crypto_scalarmult_curve25519.h>
|
||||
#define crypto_box_MACBYTES (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES)
|
||||
#endif
|
||||
|
||||
|
|
|
@ -2359,6 +2359,8 @@ void new_keys(Net_Crypto *c)
|
|||
|
||||
/* Save the public and private keys to the keys array.
|
||||
* Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES.
|
||||
*
|
||||
* TODO: Save only secret key.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/* Load the public and private keys from the keys array.
|
||||
* Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES.
|
||||
/* Load the secret key.
|
||||
* 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, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES);
|
||||
memcpy(c->self_secret_key, sk, crypto_box_SECRETKEYBYTES);
|
||||
crypto_scalarmult_curve25519_base(c->self_public_key, c->self_secret_key);
|
||||
}
|
||||
|
||||
/* Run this to (re)initialize net_crypto.
|
||||
|
|
|
@ -384,10 +384,10 @@ void new_keys(Net_Crypto *c);
|
|||
*/
|
||||
void save_keys(const Net_Crypto *c, uint8_t *keys);
|
||||
|
||||
/* Load the public and private keys from the keys array.
|
||||
* Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES.
|
||||
/* Load the secret key.
|
||||
* 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.
|
||||
* Sets all the global connection variables to their default values.
|
||||
|
|
Loading…
Reference in New Issue
Block a user