1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ssl/tsrc/crypto_test/src/destest.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,984 @@
1.4 +/* crypto/des/destest.c */
1.5 +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
1.6 + * All rights reserved.
1.7 + *
1.8 + * This package is an SSL implementation written
1.9 + * by Eric Young (eay@cryptsoft.com).
1.10 + * The implementation was written so as to conform with Netscapes SSL.
1.11 + *
1.12 + * This library is free for commercial and non-commercial use as long as
1.13 + * the following conditions are aheared to. The following conditions
1.14 + * apply to all code found in this distribution, be it the RC4, RSA,
1.15 + * lhash, DES, etc., code; not just the SSL code. The SSL documentation
1.16 + * included with this distribution is covered by the same copyright terms
1.17 + * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1.18 + *
1.19 + * Copyright remains Eric Young's, and as such any Copyright notices in
1.20 + * the code are not to be removed.
1.21 + * If this package is used in a product, Eric Young should be given attribution
1.22 + * as the author of the parts of the library used.
1.23 + * This can be in the form of a textual message at program startup or
1.24 + * in documentation (online or textual) provided with the package.
1.25 + *
1.26 + * Redistribution and use in source and binary forms, with or without
1.27 + * modification, are permitted provided that the following conditions
1.28 + * are met:
1.29 + * 1. Redistributions of source code must retain the copyright
1.30 + * notice, this list of conditions and the following disclaimer.
1.31 + * 2. Redistributions in binary form must reproduce the above copyright
1.32 + * notice, this list of conditions and the following disclaimer in the
1.33 + * documentation and/or other materials provided with the distribution.
1.34 + * 3. All advertising materials mentioning features or use of this software
1.35 + * must display the following acknowledgement:
1.36 + * "This product includes cryptographic software written by
1.37 + * Eric Young (eay@cryptsoft.com)"
1.38 + * The word 'cryptographic' can be left out if the rouines from the library
1.39 + * being used are not cryptographic related :-).
1.40 + * 4. If you include any Windows specific code (or a derivative thereof) from
1.41 + * the apps directory (application code) you must include an acknowledgement:
1.42 + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
1.43 + *
1.44 + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
1.45 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.46 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.47 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1.48 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.49 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1.50 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.51 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1.52 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1.53 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1.54 + * SUCH DAMAGE.
1.55 + *
1.56 + * The licence and distribution terms for any publically available version or
1.57 + * derivative of this code cannot be changed. i.e. this code cannot simply be
1.58 + * copied and put under another distribution licence
1.59 + * [including the GNU Public Licence.]
1.60 + */
1.61 +/*
1.62 + © Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
1.63 + */
1.64 +#include <stdio.h>
1.65 +#include <stdlib.h>
1.66 +
1.67 +#include <openssl/e_os2.h>
1.68 +#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_WINDOWS)
1.69 +#ifndef OPENSSL_SYS_MSDOS
1.70 +#define OPENSSL_SYS_MSDOS
1.71 +#endif
1.72 +#endif
1.73 +
1.74 +#ifndef OPENSSL_SYS_MSDOS
1.75 +#if !defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_VMS_DECC)
1.76 +#include OPENSSL_UNISTD
1.77 +#endif
1.78 +#else
1.79 +#include <io.h>
1.80 +#endif
1.81 +#include <string.h>
1.82 +
1.83 +
1.84 +#ifdef SYMBIAN
1.85 +#ifdef stdin
1.86 +#undef stdin
1.87 +#endif
1.88 +#ifdef stdout
1.89 +#undef stdout
1.90 +#endif
1.91 +#ifdef stderr
1.92 +#undef stderr
1.93 +#endif
1.94 +
1.95 +#define stdin fp_stdin
1.96 +#define stdout fp_stdout
1.97 +#define stderr fp_stderr
1.98 +
1.99 +extern FILE *fp_stdout;
1.100 +extern FILE *fp_stderr;
1.101 +#endif
1.102 +
1.103 +#ifdef OPENSSL_NO_DES
1.104 +int main(int argc, char *argv[])
1.105 +{
1.106 + printf("No DES support\n");
1.107 + return(0);
1.108 +}
1.109 +#else
1.110 +#include <openssl/des.h>
1.111 +
1.112 +#define crypt(c,s) (DES_crypt((c),(s)))
1.113 +
1.114 +/* tisk tisk - the test keys don't all have odd parity :-( */
1.115 +/* test data */
1.116 +#define NUM_TESTS 34
1.117 +static unsigned char key_data[NUM_TESTS][8]={
1.118 + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1.119 + {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
1.120 + {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1.121 + {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
1.122 + {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1.123 + {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
1.124 + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1.125 + {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10},
1.126 + {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57},
1.127 + {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E},
1.128 + {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86},
1.129 + {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E},
1.130 + {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6},
1.131 + {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE},
1.132 + {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6},
1.133 + {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE},
1.134 + {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16},
1.135 + {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F},
1.136 + {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46},
1.137 + {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E},
1.138 + {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76},
1.139 + {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07},
1.140 + {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F},
1.141 + {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7},
1.142 + {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF},
1.143 + {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6},
1.144 + {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF},
1.145 + {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
1.146 + {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
1.147 + {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
1.148 + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1.149 + {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
1.150 + {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1.151 + {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}};
1.152 +
1.153 +static unsigned char plain_data[NUM_TESTS][8]={
1.154 + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1.155 + {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
1.156 + {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
1.157 + {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
1.158 + {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
1.159 + {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1.160 + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1.161 + {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1.162 + {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42},
1.163 + {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA},
1.164 + {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72},
1.165 + {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A},
1.166 + {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2},
1.167 + {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A},
1.168 + {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2},
1.169 + {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A},
1.170 + {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02},
1.171 + {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A},
1.172 + {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32},
1.173 + {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA},
1.174 + {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62},
1.175 + {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2},
1.176 + {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA},
1.177 + {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92},
1.178 + {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A},
1.179 + {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2},
1.180 + {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A},
1.181 + {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1.182 + {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1.183 + {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
1.184 + {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
1.185 + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1.186 + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
1.187 + {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
1.188 +
1.189 +static unsigned char cipher_data[NUM_TESTS][8]={
1.190 + {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
1.191 + {0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58},
1.192 + {0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B},
1.193 + {0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33},
1.194 + {0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D},
1.195 + {0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD},
1.196 + {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
1.197 + {0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4},
1.198 + {0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B},
1.199 + {0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71},
1.200 + {0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A},
1.201 + {0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A},
1.202 + {0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95},
1.203 + {0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B},
1.204 + {0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09},
1.205 + {0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A},
1.206 + {0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F},
1.207 + {0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88},
1.208 + {0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77},
1.209 + {0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A},
1.210 + {0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56},
1.211 + {0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56},
1.212 + {0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56},
1.213 + {0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC},
1.214 + {0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A},
1.215 + {0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41},
1.216 + {0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93},
1.217 + {0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00},
1.218 + {0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06},
1.219 + {0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7},
1.220 + {0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51},
1.221 + {0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE},
1.222 + {0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D},
1.223 + {0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}};
1.224 +
1.225 +static unsigned char cipher_ecb2[NUM_TESTS-1][8]={
1.226 + {0x92,0x95,0xB5,0x9B,0xB3,0x84,0x73,0x6E},
1.227 + {0x19,0x9E,0x9D,0x6D,0xF3,0x9A,0xA8,0x16},
1.228 + {0x2A,0x4B,0x4D,0x24,0x52,0x43,0x84,0x27},
1.229 + {0x35,0x84,0x3C,0x01,0x9D,0x18,0xC5,0xB6},
1.230 + {0x4A,0x5B,0x2F,0x42,0xAA,0x77,0x19,0x25},
1.231 + {0xA0,0x6B,0xA9,0xB8,0xCA,0x5B,0x17,0x8A},
1.232 + {0xAB,0x9D,0xB7,0xFB,0xED,0x95,0xF2,0x74},
1.233 + {0x3D,0x25,0x6C,0x23,0xA7,0x25,0x2F,0xD6},
1.234 + {0xB7,0x6F,0xAB,0x4F,0xBD,0xBD,0xB7,0x67},
1.235 + {0x8F,0x68,0x27,0xD6,0x9C,0xF4,0x1A,0x10},
1.236 + {0x82,0x57,0xA1,0xD6,0x50,0x5E,0x81,0x85},
1.237 + {0xA2,0x0F,0x0A,0xCD,0x80,0x89,0x7D,0xFA},
1.238 + {0xCD,0x2A,0x53,0x3A,0xDB,0x0D,0x7E,0xF3},
1.239 + {0xD2,0xC2,0xBE,0x27,0xE8,0x1B,0x68,0xE3},
1.240 + {0xE9,0x24,0xCF,0x4F,0x89,0x3C,0x5B,0x0A},
1.241 + {0xA7,0x18,0xC3,0x9F,0xFA,0x9F,0xD7,0x69},
1.242 + {0x77,0x2C,0x79,0xB1,0xD2,0x31,0x7E,0xB1},
1.243 + {0x49,0xAB,0x92,0x7F,0xD0,0x22,0x00,0xB7},
1.244 + {0xCE,0x1C,0x6C,0x7D,0x85,0xE3,0x4A,0x6F},
1.245 + {0xBE,0x91,0xD6,0xE1,0x27,0xB2,0xE9,0x87},
1.246 + {0x70,0x28,0xAE,0x8F,0xD1,0xF5,0x74,0x1A},
1.247 + {0xAA,0x37,0x80,0xBB,0xF3,0x22,0x1D,0xDE},
1.248 + {0xA6,0xC4,0xD2,0x5E,0x28,0x93,0xAC,0xB3},
1.249 + {0x22,0x07,0x81,0x5A,0xE4,0xB7,0x1A,0xAD},
1.250 + {0xDC,0xCE,0x05,0xE7,0x07,0xBD,0xF5,0x84},
1.251 + {0x26,0x1D,0x39,0x2C,0xB3,0xBA,0xA5,0x85},
1.252 + {0xB4,0xF7,0x0F,0x72,0xFB,0x04,0xF0,0xDC},
1.253 + {0x95,0xBA,0xA9,0x4E,0x87,0x36,0xF2,0x89},
1.254 + {0xD4,0x07,0x3A,0xF1,0x5A,0x17,0x82,0x0E},
1.255 + {0xEF,0x6F,0xAF,0xA7,0x66,0x1A,0x7E,0x89},
1.256 + {0xC1,0x97,0xF5,0x58,0x74,0x8A,0x20,0xE7},
1.257 + {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8},
1.258 + {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}};
1.259 +
1.260 +static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
1.261 +static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86};
1.262 +static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
1.263 +static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
1.264 +/* Changed the following text constant to binary so it will work on ebcdic
1.265 + * machines :-) */
1.266 +/* static char cbc_data[40]="7654321 Now is the time for \0001"; */
1.267 +static unsigned char cbc_data[40]={
1.268 + 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20,
1.269 + 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74,
1.270 + 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20,
1.271 + 0x66,0x6F,0x72,0x20,0x00,0x31,0x00,0x00,
1.272 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1.273 + };
1.274 +
1.275 +static unsigned char cbc_ok[32]={
1.276 + 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
1.277 + 0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb,
1.278 + 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68,
1.279 + 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
1.280 +
1.281 +#ifdef SCREW_THE_PARITY
1.282 +#error "SCREW_THE_PARITY is not ment to be defined."
1.283 +#error "Original vectors are preserved for reference only."
1.284 +static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
1.285 +static unsigned char xcbc_ok[32]={
1.286 + 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48,
1.287 + 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD,
1.288 + 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76,
1.289 + 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2,
1.290 + };
1.291 +#else
1.292 +static unsigned char xcbc_ok[32]={
1.293 + 0x84,0x6B,0x29,0x14,0x85,0x1E,0x9A,0x29,
1.294 + 0x54,0x73,0x2F,0x8A,0xA0,0xA6,0x11,0xC1,
1.295 + 0x15,0xCD,0xC2,0xD7,0x95,0x1B,0x10,0x53,
1.296 + 0xA6,0x3C,0x5E,0x03,0xB2,0x1A,0xA3,0xC4,
1.297 + };
1.298 +#endif
1.299 +
1.300 +static unsigned char cbc3_ok[32]={
1.301 + 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0,
1.302 + 0x22,0x13,0x76,0x3C,0x1C,0xBD,0x4C,0xDC,
1.303 + 0x79,0x96,0x57,0xC0,0x64,0xEC,0xF5,0xD4,
1.304 + 0x1C,0x67,0x38,0x12,0xCF,0xDE,0x96,0x75};
1.305 +
1.306 +static unsigned char pcbc_ok[32]={
1.307 + 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
1.308 + 0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15,
1.309 + 0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f,
1.310 + 0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88};
1.311 +
1.312 +static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
1.313 +static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
1.314 +static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
1.315 +static unsigned char plain[24]=
1.316 + {
1.317 + 0x4e,0x6f,0x77,0x20,0x69,0x73,
1.318 + 0x20,0x74,0x68,0x65,0x20,0x74,
1.319 + 0x69,0x6d,0x65,0x20,0x66,0x6f,
1.320 + 0x72,0x20,0x61,0x6c,0x6c,0x20
1.321 + };
1.322 +static unsigned char cfb_cipher8[24]= {
1.323 + 0xf3,0x1f,0xda,0x07,0x01,0x14, 0x62,0xee,0x18,0x7f,0x43,0xd8,
1.324 + 0x0a,0x7c,0xd9,0xb5,0xb0,0xd2, 0x90,0xda,0x6e,0x5b,0x9a,0x87 };
1.325 +static unsigned char cfb_cipher16[24]={
1.326 + 0xF3,0x09,0x87,0x87,0x7F,0x57, 0xF7,0x3C,0x36,0xB6,0xDB,0x70,
1.327 + 0xD8,0xD5,0x34,0x19,0xD3,0x86, 0xB2,0x23,0xB7,0xB2,0xAD,0x1B };
1.328 +static unsigned char cfb_cipher32[24]={
1.329 + 0xF3,0x09,0x62,0x49,0xA4,0xDF, 0xA4,0x9F,0x33,0xDC,0x7B,0xAD,
1.330 + 0x4C,0xC8,0x9F,0x64,0xE4,0x53, 0xE5,0xEC,0x67,0x20,0xDA,0xB6 };
1.331 +static unsigned char cfb_cipher48[24]={
1.332 + 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x30,0xB5,0x15,0xEC,0xBB,0x85,
1.333 + 0x97,0x5A,0x13,0x8C,0x68,0x60, 0xE2,0x38,0x34,0x3C,0xDC,0x1F };
1.334 +static unsigned char cfb_cipher64[24]={
1.335 + 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x6E,0x51,0xA6,0x9E,0x83,0x9B,
1.336 + 0x1A,0x92,0xF7,0x84,0x03,0x46, 0x71,0x33,0x89,0x8E,0xA6,0x22 };
1.337 +
1.338 +static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
1.339 +static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
1.340 +static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8];
1.341 +static unsigned char ofb_cipher[24]=
1.342 + {
1.343 + 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
1.344 + 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
1.345 + 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3
1.346 + };
1.347 +
1.348 +#if 0
1.349 +static DES_LONG cbc_cksum_ret=0xB462FEF7L;
1.350 +#else
1.351 +static DES_LONG cbc_cksum_ret=0xF7FE62B4L;
1.352 +#endif
1.353 +static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
1.354 +
1.355 +static char *pt(unsigned char *p);
1.356 +static int cfb_test(int bits, unsigned char *cfb_cipher);
1.357 +static int cfb64_test(unsigned char *cfb_cipher);
1.358 +static int ede_cfb64_test(unsigned char *cfb_cipher);
1.359 +
1.360 +#ifndef SYMBIAN
1.361 +int main(int argc, char *argv[])
1.362 +#else
1.363 +int des_main(int argc, char *argv[])
1.364 +#endif
1.365 +
1.366 + {
1.367 + int j,err=0;
1.368 + unsigned int i;
1.369 + des_cblock in,out,outin,iv3,iv2;
1.370 + des_key_schedule ks,ks2,ks3;
1.371 + unsigned char cbc_in[40];
1.372 + unsigned char cbc_out[40];
1.373 + DES_LONG cs;
1.374 + unsigned char cret[8];
1.375 + size_t no_bytes=0;
1.376 +#ifdef _CRAY
1.377 + struct {
1.378 + int a:32;
1.379 + int b:32;
1.380 + } lqret[2];
1.381 +#else
1.382 + DES_LONG lqret[4];
1.383 +#endif
1.384 + int num;
1.385 + char *str;
1.386 +
1.387 +#ifndef OPENSSL_NO_DESCBCM
1.388 + fprintf(stdout,"Doing cbcm\n");
1.389 + if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
1.390 + {
1.391 + fprintf(stdout,"Key error %d\n",j);
1.392 + err=1;
1.393 + }
1.394 + if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0)
1.395 + {
1.396 + fprintf(stdout,"Key error %d\n",j);
1.397 + err=1;
1.398 + }
1.399 + if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0)
1.400 + {
1.401 + fprintf(stdout,"Key error %d\n",j);
1.402 + err=1;
1.403 + }
1.404 +
1.405 + memset(cbc_out,0,40);
1.406 + memset(cbc_in,0,40);
1.407 + i=strlen((char *)cbc_data)+1;
1.408 + /* i=((i+7)/8)*8; */
1.409 + memcpy(iv3,cbc_iv,sizeof(cbc_iv));
1.410 + memset(iv2,'\0',sizeof iv2);
1.411 +
1.412 + DES_ede3_cbcm_encrypt(cbc_data,cbc_out,16L,&ks,&ks2,&ks3,&iv3,&iv2,
1.413 + DES_ENCRYPT);
1.414 + DES_ede3_cbcm_encrypt(&cbc_data[16],&cbc_out[16],i-16,&ks,&ks2,&ks3,
1.415 + &iv3,&iv2,DES_ENCRYPT);
1.416 + /* if (memcmp(cbc_out,cbc3_ok,
1.417 + (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
1.418 + {
1.419 + printf("des_ede3_cbc_encrypt encrypt error\n");
1.420 + err=1;
1.421 + }
1.422 + */
1.423 + memcpy(iv3,cbc_iv,sizeof(cbc_iv));
1.424 + memset(iv2,'\0',sizeof iv2);
1.425 + DES_ede3_cbcm_encrypt(cbc_out,cbc_in,i,&ks,&ks2,&ks3,&iv3,&iv2,DES_DECRYPT);
1.426 + if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
1.427 + {
1.428 + unsigned int n;
1.429 +
1.430 + fprintf(stdout,"des_ede3_cbcm_encrypt decrypt error\n");
1.431 + for(n=0 ; n < i ; ++n)
1.432 + printf(" %02x",cbc_data[n]);
1.433 + fprintf(stdout,"\n");
1.434 + for(n=0 ; n < i ; ++n)
1.435 + fprintf(stdout," %02x",cbc_in[n]);
1.436 + fprintf(stdout,"\n");
1.437 + err=1;
1.438 + }
1.439 +#endif
1.440 +
1.441 + fprintf(stdout,"Doing ecb\n");
1.442 + for (i=0; i<NUM_TESTS; i++)
1.443 + {
1.444 + DES_set_key_unchecked(&key_data[i],&ks);
1.445 + memcpy(in,plain_data[i],8);
1.446 + memset(out,0,8);
1.447 + memset(outin,0,8);
1.448 + des_ecb_encrypt(&in,&out,ks,DES_ENCRYPT);
1.449 + des_ecb_encrypt(&out,&outin,ks,DES_DECRYPT);
1.450 +
1.451 + if (memcmp(out,cipher_data[i],8) != 0)
1.452 + {
1.453 + fprintf(stdout,"Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
1.454 + i+1,pt(key_data[i]),pt(in),pt(cipher_data[i]),
1.455 + pt(out));
1.456 + err=1;
1.457 + }
1.458 + if (memcmp(in,outin,8) != 0)
1.459 + {
1.460 + fprintf(stdout,"Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
1.461 + i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
1.462 + err=1;
1.463 + }
1.464 + }
1.465 +
1.466 +#ifndef LIBDES_LIT
1.467 + fprintf(stdout,"Doing ede ecb\n");
1.468 + for (i=0; i<(NUM_TESTS-2); i++)
1.469 + {
1.470 + DES_set_key_unchecked(&key_data[i],&ks);
1.471 + DES_set_key_unchecked(&key_data[i+1],&ks2);
1.472 + DES_set_key_unchecked(&key_data[i+2],&ks3);
1.473 + memcpy(in,plain_data[i],8);
1.474 + memset(out,0,8);
1.475 + memset(outin,0,8);
1.476 + des_ecb2_encrypt(&in,&out,ks,ks2,DES_ENCRYPT);
1.477 + des_ecb2_encrypt(&out,&outin,ks,ks2,DES_DECRYPT);
1.478 +
1.479 + if (memcmp(out,cipher_ecb2[i],8) != 0)
1.480 + {
1.481 + fprintf(stdout,"Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
1.482 + i+1,pt(key_data[i]),pt(in),pt(cipher_ecb2[i]),
1.483 + pt(out));
1.484 + err=1;
1.485 + }
1.486 + if (memcmp(in,outin,8) != 0)
1.487 + {
1.488 + fprintf(stdout,"Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
1.489 + i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
1.490 + err=1;
1.491 + }
1.492 + }
1.493 +#endif
1.494 +
1.495 + fprintf(stdout,"Doing cbc\n");
1.496 + if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
1.497 + {
1.498 + fprintf(stdout,"Key error %d\n",j);
1.499 + err=1;
1.500 + }
1.501 + memset(cbc_out,0,40);
1.502 + memset(cbc_in,0,40);
1.503 + memcpy(iv3,cbc_iv,sizeof(cbc_iv));
1.504 + des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
1.505 + &iv3,DES_ENCRYPT);
1.506 + if (memcmp(cbc_out,cbc_ok,32) != 0)
1.507 + {
1.508 + fprintf(stdout,"cbc_encrypt encrypt error\n");
1.509 + err=1;
1.510 + }
1.511 +
1.512 + memcpy(iv3,cbc_iv,sizeof(cbc_iv));
1.513 + des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
1.514 + &iv3,DES_DECRYPT);
1.515 + if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0)
1.516 + {
1.517 + fprintf(stdout,"cbc_encrypt decrypt error\n");
1.518 + err=1;
1.519 + }
1.520 +
1.521 +#ifndef LIBDES_LIT
1.522 + fprintf(stdout,"Doing desx cbc\n");
1.523 + if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
1.524 + {
1.525 + fprintf(stdout,"Key error %d\n",j);
1.526 + err=1;
1.527 + }
1.528 + memset(cbc_out,0,40);
1.529 + memset(cbc_in,0,40);
1.530 + memcpy(iv3,cbc_iv,sizeof(cbc_iv));
1.531 + des_xcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
1.532 + &iv3,&cbc2_key,&cbc3_key, DES_ENCRYPT);
1.533 + if (memcmp(cbc_out,xcbc_ok,32) != 0)
1.534 + {
1.535 + fprintf(stdout,"des_xcbc_encrypt encrypt error\n");
1.536 + err=1;
1.537 + }
1.538 + memcpy(iv3,cbc_iv,sizeof(cbc_iv));
1.539 + des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
1.540 + &iv3,&cbc2_key,&cbc3_key, DES_DECRYPT);
1.541 + if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
1.542 + {
1.543 + fprintf(stdout,"des_xcbc_encrypt decrypt error\n");
1.544 + err=1;
1.545 + }
1.546 +#endif
1.547 +
1.548 + fprintf(stdout,"Doing ede cbc\n");
1.549 + if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
1.550 + {
1.551 + fprintf(stdout,"Key error %d\n",j);
1.552 + err=1;
1.553 + }
1.554 + if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0)
1.555 + {
1.556 + fprintf(stdout,"Key error %d\n",j);
1.557 + err=1;
1.558 + }
1.559 + if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0)
1.560 + {
1.561 + fprintf(stdout,"Key error %d\n",j);
1.562 + err=1;
1.563 + }
1.564 + memset(cbc_out,0,40);
1.565 + memset(cbc_in,0,40);
1.566 + i=strlen((char *)cbc_data)+1;
1.567 + /* i=((i+7)/8)*8; */
1.568 + memcpy(iv3,cbc_iv,sizeof(cbc_iv));
1.569 +
1.570 + des_ede3_cbc_encrypt(cbc_data,cbc_out,16L,ks,ks2,ks3,&iv3,
1.571 + DES_ENCRYPT);
1.572 + des_ede3_cbc_encrypt(&(cbc_data[16]),&(cbc_out[16]),i-16,ks,ks2,ks3,
1.573 + &iv3,DES_ENCRYPT);
1.574 + if (memcmp(cbc_out,cbc3_ok,
1.575 + (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
1.576 + {
1.577 + unsigned int n;
1.578 +
1.579 + fprintf(stdout,"des_ede3_cbc_encrypt encrypt error\n");
1.580 + for(n=0 ; n < i ; ++n)
1.581 + fprintf(stdout," %02x",cbc_out[n]);
1.582 + fprintf(stdout,"\n");
1.583 + for(n=0 ; n < i ; ++n)
1.584 + fprintf(stdout," %02x",cbc3_ok[n]);
1.585 + fprintf(stdout,"\n");
1.586 + err=1;
1.587 + }
1.588 +
1.589 + memcpy(iv3,cbc_iv,sizeof(cbc_iv));
1.590 + des_ede3_cbc_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,&iv3,DES_DECRYPT);
1.591 + if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
1.592 + {
1.593 + unsigned int n;
1.594 +
1.595 + fprintf(stdout,"des_ede3_cbc_encrypt decrypt error\n");
1.596 + for(n=0 ; n < i ; ++n)
1.597 + fprintf(stdout," %02x",cbc_data[n]);
1.598 + fprintf(stdout,"\n");
1.599 + for(n=0 ; n < i ; ++n)
1.600 + fprintf(stdout," %02x",cbc_in[n]);
1.601 + fprintf(stdout,"\n");
1.602 + err=1;
1.603 + }
1.604 +
1.605 +#ifndef LIBDES_LIT
1.606 + fprintf(stdout,"Doing pcbc\n");
1.607 + if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
1.608 + {
1.609 + fprintf(stdout,"Key error %d\n",j);
1.610 + err=1;
1.611 + }
1.612 + memset(cbc_out,0,40);
1.613 + memset(cbc_in,0,40);
1.614 + des_pcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
1.615 + &cbc_iv,DES_ENCRYPT);
1.616 + if (memcmp(cbc_out,pcbc_ok,32) != 0)
1.617 + {
1.618 + fprintf(stdout,"pcbc_encrypt encrypt error\n");
1.619 + err=1;
1.620 + }
1.621 + des_pcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,&cbc_iv,
1.622 + DES_DECRYPT);
1.623 + if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
1.624 + {
1.625 + fprintf(stdout,"pcbc_encrypt decrypt error\n");
1.626 + err=1;
1.627 + }
1.628 +
1.629 + fprintf(stdout,"Doing ");
1.630 + fprintf(stdout,"cfb8 ");
1.631 + err+=cfb_test(8,cfb_cipher8);
1.632 + fprintf(stdout,"cfb16 ");
1.633 + err+=cfb_test(16,cfb_cipher16);
1.634 + fprintf(stdout,"cfb32 ");
1.635 + err+=cfb_test(32,cfb_cipher32);
1.636 + fprintf(stdout,"cfb48 ");
1.637 + err+=cfb_test(48,cfb_cipher48);
1.638 + fprintf(stdout,"cfb64 ");
1.639 + err+=cfb_test(64,cfb_cipher64);
1.640 +
1.641 + fprintf(stdout,"cfb64() ");
1.642 + err+=cfb64_test(cfb_cipher64);
1.643 +
1.644 + memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
1.645 + for (i=0; i<sizeof(plain); i++)
1.646 + des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]),
1.647 + 8,1,ks,&cfb_tmp,DES_ENCRYPT);
1.648 + if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0)
1.649 + {
1.650 + fprintf(stdout,"cfb_encrypt small encrypt error\n");
1.651 + err=1;
1.652 + }
1.653 +
1.654 + memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
1.655 + for (i=0; i<sizeof(plain); i++)
1.656 + des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]),
1.657 + 8,1,ks,&cfb_tmp,DES_DECRYPT);
1.658 + if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
1.659 + {
1.660 + fprintf(stdout,"cfb_encrypt small decrypt error\n");
1.661 + err=1;
1.662 + }
1.663 +
1.664 + fprintf(stdout,"ede_cfb64() ");
1.665 + err+=ede_cfb64_test(cfb_cipher64);
1.666 +
1.667 + fprintf(stdout,"done\n");
1.668 +
1.669 + fprintf(stdout,"Doing ofb\n");
1.670 + DES_set_key_checked(&ofb_key,&ks);
1.671 + memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
1.672 + des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp);
1.673 + if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
1.674 + {
1.675 + fprintf(stdout,"ofb_encrypt encrypt error\n");
1.676 +fprintf(stdout,"%02X %02X %02X %02X %02X %02X %02X %02X\n",
1.677 +ofb_buf1[8+0], ofb_buf1[8+1], ofb_buf1[8+2], ofb_buf1[8+3],
1.678 +ofb_buf1[8+4], ofb_buf1[8+5], ofb_buf1[8+6], ofb_buf1[8+7]);
1.679 +fprintf(stdout,"%02X %02X %02X %02X %02X %02X %02X %02X\n",
1.680 +ofb_buf1[8+0], ofb_cipher[8+1], ofb_cipher[8+2], ofb_cipher[8+3],
1.681 +ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]);
1.682 + err=1;
1.683 + }
1.684 + memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
1.685 + des_ofb_encrypt(ofb_buf1,ofb_buf2,64,sizeof(ofb_buf1)/8,ks,&ofb_tmp);
1.686 + if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
1.687 + {
1.688 + fprintf(stdout,"ofb_encrypt decrypt error\n");
1.689 +fprintf(stdout,"%02X %02X %02X %02X %02X %02X %02X %02X\n",
1.690 +ofb_buf2[8+0], ofb_buf2[8+1], ofb_buf2[8+2], ofb_buf2[8+3],
1.691 +ofb_buf2[8+4], ofb_buf2[8+5], ofb_buf2[8+6], ofb_buf2[8+7]);
1.692 +fprintf(stdout,"%02X %02X %02X %02X %02X %02X %02X %02X\n",
1.693 +plain[8+0], plain[8+1], plain[8+2], plain[8+3],
1.694 +plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
1.695 + err=1;
1.696 + }
1.697 +
1.698 + fprintf(stdout,"Doing ofb64\n");
1.699 + DES_set_key_checked(&ofb_key,&ks);
1.700 + memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
1.701 + memset(ofb_buf1,0,sizeof(ofb_buf1));
1.702 + memset(ofb_buf2,0,sizeof(ofb_buf1));
1.703 + num=0;
1.704 + for (i=0; i<sizeof(plain); i++)
1.705 + {
1.706 + des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,&ofb_tmp,
1.707 + &num);
1.708 + }
1.709 + if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
1.710 + {
1.711 + fprintf(stdout,"ofb64_encrypt encrypt error\n");
1.712 + err=1;
1.713 + }
1.714 + memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
1.715 + num=0;
1.716 + des_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,&ofb_tmp,
1.717 + &num);
1.718 + if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
1.719 + {
1.720 + fprintf(stdout,"ofb64_encrypt decrypt error\n");
1.721 + err=1;
1.722 + }
1.723 +
1.724 + fprintf(stdout,"Doing ede_ofb64\n");
1.725 + DES_set_key_checked(&ofb_key,&ks);
1.726 + memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
1.727 + memset(ofb_buf1,0,sizeof(ofb_buf1));
1.728 + memset(ofb_buf2,0,sizeof(ofb_buf1));
1.729 + num=0;
1.730 + for (i=0; i<sizeof(plain); i++)
1.731 + {
1.732 + des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,
1.733 + ks,&ofb_tmp,&num);
1.734 + }
1.735 + if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
1.736 + {
1.737 + fprintf(stdout,"ede_ofb64_encrypt encrypt error\n");
1.738 + err=1;
1.739 + }
1.740 + memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
1.741 + num=0;
1.742 + des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,ks,ks,
1.743 + &ofb_tmp,&num);
1.744 + if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
1.745 + {
1.746 + fprintf(stdout,"ede_ofb64_encrypt decrypt error\n");
1.747 + err=1;
1.748 + }
1.749 +
1.750 + fprintf(stdout,"Doing cbc_cksum\n");
1.751 + DES_set_key_checked(&cbc_key,&ks);
1.752 + cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv);
1.753 + if (cs != cbc_cksum_ret)
1.754 + {
1.755 + fprintf(stdout,"bad return value (%08lX), should be %08lX\n",
1.756 + (unsigned long)cs,(unsigned long)cbc_cksum_ret);
1.757 + err=1;
1.758 + }
1.759 + if (memcmp(cret,cbc_cksum_data,8) != 0)
1.760 + {
1.761 + fprintf(stdout,"bad cbc_cksum block returned\n");
1.762 + err=1;
1.763 + }
1.764 +
1.765 + fprintf(stdout,"Doing quad_cksum\n");
1.766 + cs=des_quad_cksum(cbc_data,(des_cblock *)lqret,
1.767 + (long)strlen((char *)cbc_data),2,(des_cblock *)cbc_iv);
1.768 + if (cs != 0x70d7a63aL)
1.769 + {
1.770 + fprintf(stdout,"quad_cksum error, ret %08lx should be 70d7a63a\n",
1.771 + (unsigned long)cs);
1.772 + err=1;
1.773 + }
1.774 +#ifdef _CRAY
1.775 + if (lqret[0].a != 0x327eba8dL)
1.776 + {
1.777 + fprintf(stdout,"quad_cksum error, out[0] %08lx is not %08lx\n",
1.778 + (unsigned long)lqret[0].a,0x327eba8dUL);
1.779 + err=1;
1.780 + }
1.781 + if (lqret[0].b != 0x201a49ccL)
1.782 + {
1.783 + fprintf(stdout,"quad_cksum error, out[1] %08lx is not %08lx\n",
1.784 + (unsigned long)lqret[0].b,0x201a49ccUL);
1.785 + err=1;
1.786 + }
1.787 + if (lqret[1].a != 0x70d7a63aL)
1.788 + {
1.789 + fprintf(stdout,"quad_cksum error, out[2] %08lx is not %08lx\n",
1.790 + (unsigned long)lqret[1].a,0x70d7a63aUL);
1.791 + err=1;
1.792 + }
1.793 + if (lqret[1].b != 0x501c2c26L)
1.794 + {
1.795 + fprintf(stdout,"quad_cksum error, out[3] %08lx is not %08lx\n",
1.796 + (unsigned long)lqret[1].b,0x501c2c26UL);
1.797 + err=1;
1.798 + }
1.799 +#else
1.800 + if (lqret[0] != 0x327eba8dL)
1.801 + {
1.802 + fprintf(stdout,"quad_cksum error, out[0] %08lx is not %08lx\n",
1.803 + (unsigned long)lqret[0],0x327eba8dUL);
1.804 + err=1;
1.805 + }
1.806 + if (lqret[1] != 0x201a49ccL)
1.807 + {
1.808 + fprintf(stdout,"quad_cksum error, out[1] %08lx is not %08lx\n",
1.809 + (unsigned long)lqret[1],0x201a49ccUL);
1.810 + err=1;
1.811 + }
1.812 + if (lqret[2] != 0x70d7a63aL)
1.813 + {
1.814 + fprintf(stdout,"quad_cksum error, out[2] %08lx is not %08lx\n",
1.815 + (unsigned long)lqret[2],0x70d7a63aUL);
1.816 + err=1;
1.817 + }
1.818 + if (lqret[3] != 0x501c2c26L)
1.819 + {
1.820 + fprintf(stdout,"quad_cksum error, out[3] %08lx is not %08lx\n",
1.821 + (unsigned long)lqret[3],0x501c2c26UL);
1.822 + err=1;
1.823 + }
1.824 +#endif
1.825 +#endif
1.826 +
1.827 + fprintf(stdout,"input word alignment test");
1.828 + for (i=0; i<4; i++)
1.829 + {
1.830 + fprintf(stdout," %d",i);
1.831 + des_ncbc_encrypt(&(cbc_out[i]),cbc_in,
1.832 + strlen((char *)cbc_data)+1,ks,
1.833 + &cbc_iv,DES_ENCRYPT);
1.834 + }
1.835 + fprintf(stdout,"\noutput word alignment test");
1.836 + for (i=0; i<4; i++)
1.837 + {
1.838 + fprintf(stdout," %d",i);
1.839 + des_ncbc_encrypt(cbc_out,&(cbc_in[i]),
1.840 + strlen((char *)cbc_data)+1,ks,
1.841 + &cbc_iv,DES_ENCRYPT);
1.842 + }
1.843 + fprintf(stdout,"\n");
1.844 + fprintf(stdout,"fast crypt test ");
1.845 + str=crypt("testing","ef");
1.846 + if (strcmp("efGnQx2725bI2",str) != 0)
1.847 + {
1.848 + fprintf(stdout,"fast crypt error, %s should be efGnQx2725bI2\n",str);
1.849 + err=1;
1.850 + }
1.851 + str=crypt("bca76;23","yA");
1.852 + if (strcmp("yA1Rp/1hZXIJk",str) != 0)
1.853 + {
1.854 + fprintf(stdout,"fast crypt error, %s should be yA1Rp/1hZXIJk\n",str);
1.855 + err=1;
1.856 + }
1.857 +#ifdef OPENSSL_SYS_NETWARE
1.858 + if (err) fprintf(stdout,"ERROR: %d\n", err);
1.859 +#endif
1.860 + fprintf(stdout,"\n");
1.861 + fprintf(stdout,"Test case passed!");
1.862 +
1.863 + return(err);
1.864 + }
1.865 +#endif
1.866 +static char *pt(unsigned char *p)
1.867 + {
1.868 + static char bufs[10][20];
1.869 + static int bnum=0;
1.870 + char *ret;
1.871 + int i;
1.872 + static char *f="0123456789ABCDEF";
1.873 +
1.874 + ret= &(bufs[bnum++][0]);
1.875 + bnum%=10;
1.876 + for (i=0; i<8; i++)
1.877 + {
1.878 + ret[i*2]=f[(p[i]>>4)&0xf];
1.879 + ret[i*2+1]=f[p[i]&0xf];
1.880 + }
1.881 + ret[16]='\0';
1.882 + return(ret);
1.883 + }
1.884 +
1.885 +#ifndef LIBDES_LIT
1.886 +
1.887 +static int cfb_test(int bits, unsigned char *cfb_cipher)
1.888 + {
1.889 + des_key_schedule ks;
1.890 + int i,err=0;
1.891 +
1.892 + DES_set_key_checked(&cfb_key,&ks);
1.893 + memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
1.894 + des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp,
1.895 + DES_ENCRYPT);
1.896 + if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
1.897 + {
1.898 + err=1;
1.899 + fprintf(stdout,"cfb_encrypt encrypt error\n");
1.900 + for (i=0; i<24; i+=8)
1.901 + fprintf(stdout,"%s\n",pt(&(cfb_buf1[i])));
1.902 + }
1.903 + memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
1.904 + des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,&cfb_tmp,
1.905 + DES_DECRYPT);
1.906 + if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
1.907 + {
1.908 + err=1;
1.909 + fprintf(stdout,"cfb_encrypt decrypt error\n");
1.910 + for (i=0; i<24; i+=8)
1.911 + fprintf(stdout,"%s\n",pt(&(cfb_buf1[i])));
1.912 + }
1.913 + return(err);
1.914 + }
1.915 +
1.916 +static int cfb64_test(unsigned char *cfb_cipher)
1.917 + {
1.918 + des_key_schedule ks;
1.919 + int err=0,i,n;
1.920 +
1.921 + DES_set_key_checked(&cfb_key,&ks);
1.922 + memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
1.923 + n=0;
1.924 + des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT);
1.925 + des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks,
1.926 + &cfb_tmp,&n,DES_ENCRYPT);
1.927 + if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
1.928 + {
1.929 + err=1;
1.930 + fprintf(stdout,"cfb_encrypt encrypt error\n");
1.931 + for (i=0; i<24; i+=8)
1.932 + fprintf(stdout,"%s\n",pt(&(cfb_buf1[i])));
1.933 + }
1.934 + memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
1.935 + n=0;
1.936 + des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,&cfb_tmp,&n,DES_DECRYPT);
1.937 + des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
1.938 + sizeof(plain)-17,ks,&cfb_tmp,&n,DES_DECRYPT);
1.939 + if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
1.940 + {
1.941 + err=1;
1.942 + fprintf(stdout,"cfb_encrypt decrypt error\n");
1.943 + for (i=0; i<24; i+=8)
1.944 + fprintf(stdout,"%s\n",pt(&(cfb_buf2[i])));
1.945 + }
1.946 + return(err);
1.947 + }
1.948 +
1.949 +static int ede_cfb64_test(unsigned char *cfb_cipher)
1.950 + {
1.951 + des_key_schedule ks;
1.952 + int err=0,i,n;
1.953 +
1.954 + DES_set_key_checked(&cfb_key,&ks);
1.955 + memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
1.956 + n=0;
1.957 + des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n,
1.958 + DES_ENCRYPT);
1.959 + des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
1.960 + sizeof(plain)-12,ks,ks,ks,
1.961 + &cfb_tmp,&n,DES_ENCRYPT);
1.962 + if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
1.963 + {
1.964 + err=1;
1.965 + fprintf(stdout,"ede_cfb_encrypt encrypt error\n");
1.966 + for (i=0; i<24; i+=8)
1.967 + fprintf(stdout,"%s\n",pt(&(cfb_buf1[i])));
1.968 + }
1.969 + memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
1.970 + n=0;
1.971 + des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks,
1.972 + &cfb_tmp,&n,DES_DECRYPT);
1.973 + des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
1.974 + sizeof(plain)-17,ks,ks,ks,
1.975 + &cfb_tmp,&n,DES_DECRYPT);
1.976 + if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
1.977 + {
1.978 + err=1;
1.979 + fprintf(stdout,"ede_cfb_encrypt decrypt error\n");
1.980 + for (i=0; i<24; i+=8)
1.981 + fprintf(stdout,"%s\n",pt(&(cfb_buf2[i])));
1.982 + }
1.983 + return(err);
1.984 + }
1.985 +
1.986 +
1.987 +#endif