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