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