summaryrefslogtreecommitdiff
path: root/testsuite/arctwo-test.c
blob: 4e890097f195ae2fef4c16f7be4b71964127c43c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* nettle, low-level cryptographics library
 *
 * Copyright (C) 2004 Simon Josefsson
 * Copyright (C) 2004 Niels Möller
 *
 * The nettle library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
 *
 * The nettle library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with the nettle library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 */

#include "testutils.h"
#include "arctwo.h"

/* For tests with obscure values of ebk. */
static void
test_arctwo(unsigned ekb,
	    unsigned key_length,
	    const uint8_t *key,
	    unsigned length,
	    const uint8_t *cleartext,
	    const uint8_t *ciphertext)
{
  struct arctwo_ctx ctx;
  uint8_t *data = xalloc(length);

  arctwo_set_key_ekb(&ctx, key_length, key, ekb);
  arctwo_encrypt(&ctx, length, data, cleartext);

  if (!MEMEQ(length, data, ciphertext))
    FAIL();

  arctwo_decrypt(&ctx, length, data, data);

  if (!MEMEQ(length, data, cleartext))
    FAIL();

  free(data);
}

int
test_main(void)
{
  /* Test vectors from Peter Gutmann's paper. */
  test_cipher(&nettle_arctwo_gutmann128,
	      HL("00000000 00000000 00000000 00000000"),
	      HL("00000000 00000000"),
	      H ("1c198a83 8df028b7"));

  test_cipher(&nettle_arctwo_gutmann128,
	      HL("00010203 04050607 08090a0b 0c0d0e0f"),
	      HL("00000000 00000000"),
	      H ("50dc0162 bd757f31"));

  /* This one was checked against libmcrypt's RFC2268. */
  test_cipher(&nettle_arctwo_gutmann128,
	      HL("30000000 00000000 00000000 00000000"),
	      HL("10000000 00000000"),
	      H ("8fd10389 336bf95e"));

  /* Test vectors from RFC 2268. */
  test_cipher(&nettle_arctwo64,
	      HL("ffffffff ffffffff"),
	      HL("ffffffff ffffffff"),
	      H ("278b27e4 2e2f0d49"));

  test_cipher(&nettle_arctwo64,
	      HL("30000000 00000000"),
	      HL("10000000 00000001"),
	      H ("30649edf 9be7d2c2"));

  test_cipher(&nettle_arctwo128,
	      HL("88bca90e 90875a7f 0f79c384 627bafb2"),
	      HL("00000000 00000000"),
	      H ("2269552a b0f85ca6"));

  /* More obscure tests from RFC 2286 */
  test_arctwo(63,
	      HL("00000000 00000000"),
	      HL("00000000 00000000"),
	      H ("ebb773f9 93278eff"));

  test_arctwo(64,
	      HL("88"),
	      HL("00000000 00000000"),
	      H ("61a8a244 adacccf0"));

  test_arctwo(64,
	      HL("88bca90e 90875a"),
	      HL("00000000 00000000"),
	      H ("6ccf4308 974c267f"));

  test_arctwo(64,
	      HL("88bca90e 90875a7f 0f79c384 627bafb2"),
	      HL("00000000 00000000"),
	      H ("1a807d27 2bbe5db1"));

  test_arctwo(129,
	      HL("88bca90e 90875a7f 0f79c384 627bafb2"
		 "16f80a6f 85920584 c42fceb0 be255daf 1e"),
	      HL("00000000 00000000"),
	      H ("5b78d3a4 3dfff1f1"));

  SUCCESS ();
}