| 1 |
#include <stdlib.h> |
| 2 |
#include <glib.h> |
| 3 |
#include <gmodule.h> |
| 4 |
#include <check.h> |
| 5 |
#include <string.h> |
| 6 |
#include <stdio.h> |
| 7 |
#include "arc.h" |
| 8 |
|
| 9 |
char *password = "ArcVier"; |
| 10 |
|
| 11 |
char *clear_tests[] = |
| 12 |
{ |
| 13 |
"Wie dit leest is gek :-)", |
| 14 |
"ItllBeBitlBee", |
| 15 |
"One more boring password", |
| 16 |
"Hoi hoi", |
| 17 |
NULL |
| 18 |
}; |
| 19 |
|
| 20 |
static void check_codec(int l) |
| 21 |
{ |
| 22 |
int i; |
| 23 |
|
| 24 |
for (i = 0; clear_tests[i]; i++) { |
| 25 |
tcase_fn_start(clear_tests[i], __FILE__, __LINE__); |
| 26 |
unsigned char *crypted; |
| 27 |
char *decrypted; |
| 28 |
int len; |
| 29 |
|
| 30 |
len = arc_encode(clear_tests[i], 0, &crypted, password, 12); |
| 31 |
len = arc_decode(crypted, len, &decrypted, password); |
| 32 |
|
| 33 |
fail_if(strcmp(clear_tests[i], decrypted) != 0, |
| 34 |
"%s didn't decrypt back properly", clear_tests[i]); |
| 35 |
|
| 36 |
g_free(crypted); |
| 37 |
g_free(decrypted); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
struct { |
| 42 |
unsigned char crypted[30]; |
| 43 |
int len; |
| 44 |
char *decrypted; |
| 45 |
} decrypt_tests[] = { |
| 46 |
/* One block with padding. */ |
| 47 |
{ |
| 48 |
{ |
| 49 |
0x3f, 0x79, 0xb0, 0xf5, 0x91, 0x56, 0xd2, 0x1b, 0xd1, 0x4b, 0x67, 0xac, |
| 50 |
0xb1, 0x31, 0xc9, 0xdb, 0xf9, 0xaa |
| 51 |
}, 18, "short pass" |
| 52 |
}, |
| 53 |
|
| 54 |
/* Two blocks with padding. */ |
| 55 |
{ |
| 56 |
{ |
| 57 |
0xf9, 0xa6, 0xec, 0x5d, 0xc7, 0x06, 0xb8, 0x6b, 0x63, 0x9f, 0x2d, 0xb5, |
| 58 |
0x7d, 0xaa, 0x32, 0xbb, 0xd8, 0x08, 0xfd, 0x81, 0x2e, 0xca, 0xb4, 0xd7, |
| 59 |
0x2f, 0x36, 0x9c, 0xac, 0xa0, 0xbc |
| 60 |
}, 30, "longer password" |
| 61 |
}, |
| 62 |
|
| 63 |
/* This string is exactly two "blocks" long, to make sure unpadded strings also decrypt |
| 64 |
properly. */ |
| 65 |
{ |
| 66 |
{ |
| 67 |
0x95, 0x4d, 0xcf, 0x4d, 0x5e, 0x6c, 0xcf, 0xef, 0xb9, 0x80, 0x00, 0xef, |
| 68 |
0x25, 0xe9, 0x17, 0xf6, 0x29, 0x6a, 0x82, 0x79, 0x1c, 0xca, 0x68, 0xb5, |
| 69 |
0x4e, 0xd0, 0xc1, 0x41, 0x8e, 0xe6 |
| 70 |
}, 30, "OSCAR is really creepy.." |
| 71 |
}, |
| 72 |
{ "", 0, NULL } |
| 73 |
}; |
| 74 |
|
| 75 |
static void check_decod(int l) |
| 76 |
{ |
| 77 |
int i; |
| 78 |
|
| 79 |
for (i = 0; decrypt_tests[i].len; i++) { |
| 80 |
tcase_fn_start(decrypt_tests[i].decrypted, __FILE__, __LINE__); |
| 81 |
char *decrypted; |
| 82 |
int len; |
| 83 |
|
| 84 |
len = arc_decode(decrypt_tests[i].crypted, decrypt_tests[i].len, |
| 85 |
&decrypted, password); |
| 86 |
|
| 87 |
fail_if(len == -1, |
| 88 |
"`%s' didn't decrypt properly", decrypt_tests[i].decrypted); |
| 89 |
fail_if(strcmp(decrypt_tests[i].decrypted, decrypted) != 0, |
| 90 |
"`%s' didn't decrypt properly", decrypt_tests[i].decrypted); |
| 91 |
|
| 92 |
g_free(decrypted); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
Suite *arc_suite(void) |
| 97 |
{ |
| 98 |
Suite *s = suite_create("ArcFour"); |
| 99 |
TCase *tc_core = tcase_create("Core"); |
| 100 |
|
| 101 |
suite_add_tcase(s, tc_core); |
| 102 |
tcase_add_test(tc_core, check_codec); |
| 103 |
tcase_add_test(tc_core, check_decod); |
| 104 |
return s; |
| 105 |
} |