1 /* $NetBSD: casttest.c,v 1.5 2003/08/27 12:37:09 tron Exp $ */
2 /* $KAME: casttest.c,v 1.5 2001/11/28 03:14:03 itojun Exp $ */
5 * Copyright (C) 2000 WIDE Project.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * 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.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
34 * All rights reserved.
36 * This package is an SSL implementation written
37 * by Eric Young (eay@cryptsoft.com).
38 * The implementation was written so as to conform with Netscapes SSL.
40 * This library is free for commercial and non-commercial use as long as
41 * the following conditions are aheared to. The following conditions
42 * apply to all code found in this distribution, be it the RC4, RSA,
43 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
44 * included with this distribution is covered by the same copyright terms
45 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
47 * Copyright remains Eric Young's, and as such any Copyright notices in
48 * the code are not to be removed.
49 * If this package is used in a product, Eric Young should be given attribution
50 * as the author of the parts of the library used.
51 * This can be in the form of a textual message at program startup or
52 * in documentation (online or textual) provided with the package.
54 * Redistribution and use in source and binary forms, with or without
55 * modification, are permitted provided that the following conditions
57 * 1. Redistributions of source code must retain the copyright
58 * notice, this list of conditions and the following disclaimer.
59 * 2. Redistributions in binary form must reproduce the above copyright
60 * notice, this list of conditions and the following disclaimer in the
61 * documentation and/or other materials provided with the distribution.
62 * 3. All advertising materials mentioning features or use of this software
63 * must display the following acknowledgement:
64 * "This product includes cryptographic software written by
65 * Eric Young (eay@cryptsoft.com)"
66 * The word 'cryptographic' can be left out if the rouines from the library
67 * being used are not cryptographic related :-).
68 * 4. If you include any Windows specific code (or a derivative thereof) from
69 * the apps directory (application code) you must include an acknowledgement:
70 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
72 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
73 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
74 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
75 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
76 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
77 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
78 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
79 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
80 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
81 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
84 * The licence and distribution terms for any publically available version or
85 * derivative of this code cannot be changed. i.e. this code cannot simply be
86 * copied and put under another distribution licence
87 * [including the GNU Public Licence.]
90 #include <sys/cdefs.h>
91 #include <sys/types.h>
97 #include <crypto/cast128/cast128.h>
99 static unsigned char k
[16]={
100 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
101 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A
104 static unsigned char in
[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
106 static int k_len
[3]={16,10,5};
107 static unsigned char c
[3][8]={
108 {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2},
109 {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B},
110 {0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E},
112 static unsigned char out
[80];
115 static unsigned char in_a
[16]={
116 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
117 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
118 static unsigned char in_b
[16]={
119 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
120 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
122 static unsigned char c_a
[16]={
123 0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6,
124 0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92};
125 static unsigned char c_b
[16]={
126 0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71,
127 0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E};
130 int main(int, char **);
142 rounds
= atoi(argv
[1]);
145 error
= test1(rounds
);
147 printf("ecb cast5 ok\n");
160 for (z
= 0; z
< 3; z
++) {
166 cast128_setkey(&subkey
, k
, k_len
[z
]);
168 subkey
.rounds
= (k_len
[z
] * 8 <= 80) ? 12 : 16;
169 cast128_encrypt(&subkey
, in
, out
);
171 if (memcmp(out
, c
[z
], 8) != 0) {
172 printf("ecb cast error encrypting for keysize %d\n",
175 for (i
= 0; i
< 8; i
++)
176 printf("%02X ", out
[i
]);
179 for (i
= 0; i
< 8; i
++)
180 printf("%02X ", c
[z
][i
]);
185 cast128_decrypt(&subkey
, out
, out
);
186 if (memcmp(out
, in
, 8) != 0) {
187 printf("ecb cast error decrypting for keysize %d\n",
190 for (i
= 0; i
< 8; i
++)
191 printf("%02X ", out
[i
]);
194 for (i
= 0; i
< 8; i
++)
195 printf("%02X ", in
[i
]);