Remove building with NOCRYPTO option
[minix.git] / crypto / external / bsd / heimdal / dist / lib / hcrypto / rc2test.c
blob702265e5d59c9232ab68583ddee9737266163817
1 /* $NetBSD: rc2test.c,v 1.1.1.1 2011/04/13 18:14:50 elric Exp $ */
3 /*
4 * Copyright (c) 2004 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
36 #include <config.h>
38 #include <rc2.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
43 struct {
44 const void *key;
45 const int keylen;
46 const int bitsize;
47 const void *plain;
48 const void *cipher;
49 } tests[] = {
51 "\x00\x00\x00\x00\x00\x00\x00\x00"
52 "\x00\x00\x00\x00\x00\x00\x00\x00",
53 16,
55 "\x00\x00\x00\x00\x00\x00\x00\x00",
56 "\x1C\x19\x8A\x83\x8D\xF0\x28\xB7"
59 "\x00\x00\x00\x00\x00\x00\x00\x00"
60 "\x00\x00\x00\x00\x00\x00\x00\x01",
61 16,
63 "\x00\x00\x00\x00\x00\x00\x00\x00",
64 "\x21\x82\x9C\x78\xA9\xF9\xC0\x74"
67 "\x00\x00\x00\x00\x00\x00\x00\x00"
68 "\x00\x00\x00\x00\x00\x00\x00\x00",
69 16,
71 "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
72 "\x13\xDB\x35\x17\xD3\x21\x86\x9E"
75 "\x00\x01\x02\x03\x04\x05\x06\x07"
76 "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
77 16,
79 "\x00\x00\x00\x00\x00\x00\x00\x00",
80 "\x50\xDC\x01\x62\xBD\x75\x7F\x31"
83 "\x00\x00\x00\x00\x00\x00\x00\x00",
85 63,
86 "\x00\x00\x00\x00\x00\x00\x00\x00",
87 "\xeb\xb7\x73\xf9\x93\x27\x8e\xff"
90 "\xff\xff\xff\xff\xff\xff\xff\xff",
92 64,
93 "\xff\xff\xff\xff\xff\xff\xff\xff",
94 "\x27\x8b\x27\xe4\x2e\x2f\x0d\x49"
97 "\x88",
99 64,
100 "\x00\x00\x00\x00\x00\x00\x00\x00",
101 "\x61\xa8\xa2\x44\xad\xac\xcc\xf0"
105 const unsigned char cbc_key[16] =
106 "\x00\x00\x00\x00\x00\x00\x00\x00"
107 "\x00\x00\x00\x00\x00\x00\x00\x00";
108 const char cbc_iv[8] =
109 "\x01\x01\x01\x01\x01\x01\x01\x01";
110 const unsigned char cbc_in_data[32] =
111 "\x20\x20\x20\x20\x20\x20\x20\x20"
112 "\x20\x20\x20\x20\x20\x20\x20\x20"
113 "\x20\x20\x20\x20\x20\x20\x20\x20"
114 "\x20\x20\x20\x20\x20\x20\x20\x20";
116 const char out_iv[8] = "\x00\x78\x1b\x6\xff\xb9\xfa\xe";
118 const char cbc_out_data[32] =
119 "\xb4\x3f\x89\x15\x69\x68\xda\x79"
120 "\x29\xab\x5f\x78\xc5\xba\x15\x82"
121 "\x80\x89\x57\x1b\xbe\x57\x2f\xdc"
122 "\x00\x78\x1b\x06\xff\xb9\xfa\x0e";
125 main(int argc, char **argv)
127 RC2_KEY key;
128 unsigned char t[8];
129 unsigned char out[40];
130 int i;
132 for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
133 RC2_set_key(&key, tests[i].keylen, tests[i].key, tests[i].bitsize);
135 memcpy(t, tests[i].plain, 8);
136 RC2_encryptc(t, t, &key);
137 if (memcmp(t, tests[i].cipher, 8) != 0) {
138 printf("encrypt %d\n", i);
139 exit(1);
141 RC2_decryptc(t, t, &key);
142 if (memcmp(t, tests[i].plain, 8) != 0) {
143 printf("decrypt: %d\n", i);
144 exit(1);
148 /* cbc test */
150 RC2_set_key(&key, 16, cbc_key, 0);
151 memcpy(t, cbc_iv, 8);
152 RC2_cbc_encrypt(cbc_in_data, out, 32, &key, t, 1);
154 if (memcmp(out_iv, t, 8) != 0)
155 abort();
157 if (memcmp(out, cbc_out_data, 32) != 0) {
158 printf("cbc test encrypt\n");
159 exit(1);
162 memcpy(t, cbc_iv, 8);
163 RC2_cbc_encrypt(out, out, 32, &key, t, 0);
165 if (memcmp(cbc_in_data, out, 32) != 0) {
166 printf("cbc test decrypt \n");
167 exit(1);
170 return 0;