Tizen 2.0 Release
[external/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., 59 Temple Place - Suite 330, Boston,
19  * MA 02111-1307, 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             unsigned key_length,
29             const uint8_t *key,
30             unsigned length,
31             const uint8_t *cleartext,
32             const uint8_t *ciphertext)
33 {
34   struct arctwo_ctx ctx;
35   uint8_t *data = xalloc(length);
36
37   arctwo_set_key_ekb(&ctx, key_length, key, ekb);
38   arctwo_encrypt(&ctx, length, data, cleartext);
39
40   if (!MEMEQ(length, data, ciphertext))
41     FAIL();
42
43   arctwo_decrypt(&ctx, length, data, data);
44
45   if (!MEMEQ(length, data, cleartext))
46     FAIL();
47
48   free(data);
49 }
50
51 int
52 test_main(void)
53 {
54   /* Test vectors from Peter Gutmann's paper. */
55   test_cipher(&nettle_arctwo_gutmann128,
56               HL("00000000 00000000 00000000 00000000"),
57               HL("00000000 00000000"),
58               H ("1c198a83 8df028b7"));
59
60   test_cipher(&nettle_arctwo_gutmann128,
61               HL("00010203 04050607 08090a0b 0c0d0e0f"),
62               HL("00000000 00000000"),
63               H ("50dc0162 bd757f31"));
64
65   /* This one was checked against libmcrypt's RFC2268. */
66   test_cipher(&nettle_arctwo_gutmann128,
67               HL("30000000 00000000 00000000 00000000"),
68               HL("10000000 00000000"),
69               H ("8fd10389 336bf95e"));
70
71   /* Test vectors from RFC 2268. */
72   test_cipher(&nettle_arctwo64,
73               HL("ffffffff ffffffff"),
74               HL("ffffffff ffffffff"),
75               H ("278b27e4 2e2f0d49"));
76
77   test_cipher(&nettle_arctwo64,
78               HL("30000000 00000000"),
79               HL("10000000 00000001"),
80               H ("30649edf 9be7d2c2"));
81
82   test_cipher(&nettle_arctwo128,
83               HL("88bca90e 90875a7f 0f79c384 627bafb2"),
84               HL("00000000 00000000"),
85               H ("2269552a b0f85ca6"));
86
87   /* More obscure tests from RFC 2286 */
88   test_arctwo(63,
89               HL("00000000 00000000"),
90               HL("00000000 00000000"),
91               H ("ebb773f9 93278eff"));
92
93   test_arctwo(64,
94               HL("88"),
95               HL("00000000 00000000"),
96               H ("61a8a244 adacccf0"));
97
98   test_arctwo(64,
99               HL("88bca90e 90875a"),
100               HL("00000000 00000000"),
101               H ("6ccf4308 974c267f"));
102
103   test_arctwo(64,
104               HL("88bca90e 90875a7f 0f79c384 627bafb2"),
105               HL("00000000 00000000"),
106               H ("1a807d27 2bbe5db1"));
107
108   test_arctwo(129,
109               HL("88bca90e 90875a7f 0f79c384 627bafb2"
110                  "16f80a6f 85920584 c42fceb0 be255daf 1e"),
111               HL("00000000 00000000"),
112               H ("5b78d3a4 3dfff1f1"));
113
114   SUCCESS ();
115 }