summaryrefslogtreecommitdiff
path: root/auto_tests/crypto_test.c
diff options
context:
space:
mode:
authorhugbubby <hugbubby@protonmail.com>2018-07-15 17:09:13 -0700
committerhugbubby <hugbubby@protonmail.com>2018-07-18 13:55:30 -0700
commit864d1c15e4a3b8df236af320312e8115c6bcd791 (patch)
tree945467578a0f7ee140f7d1641e3f4042e63b5bc8 /auto_tests/crypto_test.c
parent392eef7900fdedda28f9c3aff5b0434f963a7f86 (diff)
Using stdint instead of int/long
Did my best to surmise the size requirements of these integers, will do the rest of the tests soon. Also added a todo and made an obsessive change to a for loop.
Diffstat (limited to 'auto_tests/crypto_test.c')
-rw-r--r--auto_tests/crypto_test.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c
index 23c45dd0..c87ffa54 100644
--- a/auto_tests/crypto_test.c
+++ b/auto_tests/crypto_test.c
@@ -92,7 +92,7 @@ START_TEST(test_known)
92{ 92{
93 unsigned char c[147]; 93 unsigned char c[147];
94 unsigned char m[131]; 94 unsigned char m[131];
95 int clen, mlen; 95 uint16_t clen, mlen;
96 96
97 ck_assert_msg(sizeof(c) == sizeof(m) + CRYPTO_MAC_SIZE * sizeof(unsigned char), 97 ck_assert_msg(sizeof(c) == sizeof(m) + CRYPTO_MAC_SIZE * sizeof(unsigned char),
98 "cyphertext should be CRYPTO_MAC_SIZE bytes longer than plaintext"); 98 "cyphertext should be CRYPTO_MAC_SIZE bytes longer than plaintext");
@@ -116,7 +116,7 @@ START_TEST(test_fast_known)
116 unsigned char k[CRYPTO_SHARED_KEY_SIZE]; 116 unsigned char k[CRYPTO_SHARED_KEY_SIZE];
117 unsigned char c[147]; 117 unsigned char c[147];
118 unsigned char m[131]; 118 unsigned char m[131];
119 int clen, mlen; 119 uint16_t clen, mlen;
120 120
121 encrypt_precompute(bobpk, alicesk, k); 121 encrypt_precompute(bobpk, alicesk, k);
122 122
@@ -158,11 +158,11 @@ START_TEST(test_endtoend)
158 unsigned char m3[sizeof(m)]; 158 unsigned char m3[sizeof(m)];
159 unsigned char m4[sizeof(m)]; 159 unsigned char m4[sizeof(m)];
160 160
161 int mlen; 161 uint16_t mlen;
162 int c1len, c2len, c3len, c4len; 162 uint16_t c1len, c2len, c3len, c4len;
163 int m1len, m2len, m3len, m4len; 163 uint16_t m1len, m2len, m3len, m4len;
164 164
165 int testno; 165 uint8_t testno;
166 166
167 // Test 100 random messages and keypairs 167 // Test 100 random messages and keypairs
168 for (testno = 0; testno < 100; testno++) { 168 for (testno = 0; testno < 100; testno++) {
@@ -188,7 +188,7 @@ START_TEST(test_endtoend)
188 c4len = encrypt_data_symmetric(k2, n, m, mlen, c4); 188 c4len = encrypt_data_symmetric(k2, n, m, mlen, c4);
189 189
190 ck_assert_msg(c1len == c2len && c1len == c3len && c1len == c4len, "cyphertext lengths differ"); 190 ck_assert_msg(c1len == c2len && c1len == c3len && c1len == c4len, "cyphertext lengths differ");
191 ck_assert_msg(c1len == mlen + (int)CRYPTO_MAC_SIZE, "wrong cyphertext length"); 191 ck_assert_msg(c1len == mlen + (uint16_t)CRYPTO_MAC_SIZE, "wrong cyphertext length");
192 ck_assert_msg(memcmp(c1, c2, c1len) == 0 && memcmp(c1, c3, c1len) == 0 192 ck_assert_msg(memcmp(c1, c2, c1len) == 0 && memcmp(c1, c3, c1len) == 0
193 && memcmp(c1, c4, c1len) == 0, "crypertexts differ"); 193 && memcmp(c1, c4, c1len) == 0, "crypertexts differ");
194 194
@@ -220,8 +220,8 @@ START_TEST(test_large_data)
220 unsigned char m2[MAX_CRYPTO_PACKET_SIZE]; 220 unsigned char m2[MAX_CRYPTO_PACKET_SIZE];
221 unsigned char c2[sizeof(m2) + CRYPTO_MAC_SIZE]; 221 unsigned char c2[sizeof(m2) + CRYPTO_MAC_SIZE];
222 222
223 int c1len, c2len; 223 uint16_t c1len, c2len;
224 int m1plen; 224 uint16_t m1plen;
225 225
226 //Generate random messages 226 //Generate random messages
227 rand_bytes(m1, sizeof(m1)); 227 rand_bytes(m1, sizeof(m1));
@@ -254,8 +254,8 @@ START_TEST(test_large_data_symmetric)
254 unsigned char c1[sizeof(m1) + CRYPTO_MAC_SIZE]; 254 unsigned char c1[sizeof(m1) + CRYPTO_MAC_SIZE];
255 unsigned char m1prime[sizeof(m1)]; 255 unsigned char m1prime[sizeof(m1)];
256 256
257 int c1len; 257 uint16_t c1len;
258 int m1plen; 258 uint16_t m1plen;
259 259
260 //Generate random messages 260 //Generate random messages
261 rand_bytes(m1, sizeof(m1)); 261 rand_bytes(m1, sizeof(m1));
@@ -282,9 +282,7 @@ static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num)
282 num2 = num + num1; 282 num2 = num + num1;
283 283
284 if (num2 < num1) { 284 if (num2 < num1) {
285 uint32_t i; 285 for (uint16_t i = CRYPTO_NONCE_SIZE - sizeof(num1); i != 0; --i) {
286
287 for (i = CRYPTO_NONCE_SIZE - sizeof(num1); i != 0; --i) {
288 ++nonce[i - 1]; 286 ++nonce[i - 1];
289 287
290 if (nonce[i - 1] != 0) { 288 if (nonce[i - 1] != 0) {
@@ -299,7 +297,7 @@ static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num)
299 297
300START_TEST(test_increment_nonce) 298START_TEST(test_increment_nonce)
301{ 299{
302 long long unsigned int i; 300 uint32_t i;
303 301
304 uint8_t n[CRYPTO_NONCE_SIZE]; 302 uint8_t n[CRYPTO_NONCE_SIZE];
305 303
@@ -362,7 +360,7 @@ int main(void)
362 360
363 Suite *crypto = crypto_suite(); 361 Suite *crypto = crypto_suite();
364 SRunner *test_runner = srunner_create(crypto); 362 SRunner *test_runner = srunner_create(crypto);
365 int number_failed = 0; 363 uint8_t number_failed = 0;
366 364
367 srunner_run_all(test_runner, CK_NORMAL); 365 srunner_run_all(test_runner, CK_NORMAL);
368 number_failed = srunner_ntests_failed(test_runner); 366 number_failed = srunner_ntests_failed(test_runner);