2 * Copyright (c) 2004 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 __RCSID("$Heimdal: rc2test.c 17509 2006-05-08 11:27:49Z lha $"
53 "\x00\x00\x00\x00\x00\x00\x00\x00"
54 "\x00\x00\x00\x00\x00\x00\x00\x00",
57 "\x00\x00\x00\x00\x00\x00\x00\x00",
58 "\x1C\x19\x8A\x83\x8D\xF0\x28\xB7"
61 "\x00\x00\x00\x00\x00\x00\x00\x00"
62 "\x00\x00\x00\x00\x00\x00\x00\x01",
65 "\x00\x00\x00\x00\x00\x00\x00\x00",
66 "\x21\x82\x9C\x78\xA9\xF9\xC0\x74"
69 "\x00\x00\x00\x00\x00\x00\x00\x00"
70 "\x00\x00\x00\x00\x00\x00\x00\x00",
73 "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
74 "\x13\xDB\x35\x17\xD3\x21\x86\x9E"
77 "\x00\x01\x02\x03\x04\x05\x06\x07"
78 "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
81 "\x00\x00\x00\x00\x00\x00\x00\x00",
82 "\x50\xDC\x01\x62\xBD\x75\x7F\x31"
85 "\x00\x00\x00\x00\x00\x00\x00\x00",
88 "\x00\x00\x00\x00\x00\x00\x00\x00",
89 "\xeb\xb7\x73\xf9\x93\x27\x8e\xff"
92 "\xff\xff\xff\xff\xff\xff\xff\xff",
95 "\xff\xff\xff\xff\xff\xff\xff\xff",
96 "\x27\x8b\x27\xe4\x2e\x2f\x0d\x49"
102 "\x00\x00\x00\x00\x00\x00\x00\x00",
103 "\x61\xa8\xa2\x44\xad\xac\xcc\xf0"
107 const unsigned char cbc_key
[16] =
108 "\x00\x00\x00\x00\x00\x00\x00\x00"
109 "\x00\x00\x00\x00\x00\x00\x00\x00";
110 const char cbc_iv
[8] =
111 "\x01\x01\x01\x01\x01\x01\x01\x01";
112 const unsigned char cbc_in_data
[32] =
113 "\x20\x20\x20\x20\x20\x20\x20\x20"
114 "\x20\x20\x20\x20\x20\x20\x20\x20"
115 "\x20\x20\x20\x20\x20\x20\x20\x20"
116 "\x20\x20\x20\x20\x20\x20\x20\x20";
118 const char out_iv
[8] = "\x00\x78\x1b\x6\xff\xb9\xfa\xe";
120 const char cbc_out_data
[32] =
121 "\xb4\x3f\x89\x15\x69\x68\xda\x79"
122 "\x29\xab\x5f\x78\xc5\xba\x15\x82"
123 "\x80\x89\x57\x1b\xbe\x57\x2f\xdc"
124 "\x00\x78\x1b\x06\xff\xb9\xfa\x0e";
127 main(int argc
, char **argv
)
131 unsigned char out
[40];
134 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++) {
135 RC2_set_key(&key
, tests
[i
].keylen
, tests
[i
].key
, tests
[i
].bitsize
);
137 memcpy(t
, tests
[i
].plain
, 8);
138 RC2_encryptc(t
, t
, &key
);
139 if (memcmp(t
, tests
[i
].cipher
, 8) != 0) {
140 printf("encrypt %d\n", i
);
143 RC2_decryptc(t
, t
, &key
);
144 if (memcmp(t
, tests
[i
].plain
, 8) != 0) {
145 printf("decrypt: %d\n", i
);
152 RC2_set_key(&key
, 16, cbc_key
, 0);
153 memcpy(t
, cbc_iv
, 8);
154 RC2_cbc_encrypt(cbc_in_data
, out
, 32, &key
, t
, 1);
156 if (memcmp(out_iv
, t
, 8) != 0)
159 if (memcmp(out
, cbc_out_data
, 32) != 0) {
160 printf("cbc test encrypt\n");
164 memcpy(t
, cbc_iv
, 8);
165 RC2_cbc_encrypt(out
, out
, 32, &key
, t
, 0);
167 if (memcmp(cbc_in_data
, out
, 32) != 0) {
168 printf("cbc test decrypt \n");