Annotation of embedaddon/strongswan/src/libstrongswan/tests/suites/test_iv_gen.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2015 Tobias Brunner
3: * HSR Hochschule fuer Technik Rapperswil
4: *
5: * This program is free software; you can redistribute it and/or modify it
6: * under the terms of the GNU General Public License as published by the
7: * Free Software Foundation; either version 2 of the License, or (at your
8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9: *
10: * This program is distributed in the hope that it will be useful, but
11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13: * for more details.
14: */
15:
16: #include "test_suite.h"
17:
18: #include <crypto/iv/iv_gen_seq.h>
19: #include <utils/test.h>
20:
21: START_TEST(test_iv_gen_seq)
22: {
23: iv_gen_t *iv_gen;
24: uint64_t iv0, iv1_1, iv1_2;
25:
26: iv_gen = iv_gen_seq_create();
27: ck_assert(iv_gen->get_iv(iv_gen, 0, 8, (uint8_t*)&iv0));
28: ck_assert(iv_gen->get_iv(iv_gen, 1, 8, (uint8_t*)&iv1_1));
29: ck_assert(iv0 != iv1_1);
30: /* every sequence number may be used twice, but results in a different IV */
31: ck_assert(iv_gen->get_iv(iv_gen, 1, 8, (uint8_t*)&iv1_2));
32: ck_assert(iv0 != iv1_2);
33: ck_assert(iv1_1 != iv1_2);
34: ck_assert(!iv_gen->get_iv(iv_gen, 1, 8, (uint8_t*)&iv1_2));
35: iv_gen->destroy(iv_gen);
36: }
37: END_TEST
38:
39: START_TEST(test_iv_gen_seq_len)
40: {
41: iv_gen_t *iv_gen;
42: uint64_t iv;
43: uint8_t buf[9];
44:
45: iv_gen = iv_gen_seq_create();
46: ck_assert(!iv_gen->get_iv(iv_gen, 0, 0, (uint8_t*)&iv));
47: ck_assert(!iv_gen->get_iv(iv_gen, 0, 1, (uint8_t*)&iv));
48: ck_assert(!iv_gen->get_iv(iv_gen, 0, 2, (uint8_t*)&iv));
49: ck_assert(!iv_gen->get_iv(iv_gen, 0, 3, (uint8_t*)&iv));
50: ck_assert(!iv_gen->get_iv(iv_gen, 0, 4, (uint8_t*)&iv));
51: ck_assert(!iv_gen->get_iv(iv_gen, 0, 5, (uint8_t*)&iv));
52: ck_assert(!iv_gen->get_iv(iv_gen, 0, 6, (uint8_t*)&iv));
53: ck_assert(!iv_gen->get_iv(iv_gen, 0, 7, (uint8_t*)&iv));
54: ck_assert(iv_gen->get_iv(iv_gen, 0, 8, (uint8_t*)&iv));
55: ck_assert(iv_gen->get_iv(iv_gen, 0, 9, buf));
56: iv_gen->destroy(iv_gen);
57: }
58: END_TEST
59:
60: Suite *iv_gen_suite_create()
61: {
62: Suite *s;
63: TCase *tc;
64:
65: s = suite_create("iv-gen");
66:
67: tc = tcase_create("iv-gen-seq");
68: tcase_add_test(tc, test_iv_gen_seq);
69: tcase_add_test(tc, test_iv_gen_seq_len);
70: suite_add_tcase(s, tc);
71:
72: return s;
73: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>