33#include <string.h>
44#include <sys/types.h>
55
6- #include <sodium.h>
7-
86#include "../testing/misc_tools.h"
97#include "../toxcore/ccompat.h"
108#include "../toxcore/crypto_core.h"
1412#include "check_compat.h"
1513
1614static unsigned char test_salt [TOX_PASS_SALT_LENGTH ] = {0xB1 , 0xC2 , 0x09 , 0xEE , 0x50 , 0x6C , 0xF0 , 0x20 , 0xC4 , 0xD6 , 0xEB , 0xC0 , 0x44 , 0x51 , 0x3B , 0x60 , 0x4B , 0x39 , 0x4A , 0xCF , 0x09 , 0x53 , 0x4F , 0xEA , 0x08 , 0x41 , 0xFA , 0xCA , 0x66 , 0xD2 , 0x68 , 0x7F };
17- static unsigned char known_key [TOX_PASS_KEY_LENGTH ] = {0x29 , 0x36 , 0x1c , 0x9e , 0x65 , 0xbb , 0x46 , 0x8b , 0xde , 0xa1 , 0xac , 0xf , 0xd5 , 0x11 , 0x81 , 0xc8 , 0x29 , 0x28 , 0x17 , 0x23 , 0xa6 , 0xc3 , 0x6b , 0x77 , 0x2e , 0xd7 , 0xd3 , 0x10 , 0xeb , 0xd2 , 0xf7 , 0xc8 };
15+ static unsigned char known_key [CRYPTO_SHARED_KEY_SIZE ] = {0x7a , 0xfa , 0x95 , 0x45 , 0x36 , 0x8a , 0xa2 , 0x5c , 0x40 , 0xfd , 0xc0 , 0xe2 , 0x35 , 0x8 , 0x7 , 0x88 , 0xfa , 0xf9 , 0x37 , 0x86 , 0xeb , 0xff , 0x50 , 0x4f , 0x3 , 0xe2 , 0xf6 , 0xd9 , 0xef , 0x9 , 0x17 , 0x1 };
1816static const char * pw = "hunter2" ;
1917static unsigned int pwlen = 7 ;
2018
21- static unsigned char known_key2 [CRYPTO_SHARED_KEY_SIZE ] = {0x7a , 0xfa , 0x95 , 0x45 , 0x36 , 0x8a , 0xa2 , 0x5c , 0x40 , 0xfd , 0xc0 , 0xe2 , 0x35 , 0x8 , 0x7 , 0x88 , 0xfa , 0xf9 , 0x37 , 0x86 , 0xeb , 0xff , 0x50 , 0x4f , 0x3 , 0xe2 , 0xf6 , 0xd9 , 0xef , 0x9 , 0x17 , 0x1 };
22- // same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat
23-
2419/* cause I'm shameless */
2520static void accept_friend_request (Tox * m , const uint8_t * public_key , const uint8_t * data , size_t length , void * userdata )
2621{
@@ -33,20 +28,6 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
3328 }
3429}
3530
36- static void test_known_kdf (void )
37- {
38- unsigned char out [CRYPTO_SHARED_KEY_SIZE ];
39- int16_t res = crypto_pwhash_scryptsalsa208sha256 (out ,
40- CRYPTO_SHARED_KEY_SIZE ,
41- pw ,
42- pwlen ,
43- test_salt ,
44- crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE * 8 ,
45- crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE );
46- ck_assert_msg (res != -1 , "crypto function failed" );
47- ck_assert_msg (memcmp (out , known_key , CRYPTO_SHARED_KEY_SIZE ) == 0 , "derived key is wrong" );
48- }
49-
5031static void test_save_friend (void )
5132{
5233 Tox * tox1 = tox_new_log (nullptr , nullptr , nullptr );
@@ -101,7 +82,7 @@ static void test_save_friend(void)
10182 Tox_Pass_Key * key = tox_pass_key_derive ((const uint8_t * )"123qweasdzxc" , 12 , & keyerr );
10283 ck_assert_msg (key != nullptr , "pass key allocation failure" );
10384 memcpy ((uint8_t * )key , test_salt , TOX_PASS_SALT_LENGTH );
104- memcpy ((uint8_t * )key + TOX_PASS_SALT_LENGTH , known_key2 , TOX_PASS_KEY_LENGTH );
85+ memcpy ((uint8_t * )key + TOX_PASS_SALT_LENGTH , known_key , TOX_PASS_KEY_LENGTH );
10586 size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH ;
10687 uint8_t * encdata2 = (uint8_t * )malloc (size2 );
10788 ck_assert (encdata2 != nullptr );
@@ -224,7 +205,6 @@ static void test_keys(void)
224205int main (void )
225206{
226207 setvbuf (stdout , nullptr , _IONBF , 0 );
227- test_known_kdf ();
228208 test_save_friend ();
229209 test_keys ();
230210
0 commit comments