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