summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/encryptsave_test.c68
-rw-r--r--auto_tests/tox_test.c24
-rw-r--r--toxcore/Messenger.c9
-rw-r--r--toxcore/Messenger.h8
-rw-r--r--toxcore/network.c11
-rw-r--r--toxcore/tox.h8
-rw-r--r--toxencryptsave/toxencryptsave.c38
-rw-r--r--toxencryptsave/toxencryptsave.h27
8 files changed, 98 insertions, 95 deletions
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c
index 338c9ef1..de78a0c2 100644
--- a/auto_tests/encryptsave_test.c
+++ b/auto_tests/encryptsave_test.c
@@ -29,13 +29,13 @@ unsigned char known_key2[crypto_box_BEFORENMBYTES] = {0x7a, 0xfa, 0x95, 0x45, 0x
29// same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat 29// same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat
30 30
31/* cause I'm shameless */ 31/* cause I'm shameless */
32void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) 32void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
33{ 33{
34 if (*((uint32_t *)userdata) != 974536) 34 if (*((uint32_t *)userdata) != 974536)
35 return; 35 return;
36 36
37 if (length == 7 && memcmp("Gentoo", data, 7) == 0) { 37 if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
38 tox_add_friend_norequest(m, public_key); 38 tox_friend_add_norequest(m, public_key, 0);
39 } 39 }
40} 40}
41 41
@@ -55,29 +55,29 @@ END_TEST
55 55
56START_TEST(test_save_friend) 56START_TEST(test_save_friend)
57{ 57{
58 Tox *tox1 = tox_new(0); 58 TOX_ERR_NEW err = TOX_ERR_NEW_OK;
59 Tox *tox2 = tox_new(0); 59 Tox *tox1 = tox_new(0, 0, 0, 0);
60 Tox *tox2 = tox_new(0, 0, 0, 0);
60 ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); 61 ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances");
61 uint32_t to_compare = 974536; 62 uint32_t to_compare = 974536;
62 tox_callback_friend_request(tox2, accept_friend_request, &to_compare); 63 tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
63 uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; 64 uint8_t address[TOX_ADDRESS_SIZE];
64 tox_get_address(tox2, address); 65 tox_self_get_address(tox2, address);
65 int test = tox_add_friend(tox1, address, (uint8_t *)"Gentoo", 7); 66 int test = tox_friend_add(tox1, address, (uint8_t *)"Gentoo", 7, 0);
66 ck_assert_msg(test == 0, "Failed to add friend error code: %i", test); 67 ck_assert_msg(test == 0, "Failed to add friend error code: %i", test);
67 68
68 uint32_t size = tox_encrypted_size(tox1); 69 uint32_t size = tox_encrypted_size(tox1);
69 uint8_t data[size]; 70 uint8_t data[size];
70 test = tox_encrypted_save(tox1, data, "correcthorsebatterystaple", 25); 71 test = tox_encrypted_save(tox1, data, "correcthorsebatterystaple", 25);
71 ck_assert_msg(test == 0, "failed to encrypted save"); 72 ck_assert_msg(test == 0, "failed to encrypted save");
72 ck_assert_msg(tox_is_save_encrypted(data) == 1, "magic number missing"); 73 //ck_assert_msg(tox_is_save_encrypted(data) == 1, "magic number missing");
73 74
74 Tox *tox3 = tox_new(0); 75 Tox *tox3 = tox_encrypted_new(0, data, size, "correcthorsebatterystaple", 25, &err);
75 test = tox_encrypted_load(tox3, data, size, "correcthorsebatterystaple", 25); 76 ck_assert_msg(err == TOX_ERR_NEW_OK, "failed to encrypted new");
76 ck_assert_msg(test == 0, "failed to encrypted load"); 77 uint8_t address2[TOX_PUBLIC_KEY_SIZE];
77 uint8_t address2[TOX_CLIENT_ID_SIZE]; 78 test = tox_friend_get_public_key(tox3, 0, address2, 0);
78 test = tox_get_client_id(tox3, 0, address2); 79 ck_assert_msg(test == 1, "no friends!");
79 ck_assert_msg(test == 0, "no friends!"); 80 ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match!");
80 ck_assert_msg(memcmp(address, address2, TOX_CLIENT_ID_SIZE) == 0, "addresses don't match!");
81 81
82 size = tox_encrypted_size(tox3); 82 size = tox_encrypted_size(tox3);
83 uint8_t data2[size]; 83 uint8_t data2[size];
@@ -86,20 +86,19 @@ START_TEST(test_save_friend)
86 memcpy(key + 32, known_key2, crypto_box_BEFORENMBYTES); 86 memcpy(key + 32, known_key2, crypto_box_BEFORENMBYTES);
87 test = tox_encrypted_key_save(tox3, data2, key); 87 test = tox_encrypted_key_save(tox3, data2, key);
88 ck_assert_msg(test == 0, "failed to encrypted save the second"); 88 ck_assert_msg(test == 0, "failed to encrypted save the second");
89 ck_assert_msg(tox_is_save_encrypted(data2) == 1, "magic number the second missing"); 89 //ck_assert_msg(tox_is_save_encrypted(data2) == 1, "magic number the second missing");
90 90
91 // first test tox_encrypted_key_load 91 // first test tox_encrypted_key_new
92 Tox *tox4 = tox_new(0); 92 Tox *tox4 = tox_encrypted_key_new(0, data2, size, key, &err);
93 test = tox_encrypted_key_load(tox4, data2, size, key); 93 ck_assert_msg(err == TOX_ERR_NEW_OK, "failed to encrypted new the second");
94 ck_assert_msg(test == 0, "failed to encrypted load the second"); 94 uint8_t address4[TOX_PUBLIC_KEY_SIZE];
95 uint8_t address4[TOX_CLIENT_ID_SIZE]; 95 test = tox_friend_get_public_key(tox4, 0, address4, 0);
96 test = tox_get_client_id(tox4, 0, address4); 96 ck_assert_msg(test == 1, "no friends! the second");
97 ck_assert_msg(test == 0, "no friends! the second"); 97 ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match! the second");
98 ck_assert_msg(memcmp(address, address2, TOX_CLIENT_ID_SIZE) == 0, "addresses don't match! the second"); 98
99 99 // now test compaitibilty with tox_encrypted_new, first manually...
100 // now test compaitibilty with tox_encrypted_load, first manually...
101 uint8_t out1[size], out2[size]; 100 uint8_t out1[size], out2[size];
102 printf("Trying to decrypt from pw:\n"); 101 //printf("Trying to decrypt from pw:\n");
103 uint32_t sz1 = tox_pass_decrypt(data2, size, pw, pwlen, out1); 102 uint32_t sz1 = tox_pass_decrypt(data2, size, pw, pwlen, out1);
104 uint32_t sz2 = tox_pass_key_decrypt(data2, size, key, out2); 103 uint32_t sz2 = tox_pass_key_decrypt(data2, size, key, out2);
105 ck_assert_msg(sz1 == sz2, "differing output sizes"); 104 ck_assert_msg(sz1 == sz2, "differing output sizes");
@@ -107,13 +106,12 @@ START_TEST(test_save_friend)
107 106
108 // and now with the code in use (I only bothered with manually to debug this, and it seems a waste 107 // and now with the code in use (I only bothered with manually to debug this, and it seems a waste
109 // to remove the manual check now that it's there) 108 // to remove the manual check now that it's there)
110 Tox *tox5 = tox_new(0); 109 Tox *tox5 = tox_encrypted_new(0, data2, size, pw, pwlen, &err);
111 test = tox_encrypted_load(tox5, data2, size, pw, pwlen); 110 ck_assert_msg(err == TOX_ERR_NEW_OK, "failed to encrypted new the third");
112 ck_assert_msg(test == 0, "failed to encrypted load the third"); 111 uint8_t address5[TOX_PUBLIC_KEY_SIZE];
113 uint8_t address5[TOX_CLIENT_ID_SIZE]; 112 test = tox_friend_get_public_key(tox4, 0, address5, 0);
114 test = tox_get_client_id(tox4, 0, address5); 113 ck_assert_msg(test == 1, "no friends! the third");
115 ck_assert_msg(test == 0, "no friends! the third"); 114 ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match! the third");
116 ck_assert_msg(memcmp(address, address2, TOX_CLIENT_ID_SIZE) == 0, "addresses don't match! the third");
117 115
118 tox_kill(tox1); 116 tox_kill(tox1);
119 tox_kill(tox2); 117 tox_kill(tox2);
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index d9cb46db..d7a44fb2 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -503,13 +503,13 @@ END_TEST
503 503
504#define NUM_GROUP_TOX 32 504#define NUM_GROUP_TOX 32
505 505
506void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) 506void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
507{ 507{
508 if (*((uint32_t *)userdata) != 234212) 508 if (*((uint32_t *)userdata) != 234212)
509 return; 509 return;
510 510
511 if (length == 7 && memcmp("Gentoo", data, 7) == 0) { 511 if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
512 tox_add_friend_norequest(m, public_key); 512 tox_friend_add_norequest(m, public_key, 0);
513 } 513 }
514} 514}
515 515
@@ -560,24 +560,24 @@ START_TEST(test_many_group)
560 uint32_t to_comp = 234212; 560 uint32_t to_comp = 234212;
561 561
562 for (i = 0; i < NUM_GROUP_TOX; ++i) { 562 for (i = 0; i < NUM_GROUP_TOX; ++i) {
563 toxes[i] = tox_new(0); 563 toxes[i] = tox_new(0, 0, 0, 0);
564 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); 564 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
565 tox_callback_friend_request(toxes[i], &g_accept_friend_request, &to_comp); 565 tox_callback_friend_request(toxes[i], &g_accept_friend_request, &to_comp);
566 tox_callback_group_invite(toxes[i], &print_group_invite_callback, &to_comp); 566 tox_callback_group_invite(toxes[i], &print_group_invite_callback, &to_comp);
567 } 567 }
568 568
569 uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; 569 uint8_t address[TOX_ADDRESS_SIZE];
570 tox_get_address(toxes[NUM_GROUP_TOX - 1], address); 570 tox_self_get_address(toxes[NUM_GROUP_TOX - 1], address);
571 571
572 for (i = 0; i < NUM_GROUP_TOX; ++i) { 572 for (i = 0; i < NUM_GROUP_TOX; ++i) {
573 ck_assert_msg(tox_add_friend(toxes[i], address, (uint8_t *)"Gentoo", 7) == 0, "Failed to add friend"); 573 ck_assert_msg(tox_friend_add(toxes[i], address, (uint8_t *)"Gentoo", 7, 0) == 0, "Failed to add friend");
574 574
575 tox_get_address(toxes[i], address); 575 tox_self_get_address(toxes[i], address);
576 } 576 }
577 577
578 while (1) { 578 while (1) {
579 for (i = 0; i < NUM_GROUP_TOX; ++i) { 579 for (i = 0; i < NUM_GROUP_TOX; ++i) {
580 if (tox_get_friend_connection_status(toxes[i], 0) != 1) { 580 if (tox_friend_get_connection_status(toxes[i], 0, 0) != TOX_CONNECTION_UDP) {
581 break; 581 break;
582 } 582 }
583 } 583 }
@@ -586,7 +586,7 @@ START_TEST(test_many_group)
586 break; 586 break;
587 587
588 for (i = 0; i < NUM_GROUP_TOX; ++i) { 588 for (i = 0; i < NUM_GROUP_TOX; ++i) {
589 tox_do(toxes[i]); 589 tox_iteration(toxes[i]);
590 } 590 }
591 591
592 c_sleep(50); 592 c_sleep(50);
@@ -604,7 +604,7 @@ START_TEST(test_many_group)
604 604
605 while (1) { 605 while (1) {
606 for (i = 0; i < NUM_GROUP_TOX; ++i) { 606 for (i = 0; i < NUM_GROUP_TOX; ++i) {
607 tox_do(toxes[i]); 607 tox_iteration(toxes[i]);
608 } 608 }
609 609
610 if (!invite_counter) { 610 if (!invite_counter) {
@@ -642,7 +642,7 @@ START_TEST(test_many_group)
642 642
643 for (j = 0; j < 20; ++j) { 643 for (j = 0; j < 20; ++j) {
644 for (i = 0; i < NUM_GROUP_TOX; ++i) { 644 for (i = 0; i < NUM_GROUP_TOX; ++i) {
645 tox_do(toxes[i]); 645 tox_iteration(toxes[i]);
646 } 646 }
647 647
648 c_sleep(50); 648 c_sleep(50);
@@ -655,7 +655,7 @@ START_TEST(test_many_group)
655 655
656 for (j = 0; j < 10; ++j) { 656 for (j = 0; j < 10; ++j) {
657 for (i = 0; i < NUM_GROUP_TOX; ++i) { 657 for (i = 0; i < NUM_GROUP_TOX; ++i) {
658 tox_do(toxes[i]); 658 tox_iteration(toxes[i]);
659 } 659 }
660 660
661 c_sleep(50); 661 c_sleep(50);
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 544b8b0d..f6c37ac4 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1002,8 +1002,8 @@ void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, u
1002 * return 1 on success 1002 * return 1 on success
1003 * return 0 on failure 1003 * return 0 on failure
1004 */ 1004 */
1005int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, 1005static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize,
1006 const uint8_t *filename, uint16_t filename_length) 1006 const uint8_t *filename, uint16_t filename_length)
1007{ 1007{
1008 if (friend_not_valid(m, friendnumber)) 1008 if (friend_not_valid(m, friendnumber))
1009 return 0; 1009 return 0;
@@ -1612,11 +1612,6 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
1612 if (packet_id == PACKET_ID_ONLINE && len == 1) { 1612 if (packet_id == PACKET_ID_ONLINE && len == 1) {
1613 set_friend_status(m, i, FRIEND_ONLINE); 1613 set_friend_status(m, i, FRIEND_ONLINE);
1614 send_online_packet(m, i); 1614 send_online_packet(m, i);
1615 } else if (packet_id == PACKET_ID_NICKNAME || packet_id == PACKET_ID_STATUSMESSAGE
1616 || packet_id == PACKET_ID_USERSTATUS) {
1617 /* Some backward compatibility, TODO: remove. */
1618 set_friend_status(m, i, FRIEND_ONLINE);
1619 send_online_packet(m, i);
1620 } else { 1615 } else {
1621 return -1; 1616 return -1;
1622 } 1617 }
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 4659ddf9..541894ab 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -578,14 +578,6 @@ void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, u
578 578
579/* Send a file send request. 579/* Send a file send request.
580 * Maximum filename length is 255 bytes. 580 * Maximum filename length is 255 bytes.
581 * return 1 on success
582 * return 0 on failure
583 */
584int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize,
585 const uint8_t *filename, uint16_t filename_length);
586
587/* Send a file send request.
588 * Maximum filename length is 255 bytes.
589 * return file number on success 581 * return file number on success
590 * return -1 on failure 582 * return -1 on failure
591 */ 583 */
diff --git a/toxcore/network.c b/toxcore/network.c
index 9433e368..1488d980 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -488,17 +488,14 @@ Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to)
488 * If one is 0 and the other is non-0, use the non-0 value as only port 488 * If one is 0 and the other is non-0, use the non-0 value as only port
489 * If from > to, swap 489 * If from > to, swap
490 */ 490 */
491 if(port_from == 0 && port_to == 0) { 491 if (port_from == 0 && port_to == 0) {
492 port_from = TOX_PORTRANGE_FROM; 492 port_from = TOX_PORTRANGE_FROM;
493 port_to = TOX_PORTRANGE_TO; 493 port_to = TOX_PORTRANGE_TO;
494 } 494 } else if (port_from == 0 && port_to != 0) {
495 else if(port_from == 0 && port_to != 0) {
496 port_from = port_to; 495 port_from = port_to;
497 } 496 } else if (port_from != 0 && port_to == 0) {
498 else if(port_from != 0 && port_to == 0) {
499 port_to = port_from; 497 port_to = port_from;
500 } 498 } else if (port_from > port_to) {
501 else if(port_from > port_to) {
502 uint16_t temp = port_from; 499 uint16_t temp = port_from;
503 port_from = port_to; 500 port_from = port_to;
504 port_to = temp; 501 port_to = temp;
diff --git a/toxcore/tox.h b/toxcore/tox.h
index a66bcb17..8a489411 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -463,6 +463,14 @@ enum TOX_ERR_NEW {
463 */ 463 */
464 TOX_ERR_NEW_LOAD_ENCRYPTED, 464 TOX_ERR_NEW_LOAD_ENCRYPTED,
465 /** 465 /**
466 * The encrypted byte array could not be decrypted. Either the data was
467 * corrupt or the password/key was incorrect.
468 *
469 * NOTE: This error code is only set by tox_encrypted_new() and
470 * tox_encrypted_key_new(), in the toxencryptsave module.
471 */
472 TOX_ERR_NEW_LOAD_DECRYPTION_FAILED,
473 /**
466 * The data format was invalid. This can happen when loading data that was 474 * The data format was invalid. This can happen when loading data that was
467 * saved by an older version of Tox, or when the data has been corrupted. 475 * saved by an older version of Tox, or when the data has been corrupted.
468 * When loading from badly formatted data, some data may have been loaded, 476 * When loading from badly formatted data, some data may have been loaded,
diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c
index 13a34dea..f9846ac9 100644
--- a/toxencryptsave/toxencryptsave.c
+++ b/toxencryptsave/toxencryptsave.c
@@ -29,6 +29,7 @@
29#include "defines.h" 29#include "defines.h"
30#include "../toxcore/crypto_core.h" 30#include "../toxcore/crypto_core.h"
31#include "../toxcore/tox.h" 31#include "../toxcore/tox.h"
32#define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}}
32 33
33#ifdef VANILLA_NACL 34#ifdef VANILLA_NACL
34#include "crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" 35#include "crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h"
@@ -293,38 +294,44 @@ int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase,
293 return tox_pass_key_decrypt(data, length, key, out); 294 return tox_pass_key_decrypt(data, length, key, out);
294} 295}
295 296
296/* Load the messenger from encrypted data of size length. 297/* Load the new messenger from encrypted data of size length.
298 * All other arguments are like toxcore/tox_new().
297 * 299 *
298 * returns 0 on success 300 * returns NULL on failure; see the documentation in toxcore/tox.h.
299 * returns -1 on failure
300 */ 301 */
301int tox_encrypted_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength) 302Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase,
303 size_t pplength, TOX_ERR_NEW *error)
302{ 304{
303 uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; 305 uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
304 uint8_t temp_data[decrypt_length]; 306 uint8_t temp_data[decrypt_length];
305 307
306 if (tox_pass_decrypt(data, length, passphrase, pplength, temp_data) 308 if (tox_pass_decrypt(data, length, passphrase, pplength, temp_data)
307 != decrypt_length) 309 != decrypt_length) {
308 return -1; 310 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_DECRYPTION_FAILED);
311 return NULL;
312 }
309 313
310 return tox_load(tox, temp_data, decrypt_length); 314 return tox_new(options, temp_data, decrypt_length, error);
311} 315}
312 316
313/* Load the messenger from encrypted data of size length, with key from tox_derive_key. 317/* Load the messenger from encrypted data of size length, with key from tox_derive_key.
318 * All other arguments are like toxcore/tox_new().
314 * 319 *
315 * returns 0 on success 320 * returns NULL on failure; see the documentation in toxcore/tox.h.
316 * returns -1 on failure
317 */ 321 */
318int tox_encrypted_key_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *key) 322Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key,
323 TOX_ERR_NEW *error)
319{ 324{
320 uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; 325 uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
321 uint8_t temp_data[decrypt_length]; 326 uint8_t temp_data[decrypt_length];
322 327
323 if (tox_pass_key_decrypt(data, length, key, temp_data) 328 if (tox_pass_key_decrypt(data, length, key, temp_data)
324 != decrypt_length) 329 != decrypt_length) {
325 return -1; 330 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_DECRYPTION_FAILED);
331 return NULL;
332 }
326 333
327 return tox_load(tox, temp_data, decrypt_length); 334 return tox_new(options, temp_data, decrypt_length, error);
328} 335}
329 336
330/* Determines whether or not the given data is encrypted (by checking the magic number) 337/* Determines whether or not the given data is encrypted (by checking the magic number)
@@ -339,8 +346,3 @@ int tox_is_data_encrypted(const uint8_t *data)
339 else 346 else
340 return 0; 347 return 0;
341} 348}
342
343int tox_is_save_encrypted(const uint8_t *data)
344{
345 return tox_is_data_encrypted(data);
346}
diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h
index da13f312..5ceeefdd 100644
--- a/toxencryptsave/toxencryptsave.h
+++ b/toxencryptsave/toxencryptsave.h
@@ -29,10 +29,13 @@ extern "C" {
29#endif 29#endif
30 30
31#include <stdint.h> 31#include <stdint.h>
32#include <stddef.h>
32 33
33#ifndef TOX_DEFINED 34#ifndef TOX_DEFINED
34#define TOX_DEFINED 35#define TOX_DEFINED
35typedef struct Tox Tox; 36typedef struct Tox Tox;
37struct Tox_Options;
38typedef uint8_t TOX_ERR_NEW;
36#endif 39#endif
37 40
38// these functions provide access to these defines in toxencryptsave.c, which 41// these functions provide access to these defines in toxencryptsave.c, which
@@ -88,6 +91,9 @@ int tox_pass_encrypt(const uint8_t *data, uint32_t data_len, uint8_t *passphrase
88/* Save the messenger data encrypted with the given password. 91/* Save the messenger data encrypted with the given password.
89 * data must be at least tox_encrypted_size(). 92 * data must be at least tox_encrypted_size().
90 * 93 *
94 * NOTE: Unlike tox_save(), this function may fail. Be sure to check its return
95 * value.
96 *
91 * returns 0 on success 97 * returns 0 on success
92 * returns -1 on failure 98 * returns -1 on failure
93 */ 99 */
@@ -104,12 +110,13 @@ int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint3
104 */ 110 */
105int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength, uint8_t *out); 111int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength, uint8_t *out);
106 112
107/* Load the messenger from encrypted data of size length. 113/* Load the new messenger from encrypted data of size length.
114 * All other arguments are like toxcore/tox_new().
108 * 115 *
109 * returns 0 on success 116 * returns NULL on failure; see the documentation in toxcore/tox.h.
110 * returns -1 on failure
111 */ 117 */
112int tox_encrypted_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength); 118Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase,
119 size_t pplength, TOX_ERR_NEW *error);
113 120
114 121
115/******************************* BEGIN PART 1 ******************************* 122/******************************* BEGIN PART 1 *******************************
@@ -161,6 +168,9 @@ int tox_pass_key_encrypt(const uint8_t *data, uint32_t data_len, const uint8_t *
161/* Save the messenger data encrypted with the given key from tox_derive_key. 168/* Save the messenger data encrypted with the given key from tox_derive_key.
162 * data must be at least tox_encrypted_size(). 169 * data must be at least tox_encrypted_size().
163 * 170 *
171 * NOTE: Unlike tox_save(), this function may fail. Be sure to check its return
172 * value.
173 *
164 * returns 0 on success 174 * returns 0 on success
165 * returns -1 on failure 175 * returns -1 on failure
166 */ 176 */
@@ -175,11 +185,13 @@ int tox_encrypted_key_save(const Tox *tox, uint8_t *data, uint8_t *key);
175int tox_pass_key_decrypt(const uint8_t *data, uint32_t length, const uint8_t *key, uint8_t *out); 185int tox_pass_key_decrypt(const uint8_t *data, uint32_t length, const uint8_t *key, uint8_t *out);
176 186
177/* Load the messenger from encrypted data of size length, with key from tox_derive_key. 187/* Load the messenger from encrypted data of size length, with key from tox_derive_key.
188 * All other arguments are like toxcore/tox_new().
178 * 189 *
179 * returns 0 on success 190 * returns NULL on failure; see the documentation in toxcore/tox.h.
180 * returns -1 on failure
181 */ 191 */
182int tox_encrypted_key_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *key); 192Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key,
193 TOX_ERR_NEW *error);
194
183 195
184/* Determines whether or not the given data is encrypted (by checking the magic number) 196/* Determines whether or not the given data is encrypted (by checking the magic number)
185 * 197 *
@@ -187,7 +199,6 @@ int tox_encrypted_key_load(Tox *tox, const uint8_t *data, uint32_t length, uint8
187 * returns 0 otherwise 199 * returns 0 otherwise
188 */ 200 */
189int tox_is_data_encrypted(const uint8_t *data); 201int tox_is_data_encrypted(const uint8_t *data);
190int tox_is_save_encrypted(const uint8_t *data); // poorly-named alias for backwards compat (oh irony...)
191 202
192#ifdef __cplusplus 203#ifdef __cplusplus
193} 204}