add packaging
[platform/upstream/nettle.git] / testsuite / arctwo-test.c
1 /* nettle, low-level cryptographics library
2  *
3  * Copyright (C) 2004 Simon Josefsson
4  * Copyright (C) 2004 Niels Möller
5  *
6  * The nettle library is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or (at your
9  * option) any later version.
10  *
11  * The nettle library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with the nettle library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02111-1301, USA.
20  */
21
22 #include "testutils.h"
23 #include "arctwo.h"
24
25 /* For tests with obscure values of ebk. */
26 static void
27 test_arctwo(unsigned ekb,
28             const struct tstring *key,
29             const struct tstring *cleartext,
30             const struct tstring *ciphertext)
31 {
32   struct arctwo_ctx ctx;
33   uint8_t *data;
34   unsigned length;
35
36   ASSERT (cleartext->length == ciphertext->length);
37   length = cleartext->length;
38   
39   data = xalloc(length);
40
41   arctwo_set_key_ekb(&ctx, key->length, key->data, ekb);
42   arctwo_encrypt(&ctx, length, data, cleartext->data);
43
44   ASSERT(MEMEQ(length, data, ciphertext->data));
45
46   arctwo_decrypt(&ctx, length, data, data);
47
48   ASSERT(MEMEQ(length, data, cleartext->data));
49
50   free(data);
51 }
52
53 void
54 test_main(void)
55 {
56   /* Test vectors from Peter Gutmann's paper. */
57   test_cipher(&nettle_arctwo_gutmann128,
58               SHEX("00000000 00000000 00000000 00000000"),
59               SHEX("00000000 00000000"),
60               SHEX("1c198a83 8df028b7"));
61
62   test_cipher(&nettle_arctwo_gutmann128,
63               SHEX("00010203 04050607 08090a0b 0c0d0e0f"),
64               SHEX("00000000 00000000"),
65               SHEX("50dc0162 bd757f31"));
66
67   /* This one was checked against libmcrypt's RFC2268. */
68   test_cipher(&nettle_arctwo_gutmann128,
69               SHEX("30000000 00000000 00000000 00000000"),
70               SHEX("10000000 00000000"),
71               SHEX("8fd10389 336bf95e"));
72
73   /* Test vectors from RFC 2268. */
74   test_cipher(&nettle_arctwo64,
75               SHEX("ffffffff ffffffff"),
76               SHEX("ffffffff ffffffff"),
77               SHEX("278b27e4 2e2f0d49"));
78
79   test_cipher(&nettle_arctwo64,
80               SHEX("30000000 00000000"),
81               SHEX("10000000 00000001"),
82               SHEX("30649edf 9be7d2c2"));
83
84   test_cipher(&nettle_arctwo128,
85               SHEX("88bca90e 90875a7f 0f79c384 627bafb2"),
86               SHEX("00000000 00000000"),
87               SHEX("2269552a b0f85ca6"));
88
89   /* More obscure tests from RFC 2286 */
90   test_arctwo(63,
91               SHEX("00000000 00000000"),
92               SHEX("00000000 00000000"),
93               SHEX("ebb773f9 93278eff"));
94
95   test_arctwo(64,
96               SHEX("88"),
97               SHEX("00000000 00000000"),
98               SHEX("61a8a244 adacccf0"));
99
100   test_arctwo(64,
101               SHEX("88bca90e 90875a"),
102               SHEX("00000000 00000000"),
103               SHEX("6ccf4308 974c267f"));
104
105   test_arctwo(64,
106               SHEX("88bca90e 90875a7f 0f79c384 627bafb2"),
107               SHEX("00000000 00000000"),
108               SHEX("1a807d27 2bbe5db1"));
109
110   test_arctwo(129,
111               SHEX("88bca90e 90875a7f 0f79c384 627bafb2"
112                    "16f80a6f 85920584 c42fceb0 be255daf 1e"),
113               SHEX("00000000 00000000"),
114               SHEX("5b78d3a4 3dfff1f1"));
115 }