xref: /minix3/tests/lib/libdes/t_des.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /* $NetBSD: t_des.c,v 1.1 2010/08/25 16:46:36 jmmv Exp $ */
2*11be35a1SLionel Sambuc 
3*11be35a1SLionel Sambuc /*
4*11be35a1SLionel Sambuc  * Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) All rights
5*11be35a1SLionel Sambuc  * reserved.
6*11be35a1SLionel Sambuc  *
7*11be35a1SLionel Sambuc  * This package is an SSL implementation written by Eric Young
8*11be35a1SLionel Sambuc  * (eay@cryptsoft.com). The implementation was written so as to conform with
9*11be35a1SLionel Sambuc  * Netscapes SSL.
10*11be35a1SLionel Sambuc  *
11*11be35a1SLionel Sambuc  * This library is free for commercial and non-commercial use as long as the
12*11be35a1SLionel Sambuc  * following conditions are aheared to.  The following conditions apply to
13*11be35a1SLionel Sambuc  * all code found in this distribution, be it the RC4, RSA, lhash, DES, etc.,
14*11be35a1SLionel Sambuc  * code; not just the SSL code.  The SSL documentation included with this
15*11be35a1SLionel Sambuc  * distribution is covered by the same copyright terms except that the holder
16*11be35a1SLionel Sambuc  * is Tim Hudson (tjh@cryptsoft.com).
17*11be35a1SLionel Sambuc  *
18*11be35a1SLionel Sambuc  * Copyright remains Eric Young's, and as such any Copyright notices in the code
19*11be35a1SLionel Sambuc  * are not to be removed. If this package is used in a product, Eric Young
20*11be35a1SLionel Sambuc  * should be given attribution as the author of the parts of the library
21*11be35a1SLionel Sambuc  * used. This can be in the form of a textual message at program startup or
22*11be35a1SLionel Sambuc  * in documentation (online or textual) provided with the package.
23*11be35a1SLionel Sambuc  *
24*11be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
25*11be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions are
26*11be35a1SLionel Sambuc  * met: 1. Redistributions of source code must retain the copyright notice,
27*11be35a1SLionel Sambuc  * this list of conditions and the following disclaimer. 2. Redistributions
28*11be35a1SLionel Sambuc  * in binary form must reproduce the above copyright notice, this list of
29*11be35a1SLionel Sambuc  * conditions and the following disclaimer in the documentation and/or other
30*11be35a1SLionel Sambuc  * materials provided with the distribution. 3. All advertising materials
31*11be35a1SLionel Sambuc  * mentioning features or use of this software must display the following
32*11be35a1SLionel Sambuc  * acknowledgement: "This product includes cryptographic software written by
33*11be35a1SLionel Sambuc  * Eric Young (eay@cryptsoft.com)" The word 'cryptographic' can be left out
34*11be35a1SLionel Sambuc  * if the rouines from the library being used are not cryptographic related
35*11be35a1SLionel Sambuc  * :-). 4. If you include any Windows specific code (or a derivative thereof)
36*11be35a1SLionel Sambuc  * from the apps directory (application code) you must include an
37*11be35a1SLionel Sambuc  * acknowledgement: "This product includes software written by Tim Hudson
38*11be35a1SLionel Sambuc  * (tjh@cryptsoft.com)"
39*11be35a1SLionel Sambuc  *
40*11be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND ANY EXPRESS OR IMPLIED
41*11be35a1SLionel Sambuc  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42*11be35a1SLionel Sambuc  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
43*11be35a1SLionel Sambuc  * NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
44*11be35a1SLionel Sambuc  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
45*11be35a1SLionel Sambuc  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
46*11be35a1SLionel Sambuc  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
47*11be35a1SLionel Sambuc  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48*11be35a1SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49*11be35a1SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50*11be35a1SLionel Sambuc  * SUCH DAMAGE.
51*11be35a1SLionel Sambuc  *
52*11be35a1SLionel Sambuc  * The licence and distribution terms for any publically available version or
53*11be35a1SLionel Sambuc  * derivative of this code cannot be changed.  i.e. this code cannot simply
54*11be35a1SLionel Sambuc  * be copied and put under another distribution licence [including the GNU
55*11be35a1SLionel Sambuc  * Public Licence.]
56*11be35a1SLionel Sambuc  */
57*11be35a1SLionel Sambuc 
58*11be35a1SLionel Sambuc #include <atf-c.h>
59*11be35a1SLionel Sambuc #include <des.h>
60*11be35a1SLionel Sambuc #include <stdio.h>
61*11be35a1SLionel Sambuc #include <stdlib.h>
62*11be35a1SLionel Sambuc #include <string.h>
63*11be35a1SLionel Sambuc #include <unistd.h>
64*11be35a1SLionel Sambuc 
65*11be35a1SLionel Sambuc #define crypt(c,s) (des_crypt((c),(s)))
66*11be35a1SLionel Sambuc 
67*11be35a1SLionel Sambuc /* tisk tisk - the test keys don't all have odd parity :-( */
68*11be35a1SLionel Sambuc /* test data */
69*11be35a1SLionel Sambuc #define NUM_TESTS 34
70*11be35a1SLionel Sambuc static unsigned char key_data[NUM_TESTS][8] = {
71*11be35a1SLionel Sambuc 	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
72*11be35a1SLionel Sambuc 	{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
73*11be35a1SLionel Sambuc 	{0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
74*11be35a1SLionel Sambuc 	{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
75*11be35a1SLionel Sambuc 	{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
76*11be35a1SLionel Sambuc 	{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
77*11be35a1SLionel Sambuc 	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
78*11be35a1SLionel Sambuc 	{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
79*11be35a1SLionel Sambuc 	{0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57},
80*11be35a1SLionel Sambuc 	{0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E},
81*11be35a1SLionel Sambuc 	{0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86},
82*11be35a1SLionel Sambuc 	{0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E},
83*11be35a1SLionel Sambuc 	{0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6},
84*11be35a1SLionel Sambuc 	{0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE},
85*11be35a1SLionel Sambuc 	{0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6},
86*11be35a1SLionel Sambuc 	{0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE},
87*11be35a1SLionel Sambuc 	{0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16},
88*11be35a1SLionel Sambuc 	{0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F},
89*11be35a1SLionel Sambuc 	{0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46},
90*11be35a1SLionel Sambuc 	{0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E},
91*11be35a1SLionel Sambuc 	{0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76},
92*11be35a1SLionel Sambuc 	{0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07},
93*11be35a1SLionel Sambuc 	{0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F},
94*11be35a1SLionel Sambuc 	{0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7},
95*11be35a1SLionel Sambuc 	{0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF},
96*11be35a1SLionel Sambuc 	{0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6},
97*11be35a1SLionel Sambuc 	{0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF},
98*11be35a1SLionel Sambuc 	{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
99*11be35a1SLionel Sambuc 	{0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E},
100*11be35a1SLionel Sambuc 	{0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE},
101*11be35a1SLionel Sambuc 	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
102*11be35a1SLionel Sambuc 	{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
103*11be35a1SLionel Sambuc 	{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
104*11be35a1SLionel Sambuc 	{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}
105*11be35a1SLionel Sambuc };
106*11be35a1SLionel Sambuc 
107*11be35a1SLionel Sambuc static unsigned char plain_data[NUM_TESTS][8] = {
108*11be35a1SLionel Sambuc 	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
109*11be35a1SLionel Sambuc 	{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
110*11be35a1SLionel Sambuc 	{0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
111*11be35a1SLionel Sambuc 	{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
112*11be35a1SLionel Sambuc 	{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
113*11be35a1SLionel Sambuc 	{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
114*11be35a1SLionel Sambuc 	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
115*11be35a1SLionel Sambuc 	{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
116*11be35a1SLionel Sambuc 	{0x01, 0xA1, 0xD6, 0xD0, 0x39, 0x77, 0x67, 0x42},
117*11be35a1SLionel Sambuc 	{0x5C, 0xD5, 0x4C, 0xA8, 0x3D, 0xEF, 0x57, 0xDA},
118*11be35a1SLionel Sambuc 	{0x02, 0x48, 0xD4, 0x38, 0x06, 0xF6, 0x71, 0x72},
119*11be35a1SLionel Sambuc 	{0x51, 0x45, 0x4B, 0x58, 0x2D, 0xDF, 0x44, 0x0A},
120*11be35a1SLionel Sambuc 	{0x42, 0xFD, 0x44, 0x30, 0x59, 0x57, 0x7F, 0xA2},
121*11be35a1SLionel Sambuc 	{0x05, 0x9B, 0x5E, 0x08, 0x51, 0xCF, 0x14, 0x3A},
122*11be35a1SLionel Sambuc 	{0x07, 0x56, 0xD8, 0xE0, 0x77, 0x47, 0x61, 0xD2},
123*11be35a1SLionel Sambuc 	{0x76, 0x25, 0x14, 0xB8, 0x29, 0xBF, 0x48, 0x6A},
124*11be35a1SLionel Sambuc 	{0x3B, 0xDD, 0x11, 0x90, 0x49, 0x37, 0x28, 0x02},
125*11be35a1SLionel Sambuc 	{0x26, 0x95, 0x5F, 0x68, 0x35, 0xAF, 0x60, 0x9A},
126*11be35a1SLionel Sambuc 	{0x16, 0x4D, 0x5E, 0x40, 0x4F, 0x27, 0x52, 0x32},
127*11be35a1SLionel Sambuc 	{0x6B, 0x05, 0x6E, 0x18, 0x75, 0x9F, 0x5C, 0xCA},
128*11be35a1SLionel Sambuc 	{0x00, 0x4B, 0xD6, 0xEF, 0x09, 0x17, 0x60, 0x62},
129*11be35a1SLionel Sambuc 	{0x48, 0x0D, 0x39, 0x00, 0x6E, 0xE7, 0x62, 0xF2},
130*11be35a1SLionel Sambuc 	{0x43, 0x75, 0x40, 0xC8, 0x69, 0x8F, 0x3C, 0xFA},
131*11be35a1SLionel Sambuc 	{0x07, 0x2D, 0x43, 0xA0, 0x77, 0x07, 0x52, 0x92},
132*11be35a1SLionel Sambuc 	{0x02, 0xFE, 0x55, 0x77, 0x81, 0x17, 0xF1, 0x2A},
133*11be35a1SLionel Sambuc 	{0x1D, 0x9D, 0x5C, 0x50, 0x18, 0xF7, 0x28, 0xC2},
134*11be35a1SLionel Sambuc 	{0x30, 0x55, 0x32, 0x28, 0x6D, 0x6F, 0x29, 0x5A},
135*11be35a1SLionel Sambuc 	{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
136*11be35a1SLionel Sambuc 	{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
137*11be35a1SLionel Sambuc 	{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
138*11be35a1SLionel Sambuc 	{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
139*11be35a1SLionel Sambuc 	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
140*11be35a1SLionel Sambuc 	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
141*11be35a1SLionel Sambuc 	{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
142*11be35a1SLionel Sambuc };
143*11be35a1SLionel Sambuc 
144*11be35a1SLionel Sambuc static unsigned char cipher_data[NUM_TESTS][8] = {
145*11be35a1SLionel Sambuc 	{0x8C, 0xA6, 0x4D, 0xE9, 0xC1, 0xB1, 0x23, 0xA7},
146*11be35a1SLionel Sambuc 	{0x73, 0x59, 0xB2, 0x16, 0x3E, 0x4E, 0xDC, 0x58},
147*11be35a1SLionel Sambuc 	{0x95, 0x8E, 0x6E, 0x62, 0x7A, 0x05, 0x55, 0x7B},
148*11be35a1SLionel Sambuc 	{0xF4, 0x03, 0x79, 0xAB, 0x9E, 0x0E, 0xC5, 0x33},
149*11be35a1SLionel Sambuc 	{0x17, 0x66, 0x8D, 0xFC, 0x72, 0x92, 0x53, 0x2D},
150*11be35a1SLionel Sambuc 	{0x8A, 0x5A, 0xE1, 0xF8, 0x1A, 0xB8, 0xF2, 0xDD},
151*11be35a1SLionel Sambuc 	{0x8C, 0xA6, 0x4D, 0xE9, 0xC1, 0xB1, 0x23, 0xA7},
152*11be35a1SLionel Sambuc 	{0xED, 0x39, 0xD9, 0x50, 0xFA, 0x74, 0xBC, 0xC4},
153*11be35a1SLionel Sambuc 	{0x69, 0x0F, 0x5B, 0x0D, 0x9A, 0x26, 0x93, 0x9B},
154*11be35a1SLionel Sambuc 	{0x7A, 0x38, 0x9D, 0x10, 0x35, 0x4B, 0xD2, 0x71},
155*11be35a1SLionel Sambuc 	{0x86, 0x8E, 0xBB, 0x51, 0xCA, 0xB4, 0x59, 0x9A},
156*11be35a1SLionel Sambuc 	{0x71, 0x78, 0x87, 0x6E, 0x01, 0xF1, 0x9B, 0x2A},
157*11be35a1SLionel Sambuc 	{0xAF, 0x37, 0xFB, 0x42, 0x1F, 0x8C, 0x40, 0x95},
158*11be35a1SLionel Sambuc 	{0x86, 0xA5, 0x60, 0xF1, 0x0E, 0xC6, 0xD8, 0x5B},
159*11be35a1SLionel Sambuc 	{0x0C, 0xD3, 0xDA, 0x02, 0x00, 0x21, 0xDC, 0x09},
160*11be35a1SLionel Sambuc 	{0xEA, 0x67, 0x6B, 0x2C, 0xB7, 0xDB, 0x2B, 0x7A},
161*11be35a1SLionel Sambuc 	{0xDF, 0xD6, 0x4A, 0x81, 0x5C, 0xAF, 0x1A, 0x0F},
162*11be35a1SLionel Sambuc 	{0x5C, 0x51, 0x3C, 0x9C, 0x48, 0x86, 0xC0, 0x88},
163*11be35a1SLionel Sambuc 	{0x0A, 0x2A, 0xEE, 0xAE, 0x3F, 0xF4, 0xAB, 0x77},
164*11be35a1SLionel Sambuc 	{0xEF, 0x1B, 0xF0, 0x3E, 0x5D, 0xFA, 0x57, 0x5A},
165*11be35a1SLionel Sambuc 	{0x88, 0xBF, 0x0D, 0xB6, 0xD7, 0x0D, 0xEE, 0x56},
166*11be35a1SLionel Sambuc 	{0xA1, 0xF9, 0x91, 0x55, 0x41, 0x02, 0x0B, 0x56},
167*11be35a1SLionel Sambuc 	{0x6F, 0xBF, 0x1C, 0xAF, 0xCF, 0xFD, 0x05, 0x56},
168*11be35a1SLionel Sambuc 	{0x2F, 0x22, 0xE4, 0x9B, 0xAB, 0x7C, 0xA1, 0xAC},
169*11be35a1SLionel Sambuc 	{0x5A, 0x6B, 0x61, 0x2C, 0xC2, 0x6C, 0xCE, 0x4A},
170*11be35a1SLionel Sambuc 	{0x5F, 0x4C, 0x03, 0x8E, 0xD1, 0x2B, 0x2E, 0x41},
171*11be35a1SLionel Sambuc 	{0x63, 0xFA, 0xC0, 0xD0, 0x34, 0xD9, 0xF7, 0x93},
172*11be35a1SLionel Sambuc 	{0x61, 0x7B, 0x3A, 0x0C, 0xE8, 0xF0, 0x71, 0x00},
173*11be35a1SLionel Sambuc 	{0xDB, 0x95, 0x86, 0x05, 0xF8, 0xC8, 0xC6, 0x06},
174*11be35a1SLionel Sambuc 	{0xED, 0xBF, 0xD1, 0xC6, 0x6C, 0x29, 0xCC, 0xC7},
175*11be35a1SLionel Sambuc 	{0x35, 0x55, 0x50, 0xB2, 0x15, 0x0E, 0x24, 0x51},
176*11be35a1SLionel Sambuc 	{0xCA, 0xAA, 0xAF, 0x4D, 0xEA, 0xF1, 0xDB, 0xAE},
177*11be35a1SLionel Sambuc 	{0xD5, 0xD4, 0x4F, 0xF7, 0x20, 0x68, 0x3D, 0x0D},
178*11be35a1SLionel Sambuc 	{0x2A, 0x2B, 0xB0, 0x08, 0xDF, 0x97, 0xC2, 0xF2}
179*11be35a1SLionel Sambuc };
180*11be35a1SLionel Sambuc 
181*11be35a1SLionel Sambuc static unsigned char cipher_ecb2[NUM_TESTS - 1][8] = {
182*11be35a1SLionel Sambuc 	{0x92, 0x95, 0xB5, 0x9B, 0xB3, 0x84, 0x73, 0x6E},
183*11be35a1SLionel Sambuc 	{0x19, 0x9E, 0x9D, 0x6D, 0xF3, 0x9A, 0xA8, 0x16},
184*11be35a1SLionel Sambuc 	{0x2A, 0x4B, 0x4D, 0x24, 0x52, 0x43, 0x84, 0x27},
185*11be35a1SLionel Sambuc 	{0x35, 0x84, 0x3C, 0x01, 0x9D, 0x18, 0xC5, 0xB6},
186*11be35a1SLionel Sambuc 	{0x4A, 0x5B, 0x2F, 0x42, 0xAA, 0x77, 0x19, 0x25},
187*11be35a1SLionel Sambuc 	{0xA0, 0x6B, 0xA9, 0xB8, 0xCA, 0x5B, 0x17, 0x8A},
188*11be35a1SLionel Sambuc 	{0xAB, 0x9D, 0xB7, 0xFB, 0xED, 0x95, 0xF2, 0x74},
189*11be35a1SLionel Sambuc 	{0x3D, 0x25, 0x6C, 0x23, 0xA7, 0x25, 0x2F, 0xD6},
190*11be35a1SLionel Sambuc 	{0xB7, 0x6F, 0xAB, 0x4F, 0xBD, 0xBD, 0xB7, 0x67},
191*11be35a1SLionel Sambuc 	{0x8F, 0x68, 0x27, 0xD6, 0x9C, 0xF4, 0x1A, 0x10},
192*11be35a1SLionel Sambuc 	{0x82, 0x57, 0xA1, 0xD6, 0x50, 0x5E, 0x81, 0x85},
193*11be35a1SLionel Sambuc 	{0xA2, 0x0F, 0x0A, 0xCD, 0x80, 0x89, 0x7D, 0xFA},
194*11be35a1SLionel Sambuc 	{0xCD, 0x2A, 0x53, 0x3A, 0xDB, 0x0D, 0x7E, 0xF3},
195*11be35a1SLionel Sambuc 	{0xD2, 0xC2, 0xBE, 0x27, 0xE8, 0x1B, 0x68, 0xE3},
196*11be35a1SLionel Sambuc 	{0xE9, 0x24, 0xCF, 0x4F, 0x89, 0x3C, 0x5B, 0x0A},
197*11be35a1SLionel Sambuc 	{0xA7, 0x18, 0xC3, 0x9F, 0xFA, 0x9F, 0xD7, 0x69},
198*11be35a1SLionel Sambuc 	{0x77, 0x2C, 0x79, 0xB1, 0xD2, 0x31, 0x7E, 0xB1},
199*11be35a1SLionel Sambuc 	{0x49, 0xAB, 0x92, 0x7F, 0xD0, 0x22, 0x00, 0xB7},
200*11be35a1SLionel Sambuc 	{0xCE, 0x1C, 0x6C, 0x7D, 0x85, 0xE3, 0x4A, 0x6F},
201*11be35a1SLionel Sambuc 	{0xBE, 0x91, 0xD6, 0xE1, 0x27, 0xB2, 0xE9, 0x87},
202*11be35a1SLionel Sambuc 	{0x70, 0x28, 0xAE, 0x8F, 0xD1, 0xF5, 0x74, 0x1A},
203*11be35a1SLionel Sambuc 	{0xAA, 0x37, 0x80, 0xBB, 0xF3, 0x22, 0x1D, 0xDE},
204*11be35a1SLionel Sambuc 	{0xA6, 0xC4, 0xD2, 0x5E, 0x28, 0x93, 0xAC, 0xB3},
205*11be35a1SLionel Sambuc 	{0x22, 0x07, 0x81, 0x5A, 0xE4, 0xB7, 0x1A, 0xAD},
206*11be35a1SLionel Sambuc 	{0xDC, 0xCE, 0x05, 0xE7, 0x07, 0xBD, 0xF5, 0x84},
207*11be35a1SLionel Sambuc 	{0x26, 0x1D, 0x39, 0x2C, 0xB3, 0xBA, 0xA5, 0x85},
208*11be35a1SLionel Sambuc 	{0xB4, 0xF7, 0x0F, 0x72, 0xFB, 0x04, 0xF0, 0xDC},
209*11be35a1SLionel Sambuc 	{0x95, 0xBA, 0xA9, 0x4E, 0x87, 0x36, 0xF2, 0x89},
210*11be35a1SLionel Sambuc 	{0xD4, 0x07, 0x3A, 0xF1, 0x5A, 0x17, 0x82, 0x0E},
211*11be35a1SLionel Sambuc 	{0xEF, 0x6F, 0xAF, 0xA7, 0x66, 0x1A, 0x7E, 0x89},
212*11be35a1SLionel Sambuc 	{0xC1, 0x97, 0xF5, 0x58, 0x74, 0x8A, 0x20, 0xE7},
213*11be35a1SLionel Sambuc 	{0x43, 0x34, 0xCF, 0xDA, 0x22, 0xC4, 0x86, 0xC8},
214*11be35a1SLionel Sambuc 	{0x08, 0xD7, 0xB4, 0xFB, 0x62, 0x9D, 0x08, 0x85}
215*11be35a1SLionel Sambuc };
216*11be35a1SLionel Sambuc 
217*11be35a1SLionel Sambuc static unsigned char cbc_key[8] = {
218*11be35a1SLionel Sambuc 	0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
219*11be35a1SLionel Sambuc };
220*11be35a1SLionel Sambuc static unsigned char cbc2_key[8] = {
221*11be35a1SLionel Sambuc 	0xf1, 0xe0, 0xd3, 0xc2, 0xb5, 0xa4, 0x97, 0x86,
222*11be35a1SLionel Sambuc };
223*11be35a1SLionel Sambuc static unsigned char cbc3_key[8] = {
224*11be35a1SLionel Sambuc 	0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
225*11be35a1SLionel Sambuc };
226*11be35a1SLionel Sambuc static unsigned char cbc_iv[8] = {
227*11be35a1SLionel Sambuc 	0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
228*11be35a1SLionel Sambuc };
229*11be35a1SLionel Sambuc /*
230*11be35a1SLionel Sambuc  * Changed the following text constant to binary so it will work on ebcdic
231*11be35a1SLionel Sambuc  * machines :-)
232*11be35a1SLionel Sambuc  */
233*11be35a1SLionel Sambuc /* static char cbc_data[40]="7654321 Now is the time for \0001"; */
234*11be35a1SLionel Sambuc static unsigned char cbc_data[40] = {
235*11be35a1SLionel Sambuc 	0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20,
236*11be35a1SLionel Sambuc 	0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
237*11be35a1SLionel Sambuc 	0x68, 0x65, 0x20, 0x74, 0x69, 0x6D, 0x65, 0x20,
238*11be35a1SLionel Sambuc 	0x66, 0x6F, 0x72, 0x20, 0x00, 0x31, 0x00, 0x00,
239*11be35a1SLionel Sambuc 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240*11be35a1SLionel Sambuc };
241*11be35a1SLionel Sambuc 
242*11be35a1SLionel Sambuc static unsigned char cbc_ok[32] = {
243*11be35a1SLionel Sambuc 	0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4,
244*11be35a1SLionel Sambuc 	0xac, 0xd8, 0xae, 0xfd, 0xdf, 0xd8, 0xa1, 0xeb,
245*11be35a1SLionel Sambuc 	0x46, 0x8e, 0x91, 0x15, 0x78, 0x88, 0xba, 0x68,
246*11be35a1SLionel Sambuc 	0x1d, 0x26, 0x93, 0x97, 0xf7, 0xfe, 0x62, 0xb4,
247*11be35a1SLionel Sambuc };
248*11be35a1SLionel Sambuc 
249*11be35a1SLionel Sambuc #ifdef SCREW_THE_PARITY
250*11be35a1SLionel Sambuc #error "SCREW_THE_PARITY is not ment to be defined."
251*11be35a1SLionel Sambuc #error "Original vectors are preserved for reference only."
252*11be35a1SLionel Sambuc static unsigned char cbc2_key[8] = {
253*11be35a1SLionel Sambuc 	0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87,
254*11be35a1SLionel Sambuc };
255*11be35a1SLionel Sambuc static unsigned char xcbc_ok[32] = {
256*11be35a1SLionel Sambuc 	0x86, 0x74, 0x81, 0x0D, 0x61, 0xA4, 0xA5, 0x48,
257*11be35a1SLionel Sambuc 	0xB9, 0x93, 0x03, 0xE1, 0xB8, 0xBB, 0xBD, 0xBD,
258*11be35a1SLionel Sambuc 	0x64, 0x30, 0x0B, 0xB9, 0x06, 0x65, 0x81, 0x76,
259*11be35a1SLionel Sambuc 	0x04, 0x1D, 0x77, 0x62, 0x17, 0xCA, 0x2B, 0xD2,
260*11be35a1SLionel Sambuc };
261*11be35a1SLionel Sambuc #else
262*11be35a1SLionel Sambuc static unsigned char xcbc_ok[32] = {
263*11be35a1SLionel Sambuc 	0x84, 0x6B, 0x29, 0x14, 0x85, 0x1E, 0x9A, 0x29,
264*11be35a1SLionel Sambuc 	0x54, 0x73, 0x2F, 0x8A, 0xA0, 0xA6, 0x11, 0xC1,
265*11be35a1SLionel Sambuc 	0x15, 0xCD, 0xC2, 0xD7, 0x95, 0x1B, 0x10, 0x53,
266*11be35a1SLionel Sambuc 	0xA6, 0x3C, 0x5E, 0x03, 0xB2, 0x1A, 0xA3, 0xC4,
267*11be35a1SLionel Sambuc };
268*11be35a1SLionel Sambuc #endif
269*11be35a1SLionel Sambuc 
270*11be35a1SLionel Sambuc static unsigned char cbc3_ok[32] = {
271*11be35a1SLionel Sambuc 	0x3F, 0xE3, 0x01, 0xC9, 0x62, 0xAC, 0x01, 0xD0,
272*11be35a1SLionel Sambuc 	0x22, 0x13, 0x76, 0x3C, 0x1C, 0xBD, 0x4C, 0xDC,
273*11be35a1SLionel Sambuc 	0x79, 0x96, 0x57, 0xC0, 0x64, 0xEC, 0xF5, 0xD4,
274*11be35a1SLionel Sambuc 	0x1C, 0x67, 0x38, 0x12, 0xCF, 0xDE, 0x96, 0x75
275*11be35a1SLionel Sambuc };
276*11be35a1SLionel Sambuc 
277*11be35a1SLionel Sambuc static unsigned char pcbc_ok[32] = {
278*11be35a1SLionel Sambuc 	0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4,
279*11be35a1SLionel Sambuc 	0x6d, 0xec, 0xb4, 0x70, 0xa0, 0xe5, 0x6b, 0x15,
280*11be35a1SLionel Sambuc 	0xae, 0xa6, 0xbf, 0x61, 0xed, 0x7d, 0x9c, 0x9f,
281*11be35a1SLionel Sambuc 	0xf7, 0x17, 0x46, 0x3b, 0x8a, 0xb3, 0xcc, 0x88
282*11be35a1SLionel Sambuc };
283*11be35a1SLionel Sambuc 
284*11be35a1SLionel Sambuc static unsigned char cfb_key[8] = {
285*11be35a1SLionel Sambuc 	0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
286*11be35a1SLionel Sambuc };
287*11be35a1SLionel Sambuc static unsigned char cfb_iv[8] = {
288*11be35a1SLionel Sambuc 	0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
289*11be35a1SLionel Sambuc };
290*11be35a1SLionel Sambuc static unsigned char cfb_buf1[40], cfb_buf2[40], cfb_tmp[8];
291*11be35a1SLionel Sambuc static unsigned char plain[24] =
292*11be35a1SLionel Sambuc {
293*11be35a1SLionel Sambuc 	0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73,
294*11be35a1SLionel Sambuc 	0x20, 0x74, 0x68, 0x65, 0x20, 0x74,
295*11be35a1SLionel Sambuc 	0x69, 0x6d, 0x65, 0x20, 0x66, 0x6f,
296*11be35a1SLionel Sambuc 	0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20,
297*11be35a1SLionel Sambuc };
298*11be35a1SLionel Sambuc static unsigned char cfb_cipher8[24] = {
299*11be35a1SLionel Sambuc 	0xf3, 0x1f, 0xda, 0x07, 0x01, 0x14,
300*11be35a1SLionel Sambuc 	0x62, 0xee, 0x18, 0x7f, 0x43, 0xd8,
301*11be35a1SLionel Sambuc 	0x0a, 0x7c, 0xd9, 0xb5, 0xb0, 0xd2,
302*11be35a1SLionel Sambuc 	0x90, 0xda, 0x6e, 0x5b, 0x9a, 0x87,
303*11be35a1SLionel Sambuc };
304*11be35a1SLionel Sambuc static unsigned char cfb_cipher16[24] = {
305*11be35a1SLionel Sambuc 	0xF3, 0x09, 0x87, 0x87, 0x7F, 0x57,
306*11be35a1SLionel Sambuc 	0xF7, 0x3C, 0x36, 0xB6, 0xDB, 0x70,
307*11be35a1SLionel Sambuc 	0xD8, 0xD5, 0x34, 0x19, 0xD3, 0x86,
308*11be35a1SLionel Sambuc 	0xB2, 0x23, 0xB7, 0xB2, 0xAD, 0x1B,
309*11be35a1SLionel Sambuc };
310*11be35a1SLionel Sambuc static unsigned char cfb_cipher32[24] = {
311*11be35a1SLionel Sambuc 	0xF3, 0x09, 0x62, 0x49, 0xA4, 0xDF,
312*11be35a1SLionel Sambuc 	0xA4, 0x9F, 0x33, 0xDC, 0x7B, 0xAD,
313*11be35a1SLionel Sambuc 	0x4C, 0xC8, 0x9F, 0x64, 0xE4, 0x53,
314*11be35a1SLionel Sambuc 	0xE5, 0xEC, 0x67, 0x20, 0xDA, 0xB6,
315*11be35a1SLionel Sambuc };
316*11be35a1SLionel Sambuc static unsigned char cfb_cipher48[24] = {
317*11be35a1SLionel Sambuc 	0xF3, 0x09, 0x62, 0x49, 0xC7, 0xF4,
318*11be35a1SLionel Sambuc 	0x30, 0xB5, 0x15, 0xEC, 0xBB, 0x85,
319*11be35a1SLionel Sambuc 	0x97, 0x5A, 0x13, 0x8C, 0x68, 0x60,
320*11be35a1SLionel Sambuc 	0xE2, 0x38, 0x34, 0x3C, 0xDC, 0x1F,
321*11be35a1SLionel Sambuc };
322*11be35a1SLionel Sambuc static unsigned char cfb_cipher64[24] = {
323*11be35a1SLionel Sambuc 	0xF3, 0x09, 0x62, 0x49, 0xC7, 0xF4,
324*11be35a1SLionel Sambuc 	0x6E, 0x51, 0xA6, 0x9E, 0x83, 0x9B,
325*11be35a1SLionel Sambuc 	0x1A, 0x92, 0xF7, 0x84, 0x03, 0x46,
326*11be35a1SLionel Sambuc 	0x71, 0x33, 0x89, 0x8E, 0xA6, 0x22,
327*11be35a1SLionel Sambuc };
328*11be35a1SLionel Sambuc 
329*11be35a1SLionel Sambuc static unsigned char ofb_key[8] = {
330*11be35a1SLionel Sambuc 	0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
331*11be35a1SLionel Sambuc };
332*11be35a1SLionel Sambuc static unsigned char ofb_iv[8] = {
333*11be35a1SLionel Sambuc 	0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
334*11be35a1SLionel Sambuc };
335*11be35a1SLionel Sambuc static unsigned char ofb_buf1[24], ofb_buf2[24], ofb_tmp[8];
336*11be35a1SLionel Sambuc static unsigned char ofb_cipher[24] =
337*11be35a1SLionel Sambuc {
338*11be35a1SLionel Sambuc 	0xf3, 0x09, 0x62, 0x49, 0xc7, 0xf4, 0x6e, 0x51,
339*11be35a1SLionel Sambuc 	0x35, 0xf2, 0x4a, 0x24, 0x2e, 0xeb, 0x3d, 0x3f,
340*11be35a1SLionel Sambuc 	0x3d, 0x6d, 0x5b, 0xe3, 0x25, 0x5a, 0xf8, 0xc3
341*11be35a1SLionel Sambuc };
342*11be35a1SLionel Sambuc 
343*11be35a1SLionel Sambuc static DES_LONG cbc_cksum_ret = 0xB462FEF7L;
344*11be35a1SLionel Sambuc static unsigned char cbc_cksum_data[8] = {
345*11be35a1SLionel Sambuc 	0x1D, 0x26, 0x93, 0x97, 0xf7, 0xfe, 0x62, 0xb4,
346*11be35a1SLionel Sambuc };
347*11be35a1SLionel Sambuc 
348*11be35a1SLionel Sambuc static char *
pt(unsigned char * p)349*11be35a1SLionel Sambuc pt(unsigned char *p)
350*11be35a1SLionel Sambuc {
351*11be35a1SLionel Sambuc 	static char bufs[10][20];
352*11be35a1SLionel Sambuc 	static int bnum = 0;
353*11be35a1SLionel Sambuc 	char *ret;
354*11be35a1SLionel Sambuc 	int i;
355*11be35a1SLionel Sambuc 	static const char *f = "0123456789ABCDEF";
356*11be35a1SLionel Sambuc 
357*11be35a1SLionel Sambuc 	ret = &(bufs[bnum++][0]);
358*11be35a1SLionel Sambuc 	bnum %= 10;
359*11be35a1SLionel Sambuc 	for (i = 0; i < 8; i++) {
360*11be35a1SLionel Sambuc 		ret[i * 2] = f[(p[i] >> 4) & 0xf];
361*11be35a1SLionel Sambuc 		ret[i * 2 + 1] = f[p[i] & 0xf];
362*11be35a1SLionel Sambuc 	}
363*11be35a1SLionel Sambuc 	ret[16] = '\0';
364*11be35a1SLionel Sambuc 	return (ret);
365*11be35a1SLionel Sambuc }
366*11be35a1SLionel Sambuc 
367*11be35a1SLionel Sambuc static void
fail_cfb_buf(const char * msg,unsigned char * ptr)368*11be35a1SLionel Sambuc fail_cfb_buf(const char *msg, unsigned char *ptr)
369*11be35a1SLionel Sambuc {
370*11be35a1SLionel Sambuc 	char buf[1024];
371*11be35a1SLionel Sambuc 	int i;
372*11be35a1SLionel Sambuc 
373*11be35a1SLionel Sambuc 	*buf = '\0';
374*11be35a1SLionel Sambuc 	for (i = 0; i < 24; i += 8) {
375*11be35a1SLionel Sambuc 		char buf2[128];
376*11be35a1SLionel Sambuc 		snprintf(buf2, sizeof(buf2), "%s /", pt(&(cfb_buf1[i])));
377*11be35a1SLionel Sambuc 		strlcat(buf, buf2, sizeof(buf));
378*11be35a1SLionel Sambuc 	}
379*11be35a1SLionel Sambuc 
380*11be35a1SLionel Sambuc 	atf_tc_fail_nonfatal("%s: %s", msg, buf);
381*11be35a1SLionel Sambuc }
382*11be35a1SLionel Sambuc 
383*11be35a1SLionel Sambuc #if !defined(LIBDES_LIT)
384*11be35a1SLionel Sambuc static void
cfb_test(int bits,unsigned char * cfb_cipher)385*11be35a1SLionel Sambuc cfb_test(int bits, unsigned char *cfb_cipher)
386*11be35a1SLionel Sambuc {
387*11be35a1SLionel Sambuc 	des_key_schedule ks;
388*11be35a1SLionel Sambuc 
389*11be35a1SLionel Sambuc 	des_set_key_checked(&cfb_key, ks);
390*11be35a1SLionel Sambuc 	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
391*11be35a1SLionel Sambuc 	des_cfb_encrypt(plain, cfb_buf1, bits, sizeof(plain), ks, &cfb_tmp,
392*11be35a1SLionel Sambuc 			DES_ENCRYPT);
393*11be35a1SLionel Sambuc 	if (memcmp(cfb_cipher, cfb_buf1, sizeof(plain)) != 0)
394*11be35a1SLionel Sambuc 		fail_cfb_buf("cfb_encrypt encrypt error", cfb_buf1);
395*11be35a1SLionel Sambuc 	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
396*11be35a1SLionel Sambuc 	des_cfb_encrypt(cfb_buf1, cfb_buf2, bits, sizeof(plain), ks, &cfb_tmp,
397*11be35a1SLionel Sambuc 			DES_DECRYPT);
398*11be35a1SLionel Sambuc 	if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0)
399*11be35a1SLionel Sambuc 		fail_cfb_buf("cfb_encrypt decrypt error", cfb_buf2);
400*11be35a1SLionel Sambuc }
401*11be35a1SLionel Sambuc #endif /* !defined(LIBDES_LIT) */
402*11be35a1SLionel Sambuc 
403*11be35a1SLionel Sambuc #if !defined(LIBDES_LIT)
404*11be35a1SLionel Sambuc static void
cfb64_test(unsigned char * cfb_cipher)405*11be35a1SLionel Sambuc cfb64_test(unsigned char *cfb_cipher)
406*11be35a1SLionel Sambuc {
407*11be35a1SLionel Sambuc 	int n;
408*11be35a1SLionel Sambuc 	des_key_schedule ks;
409*11be35a1SLionel Sambuc 
410*11be35a1SLionel Sambuc 	des_set_key_checked(&cfb_key, ks);
411*11be35a1SLionel Sambuc 	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
412*11be35a1SLionel Sambuc 	n = 0;
413*11be35a1SLionel Sambuc 	des_cfb64_encrypt(plain, cfb_buf1, 12, ks, &cfb_tmp, &n, DES_ENCRYPT);
414*11be35a1SLionel Sambuc 	des_cfb64_encrypt(&(plain[12]), &(cfb_buf1[12]), sizeof(plain) - 12, ks,
415*11be35a1SLionel Sambuc 			  &cfb_tmp, &n, DES_ENCRYPT);
416*11be35a1SLionel Sambuc 	if (memcmp(cfb_cipher, cfb_buf1, sizeof(plain)) != 0)
417*11be35a1SLionel Sambuc 		fail_cfb_buf("cfb_encrypt encrypt error", cfb_buf1);
418*11be35a1SLionel Sambuc 	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
419*11be35a1SLionel Sambuc 	n = 0;
420*11be35a1SLionel Sambuc 	des_cfb64_encrypt(cfb_buf1, cfb_buf2, 17, ks, &cfb_tmp, &n, DES_DECRYPT);
421*11be35a1SLionel Sambuc 	des_cfb64_encrypt(&(cfb_buf1[17]), &(cfb_buf2[17]),
422*11be35a1SLionel Sambuc 			  sizeof(plain) - 17, ks, &cfb_tmp, &n, DES_DECRYPT);
423*11be35a1SLionel Sambuc 	if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0)
424*11be35a1SLionel Sambuc 		fail_cfb_buf("cfb_encrypt decrypt error", cfb_buf2);
425*11be35a1SLionel Sambuc }
426*11be35a1SLionel Sambuc #endif /* !defined(LIBDES_LIT) */
427*11be35a1SLionel Sambuc 
428*11be35a1SLionel Sambuc #if !defined(LIBDES_LIT)
429*11be35a1SLionel Sambuc static void
ede_cfb64_test(unsigned char * cfb_cipher)430*11be35a1SLionel Sambuc ede_cfb64_test(unsigned char *cfb_cipher)
431*11be35a1SLionel Sambuc {
432*11be35a1SLionel Sambuc 	int n;
433*11be35a1SLionel Sambuc 	des_key_schedule ks;
434*11be35a1SLionel Sambuc 
435*11be35a1SLionel Sambuc 	des_set_key_checked(&cfb_key, ks);
436*11be35a1SLionel Sambuc 	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
437*11be35a1SLionel Sambuc 	n = 0;
438*11be35a1SLionel Sambuc 	des_ede3_cfb64_encrypt(plain, cfb_buf1, 12, ks, ks, ks, &cfb_tmp, &n,
439*11be35a1SLionel Sambuc 			       DES_ENCRYPT);
440*11be35a1SLionel Sambuc 	des_ede3_cfb64_encrypt(&(plain[12]), &(cfb_buf1[12]),
441*11be35a1SLionel Sambuc 			       sizeof(plain) - 12, ks, ks, ks,
442*11be35a1SLionel Sambuc 			       &cfb_tmp, &n, DES_ENCRYPT);
443*11be35a1SLionel Sambuc 	if (memcmp(cfb_cipher, cfb_buf1, sizeof(plain)) != 0)
444*11be35a1SLionel Sambuc 		fail_cfb_buf("ede_cfb_encrypt encrypt error", cfb_buf1);
445*11be35a1SLionel Sambuc 	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
446*11be35a1SLionel Sambuc 	n = 0;
447*11be35a1SLionel Sambuc 	des_ede3_cfb64_encrypt(cfb_buf1, cfb_buf2, (long) 17, ks, ks, ks,
448*11be35a1SLionel Sambuc 			       &cfb_tmp, &n, DES_DECRYPT);
449*11be35a1SLionel Sambuc 	des_ede3_cfb64_encrypt(&(cfb_buf1[17]), &(cfb_buf2[17]),
450*11be35a1SLionel Sambuc 			       sizeof(plain) - 17, ks, ks, ks,
451*11be35a1SLionel Sambuc 			       &cfb_tmp, &n, DES_DECRYPT);
452*11be35a1SLionel Sambuc 	if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0)
453*11be35a1SLionel Sambuc 		fail_cfb_buf("ede_cfb_encrypt decrypt error", cfb_buf2);
454*11be35a1SLionel Sambuc }
455*11be35a1SLionel Sambuc #endif /* !defined(LIBDES_LIT) */
456*11be35a1SLionel Sambuc 
457*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(cbcm);
458*11be35a1SLionel Sambuc #if defined(NO_DESCBCM)
ATF_TC_BODY(cbcm,tc)459*11be35a1SLionel Sambuc ATF_TC_BODY(cbcm, tc)
460*11be35a1SLionel Sambuc {
461*11be35a1SLionel Sambuc 	atf_tc_skip("Test program built with NO_DESCBCM");
462*11be35a1SLionel Sambuc }
463*11be35a1SLionel Sambuc #else /* defined(NO_DESCBM) */
ATF_TC_BODY(cbcm,tc)464*11be35a1SLionel Sambuc ATF_TC_BODY(cbcm, tc)
465*11be35a1SLionel Sambuc {
466*11be35a1SLionel Sambuc 	int i, j;
467*11be35a1SLionel Sambuc 	des_cblock iv3, iv2;
468*11be35a1SLionel Sambuc 	unsigned char cbc_in[40], cbc_out[40];
469*11be35a1SLionel Sambuc 	des_key_schedule ks, ks2, ks3;
470*11be35a1SLionel Sambuc 
471*11be35a1SLionel Sambuc 	if ((j = des_set_key_checked(&cbc_key, ks)) != 0) {
472*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("Key error %d\n", j);
473*11be35a1SLionel Sambuc 	}
474*11be35a1SLionel Sambuc 	if ((j = des_set_key_checked(&cbc2_key, ks2)) != 0) {
475*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("Key error %d\n", j);
476*11be35a1SLionel Sambuc 	}
477*11be35a1SLionel Sambuc 	if ((j = des_set_key_checked(&cbc3_key, ks3)) != 0) {
478*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("Key error %d\n", j);
479*11be35a1SLionel Sambuc 	}
480*11be35a1SLionel Sambuc 	memset(cbc_out, 0, 40);
481*11be35a1SLionel Sambuc 	memset(cbc_in, 0, 40);
482*11be35a1SLionel Sambuc 	i = strlen((char *) cbc_data) + 1;
483*11be35a1SLionel Sambuc 	/* i=((i+7)/8)*8; */
484*11be35a1SLionel Sambuc 	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
485*11be35a1SLionel Sambuc 	memset(iv2, '\0', sizeof iv2);
486*11be35a1SLionel Sambuc 
487*11be35a1SLionel Sambuc 	des_ede3_cbcm_encrypt(cbc_data, cbc_out, 16L, ks, ks2, ks3, &iv3, &iv2,
488*11be35a1SLionel Sambuc 			      DES_ENCRYPT);
489*11be35a1SLionel Sambuc 	des_ede3_cbcm_encrypt(&cbc_data[16], &cbc_out[16], i - 16, ks, ks2, ks3,
490*11be35a1SLionel Sambuc 			      &iv3, &iv2, DES_ENCRYPT);
491*11be35a1SLionel Sambuc 	/*
492*11be35a1SLionel Sambuc 	 * if (memcmp(cbc_out,cbc3_ok, (unsigned int)(strlen((char
493*11be35a1SLionel Sambuc 	 * *)cbc_data)+1+7)/8*8) != 0) { printf("des_ede3_cbc_encrypt encrypt
494*11be35a1SLionel Sambuc 	 * error\n"); err=1; }
495*11be35a1SLionel Sambuc 	 */
496*11be35a1SLionel Sambuc 	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
497*11be35a1SLionel Sambuc 	memset(iv2, '\0', sizeof iv2);
498*11be35a1SLionel Sambuc 	des_ede3_cbcm_encrypt(cbc_out, cbc_in, i, ks, ks2, ks3, &iv3, &iv2,
499*11be35a1SLionel Sambuc 			      DES_DECRYPT);
500*11be35a1SLionel Sambuc 	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0) {
501*11be35a1SLionel Sambuc 		char buf[1024];
502*11be35a1SLionel Sambuc 		int n;
503*11be35a1SLionel Sambuc 
504*11be35a1SLionel Sambuc 		*buf = '\0';
505*11be35a1SLionel Sambuc 		for (n = 0; n < i; ++n) {
506*11be35a1SLionel Sambuc 			char buf2[16];
507*11be35a1SLionel Sambuc 			snprintf(buf2, sizeof(buf2), " %02x", cbc_data[n]);
508*11be35a1SLionel Sambuc 			strlcat(buf, buf2, sizeof(buf));
509*11be35a1SLionel Sambuc 		}
510*11be35a1SLionel Sambuc 		strlcat(buf, ", ", sizeof(buf));
511*11be35a1SLionel Sambuc 		for (n = 0; n < i; ++n) {
512*11be35a1SLionel Sambuc 			char buf2[16];
513*11be35a1SLionel Sambuc 			snprintf(buf2, sizeof(buf2), " %02x", cbc_in[n]);
514*11be35a1SLionel Sambuc 			strlcat(buf, buf2, sizeof(buf));
515*11be35a1SLionel Sambuc 		}
516*11be35a1SLionel Sambuc 
517*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("des_ede3_cbcm_encrypt decrypt error: %s",
518*11be35a1SLionel Sambuc 				     buf);
519*11be35a1SLionel Sambuc 	}
520*11be35a1SLionel Sambuc }
521*11be35a1SLionel Sambuc #endif /* defined(NO_DESCBM) */
522*11be35a1SLionel Sambuc 
523*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(ecb);
ATF_TC_BODY(ecb,tc)524*11be35a1SLionel Sambuc ATF_TC_BODY(ecb, tc)
525*11be35a1SLionel Sambuc {
526*11be35a1SLionel Sambuc 	int i;
527*11be35a1SLionel Sambuc 	des_cblock in, out, outin;
528*11be35a1SLionel Sambuc 	des_key_schedule ks;
529*11be35a1SLionel Sambuc 
530*11be35a1SLionel Sambuc 	for (i = 0; i < NUM_TESTS; i++) {
531*11be35a1SLionel Sambuc 		des_set_key_unchecked(&key_data[i], ks);
532*11be35a1SLionel Sambuc 		memcpy(in, plain_data[i], 8);
533*11be35a1SLionel Sambuc 		memset(out, 0, 8);
534*11be35a1SLionel Sambuc 		memset(outin, 0, 8);
535*11be35a1SLionel Sambuc 		des_ecb_encrypt(&in, &out, ks, DES_ENCRYPT);
536*11be35a1SLionel Sambuc 		des_ecb_encrypt(&out, &outin, ks, DES_DECRYPT);
537*11be35a1SLionel Sambuc 
538*11be35a1SLionel Sambuc 		if (memcmp(out, cipher_data[i], 8) != 0) {
539*11be35a1SLionel Sambuc 			atf_tc_fail_nonfatal("Encryption error %2d\nk=%s p=%s "
540*11be35a1SLionel Sambuc 					     "o=%s act=%s\n", i + 1,
541*11be35a1SLionel Sambuc 					     pt(key_data[i]), pt(in),
542*11be35a1SLionel Sambuc 					     pt(cipher_data[i]), pt(out));
543*11be35a1SLionel Sambuc 		}
544*11be35a1SLionel Sambuc 		if (memcmp(in, outin, 8) != 0) {
545*11be35a1SLionel Sambuc 			atf_tc_fail_nonfatal("Decryption error %2d\nk=%s p=%s "
546*11be35a1SLionel Sambuc 					     "o=%s act=%s\n", i + 1,
547*11be35a1SLionel Sambuc 					     pt(key_data[i]), pt(out), pt(in),
548*11be35a1SLionel Sambuc 					     pt(outin));
549*11be35a1SLionel Sambuc 		}
550*11be35a1SLionel Sambuc 	}
551*11be35a1SLionel Sambuc }
552*11be35a1SLionel Sambuc 
553*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(ede_ecb);
554*11be35a1SLionel Sambuc #if defined(LIBDES_LIT)
ATF_TC_BODY(ede_ecb,tc)555*11be35a1SLionel Sambuc ATF_TC_BODY(ede_ecb, tc)
556*11be35a1SLionel Sambuc {
557*11be35a1SLionel Sambuc 	atf_tc_skip("Test program built with LIBDES_LIT");
558*11be35a1SLionel Sambuc }
559*11be35a1SLionel Sambuc #else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ede_ecb,tc)560*11be35a1SLionel Sambuc ATF_TC_BODY(ede_ecb, tc)
561*11be35a1SLionel Sambuc {
562*11be35a1SLionel Sambuc 	int i;
563*11be35a1SLionel Sambuc 	des_cblock in, out, outin;
564*11be35a1SLionel Sambuc 	des_key_schedule ks, ks2, ks3;
565*11be35a1SLionel Sambuc 
566*11be35a1SLionel Sambuc 	for (i = 0; i < (NUM_TESTS - 1); i++) {
567*11be35a1SLionel Sambuc 		des_set_key_unchecked(&key_data[i], ks);
568*11be35a1SLionel Sambuc 		des_set_key_unchecked(&key_data[i + 1], ks2);
569*11be35a1SLionel Sambuc 		des_set_key_unchecked(&key_data[i + 2], ks3);
570*11be35a1SLionel Sambuc 		memcpy(in, plain_data[i], 8);
571*11be35a1SLionel Sambuc 		memset(out, 0, 8);
572*11be35a1SLionel Sambuc 		memset(outin, 0, 8);
573*11be35a1SLionel Sambuc 		des_ecb2_encrypt(&in, &out, ks, ks2, DES_ENCRYPT);
574*11be35a1SLionel Sambuc 		des_ecb2_encrypt(&out, &outin, ks, ks2, DES_DECRYPT);
575*11be35a1SLionel Sambuc 
576*11be35a1SLionel Sambuc 		if (memcmp(out, cipher_ecb2[i], 8) != 0) {
577*11be35a1SLionel Sambuc 			atf_tc_fail_nonfatal("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
578*11be35a1SLionel Sambuc 			 i + 1, pt(key_data[i]), pt(in), pt(cipher_ecb2[i]),
579*11be35a1SLionel Sambuc 			       pt(out));
580*11be35a1SLionel Sambuc 		}
581*11be35a1SLionel Sambuc 		if (memcmp(in, outin, 8) != 0) {
582*11be35a1SLionel Sambuc 			atf_tc_fail_nonfatal("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
583*11be35a1SLionel Sambuc 			i + 1, pt(key_data[i]), pt(out), pt(in), pt(outin));
584*11be35a1SLionel Sambuc 		}
585*11be35a1SLionel Sambuc 	}
586*11be35a1SLionel Sambuc }
587*11be35a1SLionel Sambuc #endif /* defined(LIBDES_LIT) */
588*11be35a1SLionel Sambuc 
589*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(cbc);
ATF_TC_BODY(cbc,tc)590*11be35a1SLionel Sambuc ATF_TC_BODY(cbc, tc)
591*11be35a1SLionel Sambuc {
592*11be35a1SLionel Sambuc 	int j;
593*11be35a1SLionel Sambuc 	des_cblock iv3;
594*11be35a1SLionel Sambuc 	des_key_schedule ks;
595*11be35a1SLionel Sambuc 	unsigned char cbc_in[40], cbc_out[40];
596*11be35a1SLionel Sambuc 
597*11be35a1SLionel Sambuc 	if ((j = des_set_key_checked(&cbc_key, ks)) != 0)
598*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("Key error %d\n", j);
599*11be35a1SLionel Sambuc 	memset(cbc_out, 0, 40);
600*11be35a1SLionel Sambuc 	memset(cbc_in, 0, 40);
601*11be35a1SLionel Sambuc 	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
602*11be35a1SLionel Sambuc 	des_ncbc_encrypt(cbc_data, cbc_out, strlen((char *) cbc_data) + 1, ks,
603*11be35a1SLionel Sambuc 			 &iv3, DES_ENCRYPT);
604*11be35a1SLionel Sambuc 	if (memcmp(cbc_out, cbc_ok, 32) != 0)
605*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("cbc_encrypt encrypt error\n");
606*11be35a1SLionel Sambuc 	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
607*11be35a1SLionel Sambuc 	des_ncbc_encrypt(cbc_out, cbc_in, strlen((char *) cbc_data) + 1, ks,
608*11be35a1SLionel Sambuc 			 &iv3, DES_DECRYPT);
609*11be35a1SLionel Sambuc 	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data)) != 0)
610*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("cbc_encrypt decrypt error\n");
611*11be35a1SLionel Sambuc }
612*11be35a1SLionel Sambuc 
613*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(desx_cbc);
614*11be35a1SLionel Sambuc #if defined(LIBDES_LIT)
ATF_TC_BODY(desx_cbc,tc)615*11be35a1SLionel Sambuc ATF_TC_BODY(desx_cbc, tc)
616*11be35a1SLionel Sambuc {
617*11be35a1SLionel Sambuc 	atf_tc_skip("Test program built with LIBDES_LIT");
618*11be35a1SLionel Sambuc }
619*11be35a1SLionel Sambuc #else /* defined(LIBDES_LIT) */
ATF_TC_BODY(desx_cbc,tc)620*11be35a1SLionel Sambuc ATF_TC_BODY(desx_cbc, tc)
621*11be35a1SLionel Sambuc {
622*11be35a1SLionel Sambuc 	int j;
623*11be35a1SLionel Sambuc 	des_cblock iv3;
624*11be35a1SLionel Sambuc 	des_key_schedule ks;
625*11be35a1SLionel Sambuc 	unsigned char cbc_in[40], cbc_out[40];
626*11be35a1SLionel Sambuc 
627*11be35a1SLionel Sambuc 	if ((j = des_set_key_checked(&cbc_key, ks)) != 0) {
628*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("Key error %d\n", j);
629*11be35a1SLionel Sambuc 	}
630*11be35a1SLionel Sambuc 	memset(cbc_out, 0, 40);
631*11be35a1SLionel Sambuc 	memset(cbc_in, 0, 40);
632*11be35a1SLionel Sambuc 	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
633*11be35a1SLionel Sambuc 	des_xcbc_encrypt(cbc_data, cbc_out, strlen((char *) cbc_data) + 1, ks,
634*11be35a1SLionel Sambuc 			 &iv3, &cbc2_key, &cbc3_key, DES_ENCRYPT);
635*11be35a1SLionel Sambuc 	if (memcmp(cbc_out, xcbc_ok, 32) != 0) {
636*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("des_xcbc_encrypt encrypt error\n");
637*11be35a1SLionel Sambuc 	}
638*11be35a1SLionel Sambuc 	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
639*11be35a1SLionel Sambuc 	des_xcbc_encrypt(cbc_out, cbc_in, strlen((char *) cbc_data) + 1, ks,
640*11be35a1SLionel Sambuc 			 &iv3, &cbc2_key, &cbc3_key, DES_DECRYPT);
641*11be35a1SLionel Sambuc 	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0) {
642*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("des_xcbc_encrypt decrypt error\n");
643*11be35a1SLionel Sambuc 	}
644*11be35a1SLionel Sambuc }
645*11be35a1SLionel Sambuc #endif /* defined(LIBDES_LIT) */
646*11be35a1SLionel Sambuc 
647*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(ede_cbc);
ATF_TC_BODY(ede_cbc,tc)648*11be35a1SLionel Sambuc ATF_TC_BODY(ede_cbc, tc)
649*11be35a1SLionel Sambuc {
650*11be35a1SLionel Sambuc 	int i, j;
651*11be35a1SLionel Sambuc 	des_cblock iv3;
652*11be35a1SLionel Sambuc 	des_key_schedule ks, ks2, ks3;
653*11be35a1SLionel Sambuc 	unsigned char cbc_in[40], cbc_out[40];
654*11be35a1SLionel Sambuc 
655*11be35a1SLionel Sambuc 	if ((j = des_set_key_checked(&cbc_key, ks)) != 0)
656*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("Key error %d\n", j);
657*11be35a1SLionel Sambuc 	if ((j = des_set_key_checked(&cbc2_key, ks2)) != 0)
658*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("Key error %d\n", j);
659*11be35a1SLionel Sambuc 	if ((j = des_set_key_checked(&cbc3_key, ks3)) != 0)
660*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("Key error %d\n", j);
661*11be35a1SLionel Sambuc 	memset(cbc_out, 0, 40);
662*11be35a1SLionel Sambuc 	memset(cbc_in, 0, 40);
663*11be35a1SLionel Sambuc 	i = strlen((char *) cbc_data) + 1;
664*11be35a1SLionel Sambuc 	/* i=((i+7)/8)*8; */
665*11be35a1SLionel Sambuc 	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
666*11be35a1SLionel Sambuc 
667*11be35a1SLionel Sambuc 	des_ede3_cbc_encrypt(cbc_data, cbc_out, 16L, ks, ks2, ks3, &iv3,
668*11be35a1SLionel Sambuc 			     DES_ENCRYPT);
669*11be35a1SLionel Sambuc 	des_ede3_cbc_encrypt(&(cbc_data[16]), &(cbc_out[16]), i - 16, ks, ks2,
670*11be35a1SLionel Sambuc 			     ks3, &iv3, DES_ENCRYPT);
671*11be35a1SLionel Sambuc 	if (memcmp(cbc_out, cbc3_ok, (unsigned int)
672*11be35a1SLionel Sambuc 		   (strlen((char *) cbc_data) + 1 + 7) / 8 * 8) != 0)
673*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("des_ede3_cbc_encrypt encrypt error\n");
674*11be35a1SLionel Sambuc 	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
675*11be35a1SLionel Sambuc 	des_ede3_cbc_encrypt(cbc_out, cbc_in, i, ks, ks2, ks3, &iv3,
676*11be35a1SLionel Sambuc 			     DES_DECRYPT);
677*11be35a1SLionel Sambuc 	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0)
678*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("des_ede3_cbc_encrypt decrypt error\n");
679*11be35a1SLionel Sambuc }
680*11be35a1SLionel Sambuc 
681*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(pcbc);
682*11be35a1SLionel Sambuc #if defined(LIBDES_LIT)
ATF_TC_BODY(pcbc,tc)683*11be35a1SLionel Sambuc ATF_TC_BODY(pcbc, tc)
684*11be35a1SLionel Sambuc {
685*11be35a1SLionel Sambuc 	atf_tc_skip("Test program built with LIBDES_LIT");
686*11be35a1SLionel Sambuc }
687*11be35a1SLionel Sambuc #else /* defined(LIBDES_LIT) */
ATF_TC_BODY(pcbc,tc)688*11be35a1SLionel Sambuc ATF_TC_BODY(pcbc, tc)
689*11be35a1SLionel Sambuc {
690*11be35a1SLionel Sambuc 	int j;
691*11be35a1SLionel Sambuc 	unsigned char cbc_in[40], cbc_out[40];
692*11be35a1SLionel Sambuc 	des_key_schedule ks;
693*11be35a1SLionel Sambuc 
694*11be35a1SLionel Sambuc 	if ((j = des_set_key_checked(&cbc_key, ks)) != 0) {
695*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("Key error %d\n", j);
696*11be35a1SLionel Sambuc 	}
697*11be35a1SLionel Sambuc 	memset(cbc_out, 0, 40);
698*11be35a1SLionel Sambuc 	memset(cbc_in, 0, 40);
699*11be35a1SLionel Sambuc 	des_pcbc_encrypt(cbc_data, cbc_out, strlen((char *) cbc_data) + 1, ks,
700*11be35a1SLionel Sambuc 			 &cbc_iv, DES_ENCRYPT);
701*11be35a1SLionel Sambuc 	if (memcmp(cbc_out, pcbc_ok, 32) != 0) {
702*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("pcbc_encrypt encrypt error\n");
703*11be35a1SLionel Sambuc 	}
704*11be35a1SLionel Sambuc 	des_pcbc_encrypt(cbc_out, cbc_in, strlen((char *) cbc_data) + 1, ks, &cbc_iv,
705*11be35a1SLionel Sambuc 			 DES_DECRYPT);
706*11be35a1SLionel Sambuc 	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0) {
707*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("pcbc_encrypt decrypt error\n");
708*11be35a1SLionel Sambuc 	}
709*11be35a1SLionel Sambuc }
710*11be35a1SLionel Sambuc #endif /* defined(LIBDES_LIT) */
711*11be35a1SLionel Sambuc 
712*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(cfb);
713*11be35a1SLionel Sambuc #if defined(LIBDES_LIT)
ATF_TC_BODY(cfb,tc)714*11be35a1SLionel Sambuc ATF_TC_BODY(cfb, tc)
715*11be35a1SLionel Sambuc {
716*11be35a1SLionel Sambuc 	atf_tc_skip("Test program built with LIBDES_LIT");
717*11be35a1SLionel Sambuc }
718*11be35a1SLionel Sambuc #else /* defined(LIBDES_LIT) */
ATF_TC_BODY(cfb,tc)719*11be35a1SLionel Sambuc ATF_TC_BODY(cfb, tc)
720*11be35a1SLionel Sambuc {
721*11be35a1SLionel Sambuc 	size_t i;
722*11be35a1SLionel Sambuc 	des_key_schedule ks;
723*11be35a1SLionel Sambuc 
724*11be35a1SLionel Sambuc 	printf("cfb8\n");
725*11be35a1SLionel Sambuc 	cfb_test(8, cfb_cipher8);
726*11be35a1SLionel Sambuc 	printf("cfb16\n");
727*11be35a1SLionel Sambuc 	cfb_test(16, cfb_cipher16);
728*11be35a1SLionel Sambuc 	printf("cfb32\n");
729*11be35a1SLionel Sambuc 	cfb_test(32, cfb_cipher32);
730*11be35a1SLionel Sambuc 	printf("cfb48\n");
731*11be35a1SLionel Sambuc 	cfb_test(48, cfb_cipher48);
732*11be35a1SLionel Sambuc 	printf("cfb64\n");
733*11be35a1SLionel Sambuc 	cfb_test(64, cfb_cipher64);
734*11be35a1SLionel Sambuc 
735*11be35a1SLionel Sambuc 	printf("cfb64()\n");
736*11be35a1SLionel Sambuc 	cfb64_test(cfb_cipher64);
737*11be35a1SLionel Sambuc 
738*11be35a1SLionel Sambuc 	des_set_key_checked(&cfb_key, ks);
739*11be35a1SLionel Sambuc 	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
740*11be35a1SLionel Sambuc 	for (i = 0; i < sizeof(plain); i++)
741*11be35a1SLionel Sambuc 		des_cfb_encrypt(&(plain[i]), &(cfb_buf1[i]),
742*11be35a1SLionel Sambuc 				8, 1, ks, &cfb_tmp, DES_ENCRYPT);
743*11be35a1SLionel Sambuc 	if (memcmp(cfb_cipher8, cfb_buf1, sizeof(plain)) != 0)
744*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("cfb_encrypt small encrypt error\n");
745*11be35a1SLionel Sambuc 	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
746*11be35a1SLionel Sambuc 	for (i = 0; i < sizeof(plain); i++)
747*11be35a1SLionel Sambuc 		des_cfb_encrypt(&(cfb_buf1[i]), &(cfb_buf2[i]),
748*11be35a1SLionel Sambuc 				8, 1, ks, &cfb_tmp, DES_DECRYPT);
749*11be35a1SLionel Sambuc 	if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0)
750*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("cfb_encrypt small decrypt error\n");
751*11be35a1SLionel Sambuc 	printf("ede_cfb64()\n");
752*11be35a1SLionel Sambuc 	ede_cfb64_test(cfb_cipher64);
753*11be35a1SLionel Sambuc }
754*11be35a1SLionel Sambuc #endif /* defined(LIBDES_LIT) */
755*11be35a1SLionel Sambuc 
756*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(ofb);
757*11be35a1SLionel Sambuc #if defined(LIBDES_LIT)
ATF_TC_BODY(ofb,tc)758*11be35a1SLionel Sambuc ATF_TC_BODY(ofb, tc)
759*11be35a1SLionel Sambuc {
760*11be35a1SLionel Sambuc 	atf_tc_skip("Test program built with LIBDES_LIT");
761*11be35a1SLionel Sambuc }
762*11be35a1SLionel Sambuc #else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ofb,tc)763*11be35a1SLionel Sambuc ATF_TC_BODY(ofb, tc)
764*11be35a1SLionel Sambuc {
765*11be35a1SLionel Sambuc 	des_key_schedule ks;
766*11be35a1SLionel Sambuc 
767*11be35a1SLionel Sambuc 	des_set_key_checked(&ofb_key, ks);
768*11be35a1SLionel Sambuc 	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
769*11be35a1SLionel Sambuc 	des_ofb_encrypt(plain, ofb_buf1, 64, sizeof(plain) / 8, ks, &ofb_tmp);
770*11be35a1SLionel Sambuc 	if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
771*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("ofb_encrypt encrypt error: "
772*11be35a1SLionel Sambuc 				     "%02X %02X %02X %02X %02X %02X %02X %02X, "
773*11be35a1SLionel Sambuc 				     "%02X %02X %02X %02X %02X %02X %02X %02X",
774*11be35a1SLionel Sambuc 				     ofb_buf1[8 + 0], ofb_buf1[8 + 1],
775*11be35a1SLionel Sambuc 				     ofb_buf1[8 + 2], ofb_buf1[8 + 3],
776*11be35a1SLionel Sambuc 				     ofb_buf1[8 + 4], ofb_buf1[8 + 5],
777*11be35a1SLionel Sambuc 				     ofb_buf1[8 + 6], ofb_buf1[8 + 7],
778*11be35a1SLionel Sambuc 				     ofb_buf1[8 + 0], ofb_cipher[8 + 1],
779*11be35a1SLionel Sambuc 				     ofb_cipher[8 + 2], ofb_cipher[8 + 3],
780*11be35a1SLionel Sambuc 				     ofb_buf1[8 + 4], ofb_cipher[8 + 5],
781*11be35a1SLionel Sambuc 				     ofb_cipher[8 + 6], ofb_cipher[8 + 7]);
782*11be35a1SLionel Sambuc 	}
783*11be35a1SLionel Sambuc 	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
784*11be35a1SLionel Sambuc 	des_ofb_encrypt(ofb_buf1, ofb_buf2, 64, sizeof(ofb_buf1) / 8, ks,
785*11be35a1SLionel Sambuc 			&ofb_tmp);
786*11be35a1SLionel Sambuc 	if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
787*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("ofb_encrypt decrypt error: "
788*11be35a1SLionel Sambuc 				     "%02X %02X %02X %02X %02X %02X %02X %02X, "
789*11be35a1SLionel Sambuc 				     "%02X %02X %02X %02X %02X %02X %02X %02X",
790*11be35a1SLionel Sambuc 				     ofb_buf2[8 + 0], ofb_buf2[8 + 1],
791*11be35a1SLionel Sambuc 				     ofb_buf2[8 + 2], ofb_buf2[8 + 3],
792*11be35a1SLionel Sambuc 				     ofb_buf2[8 + 4], ofb_buf2[8 + 5],
793*11be35a1SLionel Sambuc 				     ofb_buf2[8 + 6], ofb_buf2[8 + 7],
794*11be35a1SLionel Sambuc 				     plain[8 + 0], plain[8 + 1],
795*11be35a1SLionel Sambuc 				     plain[8 + 2], plain[8 + 3],
796*11be35a1SLionel Sambuc 				     plain[8 + 4], plain[8 + 5],
797*11be35a1SLionel Sambuc 				     plain[8 + 6], plain[8 + 7]);
798*11be35a1SLionel Sambuc 	}
799*11be35a1SLionel Sambuc }
800*11be35a1SLionel Sambuc #endif /* defined(LIBDES_LIT) */
801*11be35a1SLionel Sambuc 
802*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(ofb64);
803*11be35a1SLionel Sambuc #if defined(LIBDES_LIT)
ATF_TC_BODY(ofb64,tc)804*11be35a1SLionel Sambuc ATF_TC_BODY(ofb64, tc)
805*11be35a1SLionel Sambuc {
806*11be35a1SLionel Sambuc 	atf_tc_skip("Test program built with LIBDES_LIT");
807*11be35a1SLionel Sambuc }
808*11be35a1SLionel Sambuc #else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ofb64,tc)809*11be35a1SLionel Sambuc ATF_TC_BODY(ofb64, tc)
810*11be35a1SLionel Sambuc {
811*11be35a1SLionel Sambuc 	int num;
812*11be35a1SLionel Sambuc 	size_t i;
813*11be35a1SLionel Sambuc 	des_key_schedule ks;
814*11be35a1SLionel Sambuc 
815*11be35a1SLionel Sambuc 	des_set_key_checked(&ofb_key, ks);
816*11be35a1SLionel Sambuc 	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
817*11be35a1SLionel Sambuc 	memset(ofb_buf1, 0, sizeof(ofb_buf1));
818*11be35a1SLionel Sambuc 	memset(ofb_buf2, 0, sizeof(ofb_buf1));
819*11be35a1SLionel Sambuc 	num = 0;
820*11be35a1SLionel Sambuc 	for (i = 0; i < sizeof(plain); i++) {
821*11be35a1SLionel Sambuc 		des_ofb64_encrypt(&(plain[i]), &(ofb_buf1[i]), 1, ks, &ofb_tmp,
822*11be35a1SLionel Sambuc 				  &num);
823*11be35a1SLionel Sambuc 	}
824*11be35a1SLionel Sambuc 	if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
825*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("ofb64_encrypt encrypt error\n");
826*11be35a1SLionel Sambuc 	}
827*11be35a1SLionel Sambuc 	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
828*11be35a1SLionel Sambuc 	num = 0;
829*11be35a1SLionel Sambuc 	des_ofb64_encrypt(ofb_buf1, ofb_buf2, sizeof(ofb_buf1), ks, &ofb_tmp, &num);
830*11be35a1SLionel Sambuc 	if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
831*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("ofb64_encrypt decrypt error\n");
832*11be35a1SLionel Sambuc 	}
833*11be35a1SLionel Sambuc }
834*11be35a1SLionel Sambuc #endif /* defined(LIBDES_LIT) */
835*11be35a1SLionel Sambuc 
836*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(ede_ofb64);
837*11be35a1SLionel Sambuc #if defined(LIBDES_LIT)
ATF_TC_BODY(ede_ofb64,tc)838*11be35a1SLionel Sambuc ATF_TC_BODY(ede_ofb64, tc)
839*11be35a1SLionel Sambuc {
840*11be35a1SLionel Sambuc 	atf_tc_skip("Test program built with LIBDES_LIT");
841*11be35a1SLionel Sambuc }
842*11be35a1SLionel Sambuc #else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ede_ofb64,tc)843*11be35a1SLionel Sambuc ATF_TC_BODY(ede_ofb64, tc)
844*11be35a1SLionel Sambuc {
845*11be35a1SLionel Sambuc 	int num;
846*11be35a1SLionel Sambuc 	size_t i;
847*11be35a1SLionel Sambuc 	des_key_schedule ks;
848*11be35a1SLionel Sambuc 
849*11be35a1SLionel Sambuc 	des_set_key_checked(&ofb_key, ks);
850*11be35a1SLionel Sambuc 	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
851*11be35a1SLionel Sambuc 	memset(ofb_buf1, 0, sizeof(ofb_buf1));
852*11be35a1SLionel Sambuc 	memset(ofb_buf2, 0, sizeof(ofb_buf1));
853*11be35a1SLionel Sambuc 	num = 0;
854*11be35a1SLionel Sambuc 	for (i = 0; i < sizeof(plain); i++) {
855*11be35a1SLionel Sambuc 		des_ede3_ofb64_encrypt(&(plain[i]), &(ofb_buf1[i]), 1, ks, ks, ks,
856*11be35a1SLionel Sambuc 				       &ofb_tmp, &num);
857*11be35a1SLionel Sambuc 	}
858*11be35a1SLionel Sambuc 	if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
859*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("ede_ofb64_encrypt encrypt error\n");
860*11be35a1SLionel Sambuc 	}
861*11be35a1SLionel Sambuc 	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
862*11be35a1SLionel Sambuc 	num = 0;
863*11be35a1SLionel Sambuc 	des_ede3_ofb64_encrypt(ofb_buf1, ofb_buf2, sizeof(ofb_buf1), ks,
864*11be35a1SLionel Sambuc 			       ks, ks, &ofb_tmp, &num);
865*11be35a1SLionel Sambuc 	if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
866*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("ede_ofb64_encrypt decrypt error\n");
867*11be35a1SLionel Sambuc 	}
868*11be35a1SLionel Sambuc }
869*11be35a1SLionel Sambuc #endif /* defined(LIBDES_LIT) */
870*11be35a1SLionel Sambuc 
871*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(cbc_cksum);
872*11be35a1SLionel Sambuc #if defined(LIBDES_LIT)
ATF_TC_BODY(cbc_cksum,tc)873*11be35a1SLionel Sambuc ATF_TC_BODY(cbc_cksum, tc)
874*11be35a1SLionel Sambuc {
875*11be35a1SLionel Sambuc 	atf_tc_skip("Test program built with LIBDES_LIT");
876*11be35a1SLionel Sambuc }
877*11be35a1SLionel Sambuc #else /* defined(LIBDES_LIT) */
ATF_TC_BODY(cbc_cksum,tc)878*11be35a1SLionel Sambuc ATF_TC_BODY(cbc_cksum, tc)
879*11be35a1SLionel Sambuc {
880*11be35a1SLionel Sambuc 	unsigned char cret[8];
881*11be35a1SLionel Sambuc 	des_key_schedule ks;
882*11be35a1SLionel Sambuc 	DES_LONG cs;
883*11be35a1SLionel Sambuc 
884*11be35a1SLionel Sambuc 	des_set_key_checked(&cbc_key, ks);
885*11be35a1SLionel Sambuc 	cs = des_cbc_cksum(cbc_data, &cret, strlen((char *) cbc_data), ks, &cbc_iv);
886*11be35a1SLionel Sambuc 	if (cs != cbc_cksum_ret) {
887*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("bad return value (%08lX), should be %08lX\n",
888*11be35a1SLionel Sambuc 		       (unsigned long) cs, (unsigned long) cbc_cksum_ret);
889*11be35a1SLionel Sambuc 	}
890*11be35a1SLionel Sambuc 	if (memcmp(cret, cbc_cksum_data, 8) != 0) {
891*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("bad cbc_cksum block returned\n");
892*11be35a1SLionel Sambuc 	}
893*11be35a1SLionel Sambuc }
894*11be35a1SLionel Sambuc #endif /* defined(LIBDES_LIT) */
895*11be35a1SLionel Sambuc 
896*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(quad_cksum);
897*11be35a1SLionel Sambuc #if defined(LIBDES_LIT)
ATF_TC_BODY(quad_cksum,tc)898*11be35a1SLionel Sambuc ATF_TC_BODY(quad_cksum, tc)
899*11be35a1SLionel Sambuc {
900*11be35a1SLionel Sambuc 	atf_tc_skip("Test program built with LIBDES_LIT");
901*11be35a1SLionel Sambuc }
902*11be35a1SLionel Sambuc #else /* defined(LIBDES_LIT) */
ATF_TC_BODY(quad_cksum,tc)903*11be35a1SLionel Sambuc ATF_TC_BODY(quad_cksum, tc)
904*11be35a1SLionel Sambuc {
905*11be35a1SLionel Sambuc 	DES_LONG cs, lqret[4];
906*11be35a1SLionel Sambuc 
907*11be35a1SLionel Sambuc 	cs = quad_cksum(cbc_data, (des_cblock *) lqret,
908*11be35a1SLionel Sambuc 		(long) strlen((char *) cbc_data), 2, (des_cblock *) cbc_iv);
909*11be35a1SLionel Sambuc 	if (cs != 0x70d7a63aL) {
910*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("quad_cksum error, ret %08lx should be 70d7a63a\n",
911*11be35a1SLionel Sambuc 		       (unsigned long) cs);
912*11be35a1SLionel Sambuc 	}
913*11be35a1SLionel Sambuc 	if (lqret[0] != 0x327eba8dL) {
914*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("quad_cksum error, out[0] %08lx is not %08lx\n",
915*11be35a1SLionel Sambuc 		       (unsigned long) lqret[0], 0x327eba8dUL);
916*11be35a1SLionel Sambuc 	}
917*11be35a1SLionel Sambuc 	if (lqret[1] != 0x201a49ccL) {
918*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("quad_cksum error, out[1] %08lx is not %08lx\n",
919*11be35a1SLionel Sambuc 		       (unsigned long) lqret[1], 0x201a49ccUL);
920*11be35a1SLionel Sambuc 	}
921*11be35a1SLionel Sambuc 	if (lqret[2] != 0x70d7a63aL) {
922*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("quad_cksum error, out[2] %08lx is not %08lx\n",
923*11be35a1SLionel Sambuc 		       (unsigned long) lqret[2], 0x70d7a63aUL);
924*11be35a1SLionel Sambuc 	}
925*11be35a1SLionel Sambuc 	if (lqret[3] != 0x501c2c26L) {
926*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("quad_cksum error, out[3] %08lx is not %08lx\n",
927*11be35a1SLionel Sambuc 		       (unsigned long) lqret[3], 0x501c2c26UL);
928*11be35a1SLionel Sambuc 	}
929*11be35a1SLionel Sambuc }
930*11be35a1SLionel Sambuc #endif /* defined(LIBDES_LIT) */
931*11be35a1SLionel Sambuc 
932*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(align);
ATF_TC_BODY(align,tc)933*11be35a1SLionel Sambuc ATF_TC_BODY(align, tc)
934*11be35a1SLionel Sambuc {
935*11be35a1SLionel Sambuc 	int i;
936*11be35a1SLionel Sambuc 	unsigned char cbc_in[40], cbc_out[40];
937*11be35a1SLionel Sambuc 	des_key_schedule ks;
938*11be35a1SLionel Sambuc 
939*11be35a1SLionel Sambuc 	printf("input word alignment test");
940*11be35a1SLionel Sambuc 	for (i = 0; i < 4; i++) {
941*11be35a1SLionel Sambuc 		printf(" %d", i);
942*11be35a1SLionel Sambuc 		des_ncbc_encrypt(&(cbc_out[i]), cbc_in,
943*11be35a1SLionel Sambuc 				 strlen((char *) cbc_data) + 1, ks,
944*11be35a1SLionel Sambuc 				 &cbc_iv, DES_ENCRYPT);
945*11be35a1SLionel Sambuc 	}
946*11be35a1SLionel Sambuc 
947*11be35a1SLionel Sambuc 	printf("\noutput word alignment test");
948*11be35a1SLionel Sambuc 	for (i = 0; i < 4; i++) {
949*11be35a1SLionel Sambuc 		printf(" %d", i);
950*11be35a1SLionel Sambuc 		des_ncbc_encrypt(cbc_out, &(cbc_in[i]),
951*11be35a1SLionel Sambuc 				 strlen((char *) cbc_data) + 1, ks,
952*11be35a1SLionel Sambuc 				 &cbc_iv, DES_ENCRYPT);
953*11be35a1SLionel Sambuc 	}
954*11be35a1SLionel Sambuc }
955*11be35a1SLionel Sambuc 
956*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(fast_crypt);
ATF_TC_BODY(fast_crypt,tc)957*11be35a1SLionel Sambuc ATF_TC_BODY(fast_crypt, tc)
958*11be35a1SLionel Sambuc {
959*11be35a1SLionel Sambuc 	char *str;
960*11be35a1SLionel Sambuc 
961*11be35a1SLionel Sambuc 	str = crypt("testing", "ef");
962*11be35a1SLionel Sambuc 	if (strcmp("efGnQx2725bI2", str) != 0)
963*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("fast crypt error, %s should be efGnQx2725bI2\n", str);
964*11be35a1SLionel Sambuc 	str = crypt("bca76;23", "yA");
965*11be35a1SLionel Sambuc 	if (strcmp("yA1Rp/1hZXIJk", str) != 0)
966*11be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("fast crypt error, %s should be yA1Rp/1hZXIJk\n", str);
967*11be35a1SLionel Sambuc }
968*11be35a1SLionel Sambuc 
ATF_TP_ADD_TCS(tp)969*11be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
970*11be35a1SLionel Sambuc {
971*11be35a1SLionel Sambuc 
972*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, cbcm);
973*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, ecb);
974*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, ede_ecb);
975*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, cbc);
976*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, desx_cbc);
977*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, ede_cbc);
978*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, pcbc);
979*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, cfb);
980*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, ofb);
981*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, ofb64);
982*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, ede_ofb64);
983*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, cbc_cksum);
984*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, quad_cksum);
985*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, align);
986*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, fast_crypt);
987*11be35a1SLionel Sambuc 
988*11be35a1SLionel Sambuc 	return atf_no_error();
989*11be35a1SLionel Sambuc }
990