10Sstevel@tonic-gate /* crypto/des/destest.c */
20Sstevel@tonic-gate /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
30Sstevel@tonic-gate * All rights reserved.
40Sstevel@tonic-gate *
50Sstevel@tonic-gate * This package is an SSL implementation written
60Sstevel@tonic-gate * by Eric Young (eay@cryptsoft.com).
70Sstevel@tonic-gate * The implementation was written so as to conform with Netscapes SSL.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * This library is free for commercial and non-commercial use as long as
100Sstevel@tonic-gate * the following conditions are aheared to. The following conditions
110Sstevel@tonic-gate * apply to all code found in this distribution, be it the RC4, RSA,
120Sstevel@tonic-gate * lhash, DES, etc., code; not just the SSL code. The SSL documentation
130Sstevel@tonic-gate * included with this distribution is covered by the same copyright terms
140Sstevel@tonic-gate * except that the holder is Tim Hudson (tjh@cryptsoft.com).
150Sstevel@tonic-gate *
160Sstevel@tonic-gate * Copyright remains Eric Young's, and as such any Copyright notices in
170Sstevel@tonic-gate * the code are not to be removed.
180Sstevel@tonic-gate * If this package is used in a product, Eric Young should be given attribution
190Sstevel@tonic-gate * as the author of the parts of the library used.
200Sstevel@tonic-gate * This can be in the form of a textual message at program startup or
210Sstevel@tonic-gate * in documentation (online or textual) provided with the package.
220Sstevel@tonic-gate *
230Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
240Sstevel@tonic-gate * modification, are permitted provided that the following conditions
250Sstevel@tonic-gate * are met:
260Sstevel@tonic-gate * 1. Redistributions of source code must retain the copyright
270Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer.
280Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
290Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the
300Sstevel@tonic-gate * documentation and/or other materials provided with the distribution.
310Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software
320Sstevel@tonic-gate * must display the following acknowledgement:
330Sstevel@tonic-gate * "This product includes cryptographic software written by
340Sstevel@tonic-gate * Eric Young (eay@cryptsoft.com)"
350Sstevel@tonic-gate * The word 'cryptographic' can be left out if the rouines from the library
360Sstevel@tonic-gate * being used are not cryptographic related :-).
370Sstevel@tonic-gate * 4. If you include any Windows specific code (or a derivative thereof) from
380Sstevel@tonic-gate * the apps directory (application code) you must include an acknowledgement:
390Sstevel@tonic-gate * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
400Sstevel@tonic-gate *
410Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
420Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
430Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
440Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
450Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
460Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
470Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
480Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
490Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
500Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
510Sstevel@tonic-gate * SUCH DAMAGE.
520Sstevel@tonic-gate *
530Sstevel@tonic-gate * The licence and distribution terms for any publically available version or
540Sstevel@tonic-gate * derivative of this code cannot be changed. i.e. this code cannot simply be
550Sstevel@tonic-gate * copied and put under another distribution licence
560Sstevel@tonic-gate * [including the GNU Public Licence.]
570Sstevel@tonic-gate */
580Sstevel@tonic-gate
590Sstevel@tonic-gate #include <stdio.h>
600Sstevel@tonic-gate #include <stdlib.h>
610Sstevel@tonic-gate
620Sstevel@tonic-gate #include <openssl/e_os2.h>
630Sstevel@tonic-gate #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_WINDOWS)
640Sstevel@tonic-gate #ifndef OPENSSL_SYS_MSDOS
650Sstevel@tonic-gate #define OPENSSL_SYS_MSDOS
660Sstevel@tonic-gate #endif
670Sstevel@tonic-gate #endif
680Sstevel@tonic-gate
690Sstevel@tonic-gate #ifndef OPENSSL_SYS_MSDOS
700Sstevel@tonic-gate #if !defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_VMS_DECC)
710Sstevel@tonic-gate #include OPENSSL_UNISTD
720Sstevel@tonic-gate #endif
730Sstevel@tonic-gate #else
740Sstevel@tonic-gate #include <io.h>
750Sstevel@tonic-gate #endif
760Sstevel@tonic-gate #include <string.h>
770Sstevel@tonic-gate
780Sstevel@tonic-gate #ifdef OPENSSL_NO_DES
main(int argc,char * argv[])790Sstevel@tonic-gate int main(int argc, char *argv[])
800Sstevel@tonic-gate {
810Sstevel@tonic-gate printf("No DES support\n");
820Sstevel@tonic-gate return(0);
830Sstevel@tonic-gate }
840Sstevel@tonic-gate #else
850Sstevel@tonic-gate #include <openssl/des.h>
860Sstevel@tonic-gate
87*2139Sjp161948 #define crypt(c,s) (DES_crypt((c),(s)))
880Sstevel@tonic-gate
890Sstevel@tonic-gate /* tisk tisk - the test keys don't all have odd parity :-( */
900Sstevel@tonic-gate /* test data */
910Sstevel@tonic-gate #define NUM_TESTS 34
920Sstevel@tonic-gate static unsigned char key_data[NUM_TESTS][8]={
930Sstevel@tonic-gate {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
940Sstevel@tonic-gate {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
950Sstevel@tonic-gate {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
960Sstevel@tonic-gate {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
970Sstevel@tonic-gate {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
980Sstevel@tonic-gate {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
990Sstevel@tonic-gate {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1000Sstevel@tonic-gate {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10},
1010Sstevel@tonic-gate {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57},
1020Sstevel@tonic-gate {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E},
1030Sstevel@tonic-gate {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86},
1040Sstevel@tonic-gate {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E},
1050Sstevel@tonic-gate {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6},
1060Sstevel@tonic-gate {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE},
1070Sstevel@tonic-gate {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6},
1080Sstevel@tonic-gate {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE},
1090Sstevel@tonic-gate {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16},
1100Sstevel@tonic-gate {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F},
1110Sstevel@tonic-gate {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46},
1120Sstevel@tonic-gate {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E},
1130Sstevel@tonic-gate {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76},
1140Sstevel@tonic-gate {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07},
1150Sstevel@tonic-gate {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F},
1160Sstevel@tonic-gate {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7},
1170Sstevel@tonic-gate {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF},
1180Sstevel@tonic-gate {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6},
1190Sstevel@tonic-gate {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF},
1200Sstevel@tonic-gate {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
1210Sstevel@tonic-gate {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
1220Sstevel@tonic-gate {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
1230Sstevel@tonic-gate {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1240Sstevel@tonic-gate {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
1250Sstevel@tonic-gate {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1260Sstevel@tonic-gate {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}};
1270Sstevel@tonic-gate
1280Sstevel@tonic-gate static unsigned char plain_data[NUM_TESTS][8]={
1290Sstevel@tonic-gate {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1300Sstevel@tonic-gate {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
1310Sstevel@tonic-gate {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
1320Sstevel@tonic-gate {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
1330Sstevel@tonic-gate {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
1340Sstevel@tonic-gate {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1350Sstevel@tonic-gate {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1360Sstevel@tonic-gate {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1370Sstevel@tonic-gate {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42},
1380Sstevel@tonic-gate {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA},
1390Sstevel@tonic-gate {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72},
1400Sstevel@tonic-gate {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A},
1410Sstevel@tonic-gate {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2},
1420Sstevel@tonic-gate {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A},
1430Sstevel@tonic-gate {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2},
1440Sstevel@tonic-gate {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A},
1450Sstevel@tonic-gate {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02},
1460Sstevel@tonic-gate {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A},
1470Sstevel@tonic-gate {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32},
1480Sstevel@tonic-gate {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA},
1490Sstevel@tonic-gate {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62},
1500Sstevel@tonic-gate {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2},
1510Sstevel@tonic-gate {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA},
1520Sstevel@tonic-gate {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92},
1530Sstevel@tonic-gate {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A},
1540Sstevel@tonic-gate {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2},
1550Sstevel@tonic-gate {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A},
1560Sstevel@tonic-gate {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1570Sstevel@tonic-gate {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1580Sstevel@tonic-gate {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1590Sstevel@tonic-gate {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
1600Sstevel@tonic-gate {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1610Sstevel@tonic-gate {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1620Sstevel@tonic-gate {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
1630Sstevel@tonic-gate
1640Sstevel@tonic-gate static unsigned char cipher_data[NUM_TESTS][8]={
1650Sstevel@tonic-gate {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
1660Sstevel@tonic-gate {0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58},
1670Sstevel@tonic-gate {0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B},
1680Sstevel@tonic-gate {0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33},
1690Sstevel@tonic-gate {0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D},
1700Sstevel@tonic-gate {0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD},
1710Sstevel@tonic-gate {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
1720Sstevel@tonic-gate {0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4},
1730Sstevel@tonic-gate {0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B},
1740Sstevel@tonic-gate {0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71},
1750Sstevel@tonic-gate {0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A},
1760Sstevel@tonic-gate {0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A},
1770Sstevel@tonic-gate {0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95},
1780Sstevel@tonic-gate {0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B},
1790Sstevel@tonic-gate {0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09},
1800Sstevel@tonic-gate {0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A},
1810Sstevel@tonic-gate {0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F},
1820Sstevel@tonic-gate {0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88},
1830Sstevel@tonic-gate {0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77},
1840Sstevel@tonic-gate {0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A},
1850Sstevel@tonic-gate {0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56},
1860Sstevel@tonic-gate {0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56},
1870Sstevel@tonic-gate {0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56},
1880Sstevel@tonic-gate {0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC},
1890Sstevel@tonic-gate {0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A},
1900Sstevel@tonic-gate {0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41},
1910Sstevel@tonic-gate {0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93},
1920Sstevel@tonic-gate {0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00},
1930Sstevel@tonic-gate {0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06},
1940Sstevel@tonic-gate {0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7},
1950Sstevel@tonic-gate {0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51},
1960Sstevel@tonic-gate {0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE},
1970Sstevel@tonic-gate {0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D},
1980Sstevel@tonic-gate {0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}};
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate static unsigned char cipher_ecb2[NUM_TESTS-1][8]={
2010Sstevel@tonic-gate {0x92,0x95,0xB5,0x9B,0xB3,0x84,0x73,0x6E},
2020Sstevel@tonic-gate {0x19,0x9E,0x9D,0x6D,0xF3,0x9A,0xA8,0x16},
2030Sstevel@tonic-gate {0x2A,0x4B,0x4D,0x24,0x52,0x43,0x84,0x27},
2040Sstevel@tonic-gate {0x35,0x84,0x3C,0x01,0x9D,0x18,0xC5,0xB6},
2050Sstevel@tonic-gate {0x4A,0x5B,0x2F,0x42,0xAA,0x77,0x19,0x25},
2060Sstevel@tonic-gate {0xA0,0x6B,0xA9,0xB8,0xCA,0x5B,0x17,0x8A},
2070Sstevel@tonic-gate {0xAB,0x9D,0xB7,0xFB,0xED,0x95,0xF2,0x74},
2080Sstevel@tonic-gate {0x3D,0x25,0x6C,0x23,0xA7,0x25,0x2F,0xD6},
2090Sstevel@tonic-gate {0xB7,0x6F,0xAB,0x4F,0xBD,0xBD,0xB7,0x67},
2100Sstevel@tonic-gate {0x8F,0x68,0x27,0xD6,0x9C,0xF4,0x1A,0x10},
2110Sstevel@tonic-gate {0x82,0x57,0xA1,0xD6,0x50,0x5E,0x81,0x85},
2120Sstevel@tonic-gate {0xA2,0x0F,0x0A,0xCD,0x80,0x89,0x7D,0xFA},
2130Sstevel@tonic-gate {0xCD,0x2A,0x53,0x3A,0xDB,0x0D,0x7E,0xF3},
2140Sstevel@tonic-gate {0xD2,0xC2,0xBE,0x27,0xE8,0x1B,0x68,0xE3},
2150Sstevel@tonic-gate {0xE9,0x24,0xCF,0x4F,0x89,0x3C,0x5B,0x0A},
2160Sstevel@tonic-gate {0xA7,0x18,0xC3,0x9F,0xFA,0x9F,0xD7,0x69},
2170Sstevel@tonic-gate {0x77,0x2C,0x79,0xB1,0xD2,0x31,0x7E,0xB1},
2180Sstevel@tonic-gate {0x49,0xAB,0x92,0x7F,0xD0,0x22,0x00,0xB7},
2190Sstevel@tonic-gate {0xCE,0x1C,0x6C,0x7D,0x85,0xE3,0x4A,0x6F},
2200Sstevel@tonic-gate {0xBE,0x91,0xD6,0xE1,0x27,0xB2,0xE9,0x87},
2210Sstevel@tonic-gate {0x70,0x28,0xAE,0x8F,0xD1,0xF5,0x74,0x1A},
2220Sstevel@tonic-gate {0xAA,0x37,0x80,0xBB,0xF3,0x22,0x1D,0xDE},
2230Sstevel@tonic-gate {0xA6,0xC4,0xD2,0x5E,0x28,0x93,0xAC,0xB3},
2240Sstevel@tonic-gate {0x22,0x07,0x81,0x5A,0xE4,0xB7,0x1A,0xAD},
2250Sstevel@tonic-gate {0xDC,0xCE,0x05,0xE7,0x07,0xBD,0xF5,0x84},
2260Sstevel@tonic-gate {0x26,0x1D,0x39,0x2C,0xB3,0xBA,0xA5,0x85},
2270Sstevel@tonic-gate {0xB4,0xF7,0x0F,0x72,0xFB,0x04,0xF0,0xDC},
2280Sstevel@tonic-gate {0x95,0xBA,0xA9,0x4E,0x87,0x36,0xF2,0x89},
2290Sstevel@tonic-gate {0xD4,0x07,0x3A,0xF1,0x5A,0x17,0x82,0x0E},
2300Sstevel@tonic-gate {0xEF,0x6F,0xAF,0xA7,0x66,0x1A,0x7E,0x89},
2310Sstevel@tonic-gate {0xC1,0x97,0xF5,0x58,0x74,0x8A,0x20,0xE7},
2320Sstevel@tonic-gate {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8},
2330Sstevel@tonic-gate {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}};
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
2360Sstevel@tonic-gate static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86};
2370Sstevel@tonic-gate static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
2380Sstevel@tonic-gate static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
2390Sstevel@tonic-gate /* Changed the following text constant to binary so it will work on ebcdic
2400Sstevel@tonic-gate * machines :-) */
2410Sstevel@tonic-gate /* static char cbc_data[40]="7654321 Now is the time for \0001"; */
2420Sstevel@tonic-gate static unsigned char cbc_data[40]={
2430Sstevel@tonic-gate 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20,
2440Sstevel@tonic-gate 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74,
2450Sstevel@tonic-gate 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20,
2460Sstevel@tonic-gate 0x66,0x6F,0x72,0x20,0x00,0x31,0x00,0x00,
2470Sstevel@tonic-gate 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2480Sstevel@tonic-gate };
2490Sstevel@tonic-gate
2500Sstevel@tonic-gate static unsigned char cbc_ok[32]={
2510Sstevel@tonic-gate 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
2520Sstevel@tonic-gate 0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb,
2530Sstevel@tonic-gate 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68,
2540Sstevel@tonic-gate 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate #ifdef SCREW_THE_PARITY
2570Sstevel@tonic-gate #error "SCREW_THE_PARITY is not ment to be defined."
2580Sstevel@tonic-gate #error "Original vectors are preserved for reference only."
2590Sstevel@tonic-gate static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
2600Sstevel@tonic-gate static unsigned char xcbc_ok[32]={
2610Sstevel@tonic-gate 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48,
2620Sstevel@tonic-gate 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD,
2630Sstevel@tonic-gate 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76,
2640Sstevel@tonic-gate 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2,
2650Sstevel@tonic-gate };
2660Sstevel@tonic-gate #else
2670Sstevel@tonic-gate static unsigned char xcbc_ok[32]={
2680Sstevel@tonic-gate 0x84,0x6B,0x29,0x14,0x85,0x1E,0x9A,0x29,
2690Sstevel@tonic-gate 0x54,0x73,0x2F,0x8A,0xA0,0xA6,0x11,0xC1,
2700Sstevel@tonic-gate 0x15,0xCD,0xC2,0xD7,0x95,0x1B,0x10,0x53,
2710Sstevel@tonic-gate 0xA6,0x3C,0x5E,0x03,0xB2,0x1A,0xA3,0xC4,
2720Sstevel@tonic-gate };
2730Sstevel@tonic-gate #endif
2740Sstevel@tonic-gate
2750Sstevel@tonic-gate static unsigned char cbc3_ok[32]={
2760Sstevel@tonic-gate 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0,
2770Sstevel@tonic-gate 0x22,0x13,0x76,0x3C,0x1C,0xBD,0x4C,0xDC,
2780Sstevel@tonic-gate 0x79,0x96,0x57,0xC0,0x64,0xEC,0xF5,0xD4,
2790Sstevel@tonic-gate 0x1C,0x67,0x38,0x12,0xCF,0xDE,0x96,0x75};
2800Sstevel@tonic-gate
2810Sstevel@tonic-gate static unsigned char pcbc_ok[32]={
2820Sstevel@tonic-gate 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
2830Sstevel@tonic-gate 0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15,
2840Sstevel@tonic-gate 0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f,
2850Sstevel@tonic-gate 0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88};
2860Sstevel@tonic-gate
2870Sstevel@tonic-gate static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
2880Sstevel@tonic-gate static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
2890Sstevel@tonic-gate static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
2900Sstevel@tonic-gate static unsigned char plain[24]=
2910Sstevel@tonic-gate {
2920Sstevel@tonic-gate 0x4e,0x6f,0x77,0x20,0x69,0x73,
2930Sstevel@tonic-gate 0x20,0x74,0x68,0x65,0x20,0x74,
2940Sstevel@tonic-gate 0x69,0x6d,0x65,0x20,0x66,0x6f,
2950Sstevel@tonic-gate 0x72,0x20,0x61,0x6c,0x6c,0x20
2960Sstevel@tonic-gate };
2970Sstevel@tonic-gate static unsigned char cfb_cipher8[24]= {
2980Sstevel@tonic-gate 0xf3,0x1f,0xda,0x07,0x01,0x14, 0x62,0xee,0x18,0x7f,0x43,0xd8,
2990Sstevel@tonic-gate 0x0a,0x7c,0xd9,0xb5,0xb0,0xd2, 0x90,0xda,0x6e,0x5b,0x9a,0x87 };
3000Sstevel@tonic-gate static unsigned char cfb_cipher16[24]={
3010Sstevel@tonic-gate 0xF3,0x09,0x87,0x87,0x7F,0x57, 0xF7,0x3C,0x36,0xB6,0xDB,0x70,
3020Sstevel@tonic-gate 0xD8,0xD5,0x34,0x19,0xD3,0x86, 0xB2,0x23,0xB7,0xB2,0xAD,0x1B };
3030Sstevel@tonic-gate static unsigned char cfb_cipher32[24]={
3040Sstevel@tonic-gate 0xF3,0x09,0x62,0x49,0xA4,0xDF, 0xA4,0x9F,0x33,0xDC,0x7B,0xAD,
3050Sstevel@tonic-gate 0x4C,0xC8,0x9F,0x64,0xE4,0x53, 0xE5,0xEC,0x67,0x20,0xDA,0xB6 };
3060Sstevel@tonic-gate static unsigned char cfb_cipher48[24]={
3070Sstevel@tonic-gate 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x30,0xB5,0x15,0xEC,0xBB,0x85,
3080Sstevel@tonic-gate 0x97,0x5A,0x13,0x8C,0x68,0x60, 0xE2,0x38,0x34,0x3C,0xDC,0x1F };
3090Sstevel@tonic-gate static unsigned char cfb_cipher64[24]={
3100Sstevel@tonic-gate 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x6E,0x51,0xA6,0x9E,0x83,0x9B,
3110Sstevel@tonic-gate 0x1A,0x92,0xF7,0x84,0x03,0x46, 0x71,0x33,0x89,0x8E,0xA6,0x22 };
3120Sstevel@tonic-gate
3130Sstevel@tonic-gate static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
3140Sstevel@tonic-gate static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
3150Sstevel@tonic-gate static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8];
3160Sstevel@tonic-gate static unsigned char ofb_cipher[24]=
3170Sstevel@tonic-gate {
3180Sstevel@tonic-gate 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
3190Sstevel@tonic-gate 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
3200Sstevel@tonic-gate 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3
3210Sstevel@tonic-gate };
3220Sstevel@tonic-gate
3230Sstevel@tonic-gate #if 0
3240Sstevel@tonic-gate static DES_LONG cbc_cksum_ret=0xB462FEF7L;
3250Sstevel@tonic-gate #else
3260Sstevel@tonic-gate static DES_LONG cbc_cksum_ret=0xF7FE62B4L;
3270Sstevel@tonic-gate #endif
3280Sstevel@tonic-gate static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
3290Sstevel@tonic-gate
3300Sstevel@tonic-gate static char *pt(unsigned char *p);
3310Sstevel@tonic-gate static int cfb_test(int bits, unsigned char *cfb_cipher);
3320Sstevel@tonic-gate static int cfb64_test(unsigned char *cfb_cipher);
3330Sstevel@tonic-gate static int ede_cfb64_test(unsigned char *cfb_cipher);
main(int argc,char * argv[])3340Sstevel@tonic-gate int main(int argc, char *argv[])
3350Sstevel@tonic-gate {
336*2139Sjp161948 int j,err=0;
337*2139Sjp161948 unsigned int i;
3380Sstevel@tonic-gate des_cblock in,out,outin,iv3,iv2;
3390Sstevel@tonic-gate des_key_schedule ks,ks2,ks3;
3400Sstevel@tonic-gate unsigned char cbc_in[40];
3410Sstevel@tonic-gate unsigned char cbc_out[40];
3420Sstevel@tonic-gate DES_LONG cs;
3430Sstevel@tonic-gate unsigned char cret[8];
3440Sstevel@tonic-gate #ifdef _CRAY
3450Sstevel@tonic-gate struct {
3460Sstevel@tonic-gate int a:32;
3470Sstevel@tonic-gate int b:32;
3480Sstevel@tonic-gate } lqret[2];
3490Sstevel@tonic-gate #else
3500Sstevel@tonic-gate DES_LONG lqret[4];
3510Sstevel@tonic-gate #endif
3520Sstevel@tonic-gate int num;
3530Sstevel@tonic-gate char *str;
3540Sstevel@tonic-gate
3550Sstevel@tonic-gate #ifndef OPENSSL_NO_DESCBCM
3560Sstevel@tonic-gate printf("Doing cbcm\n");
3570Sstevel@tonic-gate if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
3580Sstevel@tonic-gate {
3590Sstevel@tonic-gate printf("Key error %d\n",j);
3600Sstevel@tonic-gate err=1;
3610Sstevel@tonic-gate }
3620Sstevel@tonic-gate if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0)
3630Sstevel@tonic-gate {
3640Sstevel@tonic-gate printf("Key error %d\n",j);
3650Sstevel@tonic-gate err=1;
3660Sstevel@tonic-gate }
3670Sstevel@tonic-gate if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0)
3680Sstevel@tonic-gate {
3690Sstevel@tonic-gate printf("Key error %d\n",j);
3700Sstevel@tonic-gate err=1;
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate memset(cbc_out,0,40);
3730Sstevel@tonic-gate memset(cbc_in,0,40);
3740Sstevel@tonic-gate i=strlen((char *)cbc_data)+1;
3750Sstevel@tonic-gate /* i=((i+7)/8)*8; */
3760Sstevel@tonic-gate memcpy(iv3,cbc_iv,sizeof(cbc_iv));
3770Sstevel@tonic-gate memset(iv2,'\0',sizeof iv2);
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate DES_ede3_cbcm_encrypt(cbc_data,cbc_out,16L,&ks,&ks2,&ks3,&iv3,&iv2,
3800Sstevel@tonic-gate DES_ENCRYPT);
3810Sstevel@tonic-gate DES_ede3_cbcm_encrypt(&cbc_data[16],&cbc_out[16],i-16,&ks,&ks2,&ks3,
3820Sstevel@tonic-gate &iv3,&iv2,DES_ENCRYPT);
3830Sstevel@tonic-gate /* if (memcmp(cbc_out,cbc3_ok,
3840Sstevel@tonic-gate (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
3850Sstevel@tonic-gate {
3860Sstevel@tonic-gate printf("des_ede3_cbc_encrypt encrypt error\n");
3870Sstevel@tonic-gate err=1;
3880Sstevel@tonic-gate }
3890Sstevel@tonic-gate */
3900Sstevel@tonic-gate memcpy(iv3,cbc_iv,sizeof(cbc_iv));
3910Sstevel@tonic-gate memset(iv2,'\0',sizeof iv2);
3920Sstevel@tonic-gate DES_ede3_cbcm_encrypt(cbc_out,cbc_in,i,&ks,&ks2,&ks3,&iv3,&iv2,DES_DECRYPT);
3930Sstevel@tonic-gate if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
3940Sstevel@tonic-gate {
395*2139Sjp161948 unsigned int n;
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate printf("des_ede3_cbcm_encrypt decrypt error\n");
3980Sstevel@tonic-gate for(n=0 ; n < i ; ++n)
3990Sstevel@tonic-gate printf(" %02x",cbc_data[n]);
4000Sstevel@tonic-gate printf("\n");
4010Sstevel@tonic-gate for(n=0 ; n < i ; ++n)
4020Sstevel@tonic-gate printf(" %02x",cbc_in[n]);
4030Sstevel@tonic-gate printf("\n");
4040Sstevel@tonic-gate err=1;
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate #endif
4070Sstevel@tonic-gate
4080Sstevel@tonic-gate printf("Doing ecb\n");
4090Sstevel@tonic-gate for (i=0; i<NUM_TESTS; i++)
4100Sstevel@tonic-gate {
4110Sstevel@tonic-gate DES_set_key_unchecked(&key_data[i],&ks);
4120Sstevel@tonic-gate memcpy(in,plain_data[i],8);
4130Sstevel@tonic-gate memset(out,0,8);
4140Sstevel@tonic-gate memset(outin,0,8);
4150Sstevel@tonic-gate des_ecb_encrypt(&in,&out,ks,DES_ENCRYPT);
4160Sstevel@tonic-gate des_ecb_encrypt(&out,&outin,ks,DES_DECRYPT);
4170Sstevel@tonic-gate
4180Sstevel@tonic-gate if (memcmp(out,cipher_data[i],8) != 0)
4190Sstevel@tonic-gate {
4200Sstevel@tonic-gate printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
4210Sstevel@tonic-gate i+1,pt(key_data[i]),pt(in),pt(cipher_data[i]),
4220Sstevel@tonic-gate pt(out));
4230Sstevel@tonic-gate err=1;
4240Sstevel@tonic-gate }
4250Sstevel@tonic-gate if (memcmp(in,outin,8) != 0)
4260Sstevel@tonic-gate {
4270Sstevel@tonic-gate printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
4280Sstevel@tonic-gate i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
4290Sstevel@tonic-gate err=1;
4300Sstevel@tonic-gate }
4310Sstevel@tonic-gate }
4320Sstevel@tonic-gate
4330Sstevel@tonic-gate #ifndef LIBDES_LIT
4340Sstevel@tonic-gate printf("Doing ede ecb\n");
4350Sstevel@tonic-gate for (i=0; i<(NUM_TESTS-2); i++)
4360Sstevel@tonic-gate {
4370Sstevel@tonic-gate DES_set_key_unchecked(&key_data[i],&ks);
4380Sstevel@tonic-gate DES_set_key_unchecked(&key_data[i+1],&ks2);
4390Sstevel@tonic-gate DES_set_key_unchecked(&key_data[i+2],&ks3);
4400Sstevel@tonic-gate memcpy(in,plain_data[i],8);
4410Sstevel@tonic-gate memset(out,0,8);
4420Sstevel@tonic-gate memset(outin,0,8);
4430Sstevel@tonic-gate des_ecb2_encrypt(&in,&out,ks,ks2,DES_ENCRYPT);
4440Sstevel@tonic-gate des_ecb2_encrypt(&out,&outin,ks,ks2,DES_DECRYPT);
4450Sstevel@tonic-gate
4460Sstevel@tonic-gate if (memcmp(out,cipher_ecb2[i],8) != 0)
4470Sstevel@tonic-gate {
4480Sstevel@tonic-gate printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
4490Sstevel@tonic-gate i+1,pt(key_data[i]),pt(in),pt(cipher_ecb2[i]),
4500Sstevel@tonic-gate pt(out));
4510Sstevel@tonic-gate err=1;
4520Sstevel@tonic-gate }
4530Sstevel@tonic-gate if (memcmp(in,outin,8) != 0)
4540Sstevel@tonic-gate {
4550Sstevel@tonic-gate printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
4560Sstevel@tonic-gate i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
4570Sstevel@tonic-gate err=1;
4580Sstevel@tonic-gate }
4590Sstevel@tonic-gate }
4600Sstevel@tonic-gate #endif
4610Sstevel@tonic-gate
4620Sstevel@tonic-gate printf("Doing cbc\n");
4630Sstevel@tonic-gate if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
4640Sstevel@tonic-gate {
4650Sstevel@tonic-gate printf("Key error %d\n",j);
4660Sstevel@tonic-gate err=1;
4670Sstevel@tonic-gate }
4680Sstevel@tonic-gate memset(cbc_out,0,40);
4690Sstevel@tonic-gate memset(cbc_in,0,40);
4700Sstevel@tonic-gate memcpy(iv3,cbc_iv,sizeof(cbc_iv));
4710Sstevel@tonic-gate des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
4720Sstevel@tonic-gate &iv3,DES_ENCRYPT);
4730Sstevel@tonic-gate if (memcmp(cbc_out,cbc_ok,32) != 0)
4740Sstevel@tonic-gate {
4750Sstevel@tonic-gate printf("cbc_encrypt encrypt error\n");
4760Sstevel@tonic-gate err=1;
4770Sstevel@tonic-gate }
4780Sstevel@tonic-gate
4790Sstevel@tonic-gate memcpy(iv3,cbc_iv,sizeof(cbc_iv));
4800Sstevel@tonic-gate des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
4810Sstevel@tonic-gate &iv3,DES_DECRYPT);
4820Sstevel@tonic-gate if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0)
4830Sstevel@tonic-gate {
4840Sstevel@tonic-gate printf("cbc_encrypt decrypt error\n");
4850Sstevel@tonic-gate err=1;
4860Sstevel@tonic-gate }
4870Sstevel@tonic-gate
4880Sstevel@tonic-gate #ifndef LIBDES_LIT
4890Sstevel@tonic-gate printf("Doing desx cbc\n");
4900Sstevel@tonic-gate if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
4910Sstevel@tonic-gate {
4920Sstevel@tonic-gate printf("Key error %d\n",j);
4930Sstevel@tonic-gate err=1;
4940Sstevel@tonic-gate }
4950Sstevel@tonic-gate memset(cbc_out,0,40);
4960Sstevel@tonic-gate memset(cbc_in,0,40);
4970Sstevel@tonic-gate memcpy(iv3,cbc_iv,sizeof(cbc_iv));
4980Sstevel@tonic-gate des_xcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
4990Sstevel@tonic-gate &iv3,&cbc2_key,&cbc3_key, DES_ENCRYPT);
5000Sstevel@tonic-gate if (memcmp(cbc_out,xcbc_ok,32) != 0)
5010Sstevel@tonic-gate {
5020Sstevel@tonic-gate printf("des_xcbc_encrypt encrypt error\n");
5030Sstevel@tonic-gate err=1;
5040Sstevel@tonic-gate }
5050Sstevel@tonic-gate memcpy(iv3,cbc_iv,sizeof(cbc_iv));
5060Sstevel@tonic-gate des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
5070Sstevel@tonic-gate &iv3,&cbc2_key,&cbc3_key, DES_DECRYPT);
5080Sstevel@tonic-gate if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
5090Sstevel@tonic-gate {
5100Sstevel@tonic-gate printf("des_xcbc_encrypt decrypt error\n");
5110Sstevel@tonic-gate err=1;
5120Sstevel@tonic-gate }
5130Sstevel@tonic-gate #endif
5140Sstevel@tonic-gate
5150Sstevel@tonic-gate printf("Doing ede cbc\n");
5160Sstevel@tonic-gate if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
5170Sstevel@tonic-gate {
5180Sstevel@tonic-gate printf("Key error %d\n",j);
5190Sstevel@tonic-gate err=1;
5200Sstevel@tonic-gate }
5210Sstevel@tonic-gate if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0)
5220Sstevel@tonic-gate {
5230Sstevel@tonic-gate printf("Key error %d\n",j);
5240Sstevel@tonic-gate err=1;
5250Sstevel@tonic-gate }
5260Sstevel@tonic-gate if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0)
5270Sstevel@tonic-gate {
5280Sstevel@tonic-gate printf("Key error %d\n",j);
5290Sstevel@tonic-gate err=1;
5300Sstevel@tonic-gate }
5310Sstevel@tonic-gate memset(cbc_out,0,40);
5320Sstevel@tonic-gate memset(cbc_in,0,40);
5330Sstevel@tonic-gate i=strlen((char *)cbc_data)+1;
5340Sstevel@tonic-gate /* i=((i+7)/8)*8; */
5350Sstevel@tonic-gate memcpy(iv3,cbc_iv,sizeof(cbc_iv));
5360Sstevel@tonic-gate
5370Sstevel@tonic-gate des_ede3_cbc_encrypt(cbc_data,cbc_out,16L,ks,ks2,ks3,&iv3,
5380Sstevel@tonic-gate DES_ENCRYPT);
5390Sstevel@tonic-gate des_ede3_cbc_encrypt(&(cbc_data[16]),&(cbc_out[16]),i-16,ks,ks2,ks3,
5400Sstevel@tonic-gate &iv3,DES_ENCRYPT);
5410Sstevel@tonic-gate if (memcmp(cbc_out,cbc3_ok,
5420Sstevel@tonic-gate (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
5430Sstevel@tonic-gate {
544*2139Sjp161948 unsigned int n;
5450Sstevel@tonic-gate
5460Sstevel@tonic-gate printf("des_ede3_cbc_encrypt encrypt error\n");
5470Sstevel@tonic-gate for(n=0 ; n < i ; ++n)
5480Sstevel@tonic-gate printf(" %02x",cbc_out[n]);
5490Sstevel@tonic-gate printf("\n");
5500Sstevel@tonic-gate for(n=0 ; n < i ; ++n)
5510Sstevel@tonic-gate printf(" %02x",cbc3_ok[n]);
5520Sstevel@tonic-gate printf("\n");
5530Sstevel@tonic-gate err=1;
5540Sstevel@tonic-gate }
5550Sstevel@tonic-gate
5560Sstevel@tonic-gate memcpy(iv3,cbc_iv,sizeof(cbc_iv));
5570Sstevel@tonic-gate des_ede3_cbc_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,&iv3,DES_DECRYPT);
5580Sstevel@tonic-gate if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
5590Sstevel@tonic-gate {
560*2139Sjp161948 unsigned int n;
5610Sstevel@tonic-gate
5620Sstevel@tonic-gate printf("des_ede3_cbc_encrypt decrypt error\n");
5630Sstevel@tonic-gate for(n=0 ; n < i ; ++n)
5640Sstevel@tonic-gate printf(" %02x",cbc_data[n]);
5650Sstevel@tonic-gate printf("\n");
5660Sstevel@tonic-gate for(n=0 ; n < i ; ++n)
5670Sstevel@tonic-gate printf(" %02x",cbc_in[n]);
5680Sstevel@tonic-gate printf("\n");
5690Sstevel@tonic-gate err=1;
5700Sstevel@tonic-gate }
5710Sstevel@tonic-gate
5720Sstevel@tonic-gate #ifndef LIBDES_LIT
5730Sstevel@tonic-gate printf("Doing pcbc\n");
5740Sstevel@tonic-gate if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
5750Sstevel@tonic-gate {
5760Sstevel@tonic-gate printf("Key error %d\n",j);
5770Sstevel@tonic-gate err=1;
5780Sstevel@tonic-gate }
5790Sstevel@tonic-gate memset(cbc_out,0,40);
5800Sstevel@tonic-gate memset(cbc_in,0,40);
5810Sstevel@tonic-gate des_pcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
5820Sstevel@tonic-gate &cbc_iv,DES_ENCRYPT);
5830Sstevel@tonic-gate if (memcmp(cbc_out,pcbc_ok,32) != 0)
5840Sstevel@tonic-gate {
5850Sstevel@tonic-gate printf("pcbc_encrypt encrypt error\n");
5860Sstevel@tonic-gate err=1;
5870Sstevel@tonic-gate }
5880Sstevel@tonic-gate des_pcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,&cbc_iv,
5890Sstevel@tonic-gate DES_DECRYPT);
5900Sstevel@tonic-gate if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
5910Sstevel@tonic-gate {
5920Sstevel@tonic-gate printf("pcbc_encrypt decrypt error\n");
5930Sstevel@tonic-gate err=1;
5940Sstevel@tonic-gate }
5950Sstevel@tonic-gate
5960Sstevel@tonic-gate printf("Doing ");
5970Sstevel@tonic-gate printf("cfb8 ");
5980Sstevel@tonic-gate err+=cfb_test(8,cfb_cipher8);
5990Sstevel@tonic-gate printf("cfb16 ");
6000Sstevel@tonic-gate err+=cfb_test(16,cfb_cipher16);
6010Sstevel@tonic-gate printf("cfb32 ");
6020Sstevel@tonic-gate err+=cfb_test(32,cfb_cipher32);
6030Sstevel@tonic-gate printf("cfb48 ");
6040Sstevel@tonic-gate err+=cfb_test(48,cfb_cipher48);
6050Sstevel@tonic-gate printf("cfb64 ");
6060Sstevel@tonic-gate err+=cfb_test(64,cfb_cipher64);
6070Sstevel@tonic-gate
6080Sstevel@tonic-gate printf("cfb64() ");
6090Sstevel@tonic-gate err+=cfb64_test(cfb_cipher64);
6100Sstevel@tonic-gate
6110Sstevel@tonic-gate memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
6120Sstevel@tonic-gate for (i=0; i<sizeof(plain); i++)
6130Sstevel@tonic-gate des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]),
6140Sstevel@tonic-gate 8,1,ks,&cfb_tmp,DES_ENCRYPT);
6150Sstevel@tonic-gate if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0)
6160Sstevel@tonic-gate {
6170Sstevel@tonic-gate printf("cfb_encrypt small encrypt error\n");
6180Sstevel@tonic-gate err=1;
6190Sstevel@tonic-gate }
6200Sstevel@tonic-gate
6210Sstevel@tonic-gate memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
6220Sstevel@tonic-gate for (i=0; i<sizeof(plain); i++)
6230Sstevel@tonic-gate des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]),
6240Sstevel@tonic-gate 8,1,ks,&cfb_tmp,DES_DECRYPT);
6250Sstevel@tonic-gate if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
6260Sstevel@tonic-gate {
6270Sstevel@tonic-gate printf("cfb_encrypt small decrypt error\n");
6280Sstevel@tonic-gate err=1;
6290Sstevel@tonic-gate }
6300Sstevel@tonic-gate
6310Sstevel@tonic-gate printf("ede_cfb64() ");
6320Sstevel@tonic-gate err+=ede_cfb64_test(cfb_cipher64);
6330Sstevel@tonic-gate
6340Sstevel@tonic-gate printf("done\n");
6350Sstevel@tonic-gate
6360Sstevel@tonic-gate printf("Doing ofb\n");
6370Sstevel@tonic-gate DES_set_key_checked(&ofb_key,&ks);
6380Sstevel@tonic-gate memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
6390Sstevel@tonic-gate des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp);
6400Sstevel@tonic-gate if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
6410Sstevel@tonic-gate {
6420Sstevel@tonic-gate printf("ofb_encrypt encrypt error\n");
6430Sstevel@tonic-gate printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
6440Sstevel@tonic-gate ofb_buf1[8+0], ofb_buf1[8+1], ofb_buf1[8+2], ofb_buf1[8+3],
6450Sstevel@tonic-gate ofb_buf1[8+4], ofb_buf1[8+5], ofb_buf1[8+6], ofb_buf1[8+7]);
6460Sstevel@tonic-gate printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
6470Sstevel@tonic-gate ofb_buf1[8+0], ofb_cipher[8+1], ofb_cipher[8+2], ofb_cipher[8+3],
6480Sstevel@tonic-gate ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]);
6490Sstevel@tonic-gate err=1;
6500Sstevel@tonic-gate }
6510Sstevel@tonic-gate memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
6520Sstevel@tonic-gate des_ofb_encrypt(ofb_buf1,ofb_buf2,64,sizeof(ofb_buf1)/8,ks,&ofb_tmp);
6530Sstevel@tonic-gate if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
6540Sstevel@tonic-gate {
6550Sstevel@tonic-gate printf("ofb_encrypt decrypt error\n");
6560Sstevel@tonic-gate printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
6570Sstevel@tonic-gate ofb_buf2[8+0], ofb_buf2[8+1], ofb_buf2[8+2], ofb_buf2[8+3],
6580Sstevel@tonic-gate ofb_buf2[8+4], ofb_buf2[8+5], ofb_buf2[8+6], ofb_buf2[8+7]);
6590Sstevel@tonic-gate printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
6600Sstevel@tonic-gate plain[8+0], plain[8+1], plain[8+2], plain[8+3],
6610Sstevel@tonic-gate plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
6620Sstevel@tonic-gate err=1;
6630Sstevel@tonic-gate }
6640Sstevel@tonic-gate
6650Sstevel@tonic-gate printf("Doing ofb64\n");
6660Sstevel@tonic-gate DES_set_key_checked(&ofb_key,&ks);
6670Sstevel@tonic-gate memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
6680Sstevel@tonic-gate memset(ofb_buf1,0,sizeof(ofb_buf1));
6690Sstevel@tonic-gate memset(ofb_buf2,0,sizeof(ofb_buf1));
6700Sstevel@tonic-gate num=0;
6710Sstevel@tonic-gate for (i=0; i<sizeof(plain); i++)
6720Sstevel@tonic-gate {
6730Sstevel@tonic-gate des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,&ofb_tmp,
6740Sstevel@tonic-gate &num);
6750Sstevel@tonic-gate }
6760Sstevel@tonic-gate if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
6770Sstevel@tonic-gate {
6780Sstevel@tonic-gate printf("ofb64_encrypt encrypt error\n");
6790Sstevel@tonic-gate err=1;
6800Sstevel@tonic-gate }
6810Sstevel@tonic-gate memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
6820Sstevel@tonic-gate num=0;
6830Sstevel@tonic-gate des_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,&ofb_tmp,
6840Sstevel@tonic-gate &num);
6850Sstevel@tonic-gate if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
6860Sstevel@tonic-gate {
6870Sstevel@tonic-gate printf("ofb64_encrypt decrypt error\n");
6880Sstevel@tonic-gate err=1;
6890Sstevel@tonic-gate }
6900Sstevel@tonic-gate
6910Sstevel@tonic-gate printf("Doing ede_ofb64\n");
6920Sstevel@tonic-gate DES_set_key_checked(&ofb_key,&ks);
6930Sstevel@tonic-gate memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
6940Sstevel@tonic-gate memset(ofb_buf1,0,sizeof(ofb_buf1));
6950Sstevel@tonic-gate memset(ofb_buf2,0,sizeof(ofb_buf1));
6960Sstevel@tonic-gate num=0;
6970Sstevel@tonic-gate for (i=0; i<sizeof(plain); i++)
6980Sstevel@tonic-gate {
6990Sstevel@tonic-gate des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,
7000Sstevel@tonic-gate ks,&ofb_tmp,&num);
7010Sstevel@tonic-gate }
7020Sstevel@tonic-gate if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
7030Sstevel@tonic-gate {
7040Sstevel@tonic-gate printf("ede_ofb64_encrypt encrypt error\n");
7050Sstevel@tonic-gate err=1;
7060Sstevel@tonic-gate }
7070Sstevel@tonic-gate memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
7080Sstevel@tonic-gate num=0;
7090Sstevel@tonic-gate des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,ks,ks,
7100Sstevel@tonic-gate &ofb_tmp,&num);
7110Sstevel@tonic-gate if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
7120Sstevel@tonic-gate {
7130Sstevel@tonic-gate printf("ede_ofb64_encrypt decrypt error\n");
7140Sstevel@tonic-gate err=1;
7150Sstevel@tonic-gate }
7160Sstevel@tonic-gate
7170Sstevel@tonic-gate printf("Doing cbc_cksum\n");
7180Sstevel@tonic-gate DES_set_key_checked(&cbc_key,&ks);
7190Sstevel@tonic-gate cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv);
7200Sstevel@tonic-gate if (cs != cbc_cksum_ret)
7210Sstevel@tonic-gate {
7220Sstevel@tonic-gate printf("bad return value (%08lX), should be %08lX\n",
7230Sstevel@tonic-gate (unsigned long)cs,(unsigned long)cbc_cksum_ret);
7240Sstevel@tonic-gate err=1;
7250Sstevel@tonic-gate }
7260Sstevel@tonic-gate if (memcmp(cret,cbc_cksum_data,8) != 0)
7270Sstevel@tonic-gate {
7280Sstevel@tonic-gate printf("bad cbc_cksum block returned\n");
7290Sstevel@tonic-gate err=1;
7300Sstevel@tonic-gate }
7310Sstevel@tonic-gate
7320Sstevel@tonic-gate printf("Doing quad_cksum\n");
7330Sstevel@tonic-gate cs=des_quad_cksum(cbc_data,(des_cblock *)lqret,
7340Sstevel@tonic-gate (long)strlen((char *)cbc_data),2,(des_cblock *)cbc_iv);
7350Sstevel@tonic-gate if (cs != 0x70d7a63aL)
7360Sstevel@tonic-gate {
7370Sstevel@tonic-gate printf("quad_cksum error, ret %08lx should be 70d7a63a\n",
7380Sstevel@tonic-gate (unsigned long)cs);
7390Sstevel@tonic-gate err=1;
7400Sstevel@tonic-gate }
7410Sstevel@tonic-gate #ifdef _CRAY
7420Sstevel@tonic-gate if (lqret[0].a != 0x327eba8dL)
7430Sstevel@tonic-gate {
7440Sstevel@tonic-gate printf("quad_cksum error, out[0] %08lx is not %08lx\n",
7450Sstevel@tonic-gate (unsigned long)lqret[0].a,0x327eba8dUL);
7460Sstevel@tonic-gate err=1;
7470Sstevel@tonic-gate }
7480Sstevel@tonic-gate if (lqret[0].b != 0x201a49ccL)
7490Sstevel@tonic-gate {
7500Sstevel@tonic-gate printf("quad_cksum error, out[1] %08lx is not %08lx\n",
7510Sstevel@tonic-gate (unsigned long)lqret[0].b,0x201a49ccUL);
7520Sstevel@tonic-gate err=1;
7530Sstevel@tonic-gate }
7540Sstevel@tonic-gate if (lqret[1].a != 0x70d7a63aL)
7550Sstevel@tonic-gate {
7560Sstevel@tonic-gate printf("quad_cksum error, out[2] %08lx is not %08lx\n",
7570Sstevel@tonic-gate (unsigned long)lqret[1].a,0x70d7a63aUL);
7580Sstevel@tonic-gate err=1;
7590Sstevel@tonic-gate }
7600Sstevel@tonic-gate if (lqret[1].b != 0x501c2c26L)
7610Sstevel@tonic-gate {
7620Sstevel@tonic-gate printf("quad_cksum error, out[3] %08lx is not %08lx\n",
7630Sstevel@tonic-gate (unsigned long)lqret[1].b,0x501c2c26UL);
7640Sstevel@tonic-gate err=1;
7650Sstevel@tonic-gate }
7660Sstevel@tonic-gate #else
7670Sstevel@tonic-gate if (lqret[0] != 0x327eba8dL)
7680Sstevel@tonic-gate {
7690Sstevel@tonic-gate printf("quad_cksum error, out[0] %08lx is not %08lx\n",
7700Sstevel@tonic-gate (unsigned long)lqret[0],0x327eba8dUL);
7710Sstevel@tonic-gate err=1;
7720Sstevel@tonic-gate }
7730Sstevel@tonic-gate if (lqret[1] != 0x201a49ccL)
7740Sstevel@tonic-gate {
7750Sstevel@tonic-gate printf("quad_cksum error, out[1] %08lx is not %08lx\n",
7760Sstevel@tonic-gate (unsigned long)lqret[1],0x201a49ccUL);
7770Sstevel@tonic-gate err=1;
7780Sstevel@tonic-gate }
7790Sstevel@tonic-gate if (lqret[2] != 0x70d7a63aL)
7800Sstevel@tonic-gate {
7810Sstevel@tonic-gate printf("quad_cksum error, out[2] %08lx is not %08lx\n",
7820Sstevel@tonic-gate (unsigned long)lqret[2],0x70d7a63aUL);
7830Sstevel@tonic-gate err=1;
7840Sstevel@tonic-gate }
7850Sstevel@tonic-gate if (lqret[3] != 0x501c2c26L)
7860Sstevel@tonic-gate {
7870Sstevel@tonic-gate printf("quad_cksum error, out[3] %08lx is not %08lx\n",
7880Sstevel@tonic-gate (unsigned long)lqret[3],0x501c2c26UL);
7890Sstevel@tonic-gate err=1;
7900Sstevel@tonic-gate }
7910Sstevel@tonic-gate #endif
7920Sstevel@tonic-gate #endif
7930Sstevel@tonic-gate
7940Sstevel@tonic-gate printf("input word alignment test");
7950Sstevel@tonic-gate for (i=0; i<4; i++)
7960Sstevel@tonic-gate {
7970Sstevel@tonic-gate printf(" %d",i);
7980Sstevel@tonic-gate des_ncbc_encrypt(&(cbc_out[i]),cbc_in,
7990Sstevel@tonic-gate strlen((char *)cbc_data)+1,ks,
8000Sstevel@tonic-gate &cbc_iv,DES_ENCRYPT);
8010Sstevel@tonic-gate }
8020Sstevel@tonic-gate printf("\noutput word alignment test");
8030Sstevel@tonic-gate for (i=0; i<4; i++)
8040Sstevel@tonic-gate {
8050Sstevel@tonic-gate printf(" %d",i);
8060Sstevel@tonic-gate des_ncbc_encrypt(cbc_out,&(cbc_in[i]),
8070Sstevel@tonic-gate strlen((char *)cbc_data)+1,ks,
8080Sstevel@tonic-gate &cbc_iv,DES_ENCRYPT);
8090Sstevel@tonic-gate }
8100Sstevel@tonic-gate printf("\n");
8110Sstevel@tonic-gate printf("fast crypt test ");
8120Sstevel@tonic-gate str=crypt("testing","ef");
8130Sstevel@tonic-gate if (strcmp("efGnQx2725bI2",str) != 0)
8140Sstevel@tonic-gate {
8150Sstevel@tonic-gate printf("fast crypt error, %s should be efGnQx2725bI2\n",str);
8160Sstevel@tonic-gate err=1;
8170Sstevel@tonic-gate }
8180Sstevel@tonic-gate str=crypt("bca76;23","yA");
8190Sstevel@tonic-gate if (strcmp("yA1Rp/1hZXIJk",str) != 0)
8200Sstevel@tonic-gate {
8210Sstevel@tonic-gate printf("fast crypt error, %s should be yA1Rp/1hZXIJk\n",str);
8220Sstevel@tonic-gate err=1;
8230Sstevel@tonic-gate }
824*2139Sjp161948 #ifdef OPENSSL_SYS_NETWARE
825*2139Sjp161948 if (err) printf("ERROR: %d\n", err);
826*2139Sjp161948 #endif
8270Sstevel@tonic-gate printf("\n");
8280Sstevel@tonic-gate return(err);
8290Sstevel@tonic-gate }
8300Sstevel@tonic-gate
pt(unsigned char * p)8310Sstevel@tonic-gate static char *pt(unsigned char *p)
8320Sstevel@tonic-gate {
8330Sstevel@tonic-gate static char bufs[10][20];
8340Sstevel@tonic-gate static int bnum=0;
8350Sstevel@tonic-gate char *ret;
8360Sstevel@tonic-gate int i;
8370Sstevel@tonic-gate static char *f="0123456789ABCDEF";
8380Sstevel@tonic-gate
8390Sstevel@tonic-gate ret= &(bufs[bnum++][0]);
8400Sstevel@tonic-gate bnum%=10;
8410Sstevel@tonic-gate for (i=0; i<8; i++)
8420Sstevel@tonic-gate {
8430Sstevel@tonic-gate ret[i*2]=f[(p[i]>>4)&0xf];
8440Sstevel@tonic-gate ret[i*2+1]=f[p[i]&0xf];
8450Sstevel@tonic-gate }
8460Sstevel@tonic-gate ret[16]='\0';
8470Sstevel@tonic-gate return(ret);
8480Sstevel@tonic-gate }
8490Sstevel@tonic-gate
8500Sstevel@tonic-gate #ifndef LIBDES_LIT
8510Sstevel@tonic-gate
cfb_test(int bits,unsigned char * cfb_cipher)8520Sstevel@tonic-gate static int cfb_test(int bits, unsigned char *cfb_cipher)
8530Sstevel@tonic-gate {
8540Sstevel@tonic-gate des_key_schedule ks;
8550Sstevel@tonic-gate int i,err=0;
8560Sstevel@tonic-gate
8570Sstevel@tonic-gate DES_set_key_checked(&cfb_key,&ks);
8580Sstevel@tonic-gate memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
8590Sstevel@tonic-gate des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp,
8600Sstevel@tonic-gate DES_ENCRYPT);
8610Sstevel@tonic-gate if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
8620Sstevel@tonic-gate {
8630Sstevel@tonic-gate err=1;
8640Sstevel@tonic-gate printf("cfb_encrypt encrypt error\n");
8650Sstevel@tonic-gate for (i=0; i<24; i+=8)
8660Sstevel@tonic-gate printf("%s\n",pt(&(cfb_buf1[i])));
8670Sstevel@tonic-gate }
8680Sstevel@tonic-gate memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
8690Sstevel@tonic-gate des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,&cfb_tmp,
8700Sstevel@tonic-gate DES_DECRYPT);
8710Sstevel@tonic-gate if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
8720Sstevel@tonic-gate {
8730Sstevel@tonic-gate err=1;
8740Sstevel@tonic-gate printf("cfb_encrypt decrypt error\n");
8750Sstevel@tonic-gate for (i=0; i<24; i+=8)
8760Sstevel@tonic-gate printf("%s\n",pt(&(cfb_buf1[i])));
8770Sstevel@tonic-gate }
8780Sstevel@tonic-gate return(err);
8790Sstevel@tonic-gate }
8800Sstevel@tonic-gate
cfb64_test(unsigned char * cfb_cipher)8810Sstevel@tonic-gate static int cfb64_test(unsigned char *cfb_cipher)
8820Sstevel@tonic-gate {
8830Sstevel@tonic-gate des_key_schedule ks;
8840Sstevel@tonic-gate int err=0,i,n;
8850Sstevel@tonic-gate
8860Sstevel@tonic-gate DES_set_key_checked(&cfb_key,&ks);
8870Sstevel@tonic-gate memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
8880Sstevel@tonic-gate n=0;
8890Sstevel@tonic-gate des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT);
8900Sstevel@tonic-gate des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks,
8910Sstevel@tonic-gate &cfb_tmp,&n,DES_ENCRYPT);
8920Sstevel@tonic-gate if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
8930Sstevel@tonic-gate {
8940Sstevel@tonic-gate err=1;
8950Sstevel@tonic-gate printf("cfb_encrypt encrypt error\n");
8960Sstevel@tonic-gate for (i=0; i<24; i+=8)
8970Sstevel@tonic-gate printf("%s\n",pt(&(cfb_buf1[i])));
8980Sstevel@tonic-gate }
8990Sstevel@tonic-gate memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
9000Sstevel@tonic-gate n=0;
9010Sstevel@tonic-gate des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,&cfb_tmp,&n,DES_DECRYPT);
9020Sstevel@tonic-gate des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
9030Sstevel@tonic-gate sizeof(plain)-17,ks,&cfb_tmp,&n,DES_DECRYPT);
9040Sstevel@tonic-gate if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
9050Sstevel@tonic-gate {
9060Sstevel@tonic-gate err=1;
9070Sstevel@tonic-gate printf("cfb_encrypt decrypt error\n");
9080Sstevel@tonic-gate for (i=0; i<24; i+=8)
9090Sstevel@tonic-gate printf("%s\n",pt(&(cfb_buf2[i])));
9100Sstevel@tonic-gate }
9110Sstevel@tonic-gate return(err);
9120Sstevel@tonic-gate }
9130Sstevel@tonic-gate
ede_cfb64_test(unsigned char * cfb_cipher)9140Sstevel@tonic-gate static int ede_cfb64_test(unsigned char *cfb_cipher)
9150Sstevel@tonic-gate {
9160Sstevel@tonic-gate des_key_schedule ks;
9170Sstevel@tonic-gate int err=0,i,n;
9180Sstevel@tonic-gate
9190Sstevel@tonic-gate DES_set_key_checked(&cfb_key,&ks);
9200Sstevel@tonic-gate memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
9210Sstevel@tonic-gate n=0;
9220Sstevel@tonic-gate des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n,
9230Sstevel@tonic-gate DES_ENCRYPT);
9240Sstevel@tonic-gate des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
9250Sstevel@tonic-gate sizeof(plain)-12,ks,ks,ks,
9260Sstevel@tonic-gate &cfb_tmp,&n,DES_ENCRYPT);
9270Sstevel@tonic-gate if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
9280Sstevel@tonic-gate {
9290Sstevel@tonic-gate err=1;
9300Sstevel@tonic-gate printf("ede_cfb_encrypt encrypt error\n");
9310Sstevel@tonic-gate for (i=0; i<24; i+=8)
9320Sstevel@tonic-gate printf("%s\n",pt(&(cfb_buf1[i])));
9330Sstevel@tonic-gate }
9340Sstevel@tonic-gate memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
9350Sstevel@tonic-gate n=0;
9360Sstevel@tonic-gate des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks,
9370Sstevel@tonic-gate &cfb_tmp,&n,DES_DECRYPT);
9380Sstevel@tonic-gate des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
9390Sstevel@tonic-gate sizeof(plain)-17,ks,ks,ks,
9400Sstevel@tonic-gate &cfb_tmp,&n,DES_DECRYPT);
9410Sstevel@tonic-gate if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
9420Sstevel@tonic-gate {
9430Sstevel@tonic-gate err=1;
9440Sstevel@tonic-gate printf("ede_cfb_encrypt decrypt error\n");
9450Sstevel@tonic-gate for (i=0; i<24; i+=8)
9460Sstevel@tonic-gate printf("%s\n",pt(&(cfb_buf2[i])));
9470Sstevel@tonic-gate }
9480Sstevel@tonic-gate return(err);
9490Sstevel@tonic-gate }
9500Sstevel@tonic-gate
9510Sstevel@tonic-gate #endif
9520Sstevel@tonic-gate #endif
953