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