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