summaryrefslogtreecommitdiff
path: root/auto_tests/encryptsave_test.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-11-25 15:31:46 -0500
committerirungentoo <irungentoo@gmail.com>2014-11-25 15:31:46 -0500
commit89f2436fac93491d9830bcf7a41ff49ea7721104 (patch)
treefd4b838a4086dece4a2625f5d2758b890e118a69 /auto_tests/encryptsave_test.c
parent28ffa035cb9e19ffed73255b9cde9657da57b79b (diff)
Astyle autotests.
Diffstat (limited to 'auto_tests/encryptsave_test.c')
-rw-r--r--auto_tests/encryptsave_test.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c
index 3045fbfa..aa5bef3f 100644
--- a/auto_tests/encryptsave_test.c
+++ b/auto_tests/encryptsave_test.c
@@ -20,12 +20,12 @@
20#include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h" /* sodium_memzero */ 20#include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h" /* sodium_memzero */
21#endif 21#endif
22 22
23unsigned char salt[32] = {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}; 23unsigned char salt[32] = {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};
24unsigned char known_key[crypto_box_BEFORENMBYTES] = {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}; 24unsigned char known_key[crypto_box_BEFORENMBYTES] = {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};
25char* pw = "hunter2"; 25char *pw = "hunter2";
26unsigned int pwlen = 7; 26unsigned int pwlen = 7;
27 27
28unsigned char known_key2[crypto_box_BEFORENMBYTES] = {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}; 28unsigned char known_key2[crypto_box_BEFORENMBYTES] = {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};
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 */
@@ -49,7 +49,7 @@ START_TEST(test_known_kdf)
49 salt, 49 salt,
50 crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE * 8, 50 crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE * 8,
51 crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE); 51 crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE);
52 ck_assert_msg(memcmp(out, known_key, crypto_box_BEFORENMBYTES) == 0, "derived key is wrong"); 52 ck_assert_msg(memcmp(out, known_key, crypto_box_BEFORENMBYTES) == 0, "derived key is wrong");
53} 53}
54END_TEST 54END_TEST
55 55
@@ -82,13 +82,14 @@ START_TEST(test_save_friend)
82 size = tox_encrypted_size(tox3); 82 size = tox_encrypted_size(tox3);
83 uint8_t data2[size]; 83 uint8_t data2[size];
84 uint8_t key[32 + crypto_box_BEFORENMBYTES]; 84 uint8_t key[32 + crypto_box_BEFORENMBYTES];
85 memcpy(key, salt, 32); memcpy(key+32, known_key2, crypto_box_BEFORENMBYTES); 85 memcpy(key, salt, 32);
86 memcpy(key + 32, known_key2, crypto_box_BEFORENMBYTES);
86 test = tox_encrypted_key_save(tox3, data2, key); 87 test = tox_encrypted_key_save(tox3, data2, key);
87 ck_assert_msg(test == 0, "failed to encrypted save the second"); 88 ck_assert_msg(test == 0, "failed to encrypted save the second");
88 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");
89 90
90 // first test tox_encrypted_key_load 91 // first test tox_encrypted_key_load
91 Tox* tox4 = tox_new(0); 92 Tox *tox4 = tox_new(0);
92 test = tox_encrypted_key_load(tox4, data2, size, key); 93 test = tox_encrypted_key_load(tox4, data2, size, key);
93 ck_assert_msg(test == 0, "failed to encrypted load the second"); 94 ck_assert_msg(test == 0, "failed to encrypted load the second");
94 uint8_t address4[TOX_CLIENT_ID_SIZE]; 95 uint8_t address4[TOX_CLIENT_ID_SIZE];
@@ -106,7 +107,7 @@ START_TEST(test_save_friend)
106 107
107 // and now with the code in use (I only bothered with manually to debug this, and it seems a waste 108 // and now with the code in use (I only bothered with manually to debug this, and it seems a waste
108 // to remove the manual check now that it's there) 109 // to remove the manual check now that it's there)
109 Tox* tox5 = tox_new(0); 110 Tox *tox5 = tox_new(0);
110 test = tox_encrypted_load(tox5, data2, size, pw, pwlen); 111 test = tox_encrypted_load(tox5, data2, size, pw, pwlen);
111 ck_assert_msg(test == 0, "failed to encrypted load the third"); 112 ck_assert_msg(test == 0, "failed to encrypted load the third");
112 uint8_t address5[TOX_CLIENT_ID_SIZE]; 113 uint8_t address5[TOX_CLIENT_ID_SIZE];
@@ -120,29 +121,29 @@ START_TEST(test_keys)
120{ 121{
121 uint8_t key[tox_pass_key_length()]; 122 uint8_t key[tox_pass_key_length()];
122 tox_derive_key_from_pass("123qweasdzxc", 12, key); 123 tox_derive_key_from_pass("123qweasdzxc", 12, key);
123 uint8_t* string = "No Patrick, mayonnaise is not an instrument."; // 44 124 uint8_t *string = "No Patrick, mayonnaise is not an instrument."; // 44
124 125
125 uint8_t encrypted[44+tox_pass_encryption_extra_length()]; 126 uint8_t encrypted[44 + tox_pass_encryption_extra_length()];
126 int sz = tox_pass_key_encrypt(string, 44, key, encrypted); 127 int sz = tox_pass_key_encrypt(string, 44, key, encrypted);
127 128
128 uint8_t encrypted2[44+tox_pass_encryption_extra_length()]; 129 uint8_t encrypted2[44 + tox_pass_encryption_extra_length()];
129 int sz2 = tox_pass_encrypt(string, 44, "123qweasdzxc", 12, encrypted2); 130 int sz2 = tox_pass_encrypt(string, 44, "123qweasdzxc", 12, encrypted2);
130 131
131 ck_assert_msg(sz == sz2, "an encryption failed"); 132 ck_assert_msg(sz == sz2, "an encryption failed");
132 133
133 uint8_t out1[44+tox_pass_encryption_extra_length()]; 134 uint8_t out1[44 + tox_pass_encryption_extra_length()];
134 uint8_t out2[44+tox_pass_encryption_extra_length()]; 135 uint8_t out2[44 + tox_pass_encryption_extra_length()];
135 136
136 sz = tox_pass_key_decrypt(encrypted, 44+tox_pass_encryption_extra_length(), key, out1); 137 sz = tox_pass_key_decrypt(encrypted, 44 + tox_pass_encryption_extra_length(), key, out1);
137 ck_assert_msg(sz == 44, "sz isn't right"); 138 ck_assert_msg(sz == 44, "sz isn't right");
138 ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 1 failed"); 139 ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 1 failed");
139 140
140 sz2 = tox_pass_decrypt(encrypted2, 44+tox_pass_encryption_extra_length(), "123qweasdzxc", 12, out2); 141 sz2 = tox_pass_decrypt(encrypted2, 44 + tox_pass_encryption_extra_length(), "123qweasdzxc", 12, out2);
141 ck_assert_msg(sz2 == 44, "sz2 isn't right"); 142 ck_assert_msg(sz2 == 44, "sz2 isn't right");
142 ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed"); 143 ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed");
143 144
144 // test that pass_decrypt can decrypt things from pass_key_encrypt 145 // test that pass_decrypt can decrypt things from pass_key_encrypt
145 sz = tox_pass_decrypt(encrypted, 44+tox_pass_encryption_extra_length(), "123qweasdzxc", 12, out1); 146 sz = tox_pass_decrypt(encrypted, 44 + tox_pass_encryption_extra_length(), "123qweasdzxc", 12, out1);
146 ck_assert_msg(sz == 44, "sz isn't right"); 147 ck_assert_msg(sz == 44, "sz isn't right");
147 ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 3 failed"); 148 ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 3 failed");
148 149
@@ -154,7 +155,7 @@ START_TEST(test_keys)
154} 155}
155END_TEST 156END_TEST
156 157
157Suite * encryptsave_suite(void) 158Suite *encryptsave_suite(void)
158{ 159{
159 Suite *s = suite_create("encryptsave"); 160 Suite *s = suite_create("encryptsave");
160 161
@@ -169,7 +170,7 @@ int main(int argc, char *argv[])
169{ 170{
170 srand((unsigned int) time(NULL)); 171 srand((unsigned int) time(NULL));
171 172
172 Suite * encryptsave = encryptsave_suite(); 173 Suite *encryptsave = encryptsave_suite();
173 SRunner *test_runner = srunner_create(encryptsave); 174 SRunner *test_runner = srunner_create(encryptsave);
174 175
175 int number_failed = 0; 176 int number_failed = 0;