source: tests/check_arc.c @ 5ebff60

Last change on this file since 5ebff60 was 5ebff60, checked in by dequis <dx@…>, at 2015-02-20T22:50:54Z

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[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]9char *password = "ArcVier";
[2305488]10
11char *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
20static void check_codec(int l)
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}
40
[5ebff60]41struct {
[ddcf491f]42        unsigned char crypted[30];
[2305488]43        int len;
44        char *decrypted;
45} decrypt_tests[] = {
[ddcf491f]46        /* One block with padding. */
[2305488]47        {
48                {
[ddcf491f]49                        0x3f, 0x79, 0xb0, 0xf5, 0x91, 0x56, 0xd2, 0x1b, 0xd1, 0x4b, 0x67, 0xac,
50                        0xb1, 0x31, 0xc9, 0xdb, 0xf9, 0xaa
51                }, 18, "short pass"
[2305488]52        },
[5ebff60]53
[ddcf491f]54        /* Two blocks with padding. */
[2305488]55        {
56                {
[ddcf491f]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"
[2305488]61        },
[ddcf491f]62
63        /* This string is exactly two "blocks" long, to make sure unpadded strings also decrypt
64           properly. */
[2305488]65        {
66                {
[ddcf491f]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.."
[2799ff9]71        },
72        { "", 0, NULL }
[2305488]73};
74
75static void check_decod(int l)
76{
77        int i;
[5ebff60]78
79        for (i = 0; decrypt_tests[i].len; i++) {
80                tcase_fn_start(decrypt_tests[i].decrypted, __FILE__, __LINE__);
[2305488]81                char *decrypted;
82                int len;
[5ebff60]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);
[2305488]93        }
94}
95
[5ebff60]96Suite *arc_suite(void)
[2305488]97{
98        Suite *s = suite_create("ArcFour");
99        TCase *tc_core = tcase_create("Core");
[5ebff60]100
101        suite_add_tcase(s, tc_core);
102        tcase_add_test(tc_core, check_codec);
103        tcase_add_test(tc_core, check_decod);
[2305488]104        return s;
105}
Note: See TracBrowser for help on using the repository browser.