155714Skris/* crypto/rc5/rc5test.c */ 255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 355714Skris * All rights reserved. 455714Skris * 555714Skris * This package is an SSL implementation written 655714Skris * by Eric Young (eay@cryptsoft.com). 755714Skris * The implementation was written so as to conform with Netscapes SSL. 8296465Sdelphij * 955714Skris * This library is free for commercial and non-commercial use as long as 1055714Skris * the following conditions are aheared to. The following conditions 1155714Skris * apply to all code found in this distribution, be it the RC4, RSA, 1255714Skris * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1355714Skris * included with this distribution is covered by the same copyright terms 1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15296465Sdelphij * 1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in 1755714Skris * the code are not to be removed. 1855714Skris * If this package is used in a product, Eric Young should be given attribution 1955714Skris * as the author of the parts of the library used. 2055714Skris * This can be in the form of a textual message at program startup or 2155714Skris * in documentation (online or textual) provided with the package. 22296465Sdelphij * 2355714Skris * Redistribution and use in source and binary forms, with or without 2455714Skris * modification, are permitted provided that the following conditions 2555714Skris * are met: 2655714Skris * 1. Redistributions of source code must retain the copyright 2755714Skris * notice, this list of conditions and the following disclaimer. 2855714Skris * 2. Redistributions in binary form must reproduce the above copyright 2955714Skris * notice, this list of conditions and the following disclaimer in the 3055714Skris * documentation and/or other materials provided with the distribution. 3155714Skris * 3. All advertising materials mentioning features or use of this software 3255714Skris * must display the following acknowledgement: 3355714Skris * "This product includes cryptographic software written by 3455714Skris * Eric Young (eay@cryptsoft.com)" 3555714Skris * The word 'cryptographic' can be left out if the rouines from the library 3655714Skris * being used are not cryptographic related :-). 37296465Sdelphij * 4. If you include any Windows specific code (or a derivative thereof) from 3855714Skris * the apps directory (application code) you must include an acknowledgement: 3955714Skris * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40296465Sdelphij * 4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4455714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5155714Skris * SUCH DAMAGE. 52296465Sdelphij * 5355714Skris * The licence and distribution terms for any publically available version or 5455714Skris * derivative of this code cannot be changed. i.e. this code cannot simply be 5555714Skris * copied and put under another distribution licence 5655714Skris * [including the GNU Public Licence.] 5755714Skris */ 5855714Skris 59296465Sdelphij/* 60296465Sdelphij * This has been a quickly hacked 'ideatest.c'. When I add tests for other 61296465Sdelphij * RC5 modes, more of the code will be uncommented. 62296465Sdelphij */ 6355714Skris 6455714Skris#include <stdio.h> 6555714Skris#include <string.h> 6655714Skris#include <stdlib.h> 6755714Skris 68109998Smarkm#include "../e_os.h" 69109998Smarkm 70109998Smarkm#ifdef OPENSSL_NO_RC5 7155714Skrisint main(int argc, char *argv[]) 7255714Skris{ 7355714Skris printf("No RC5 support\n"); 74296465Sdelphij return (0); 7555714Skris} 7655714Skris#else 77296465Sdelphij# include <openssl/rc5.h> 7855714Skris 79296465Sdelphijstatic unsigned char RC5key[5][16] = { 80296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 81296465Sdelphij 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 82296465Sdelphij {0x91, 0x5f, 0x46, 0x19, 0xbe, 0x41, 0xb2, 0x51, 83296465Sdelphij 0x63, 0x55, 0xa5, 0x01, 0x10, 0xa9, 0xce, 0x91}, 84296465Sdelphij {0x78, 0x33, 0x48, 0xe7, 0x5a, 0xeb, 0x0f, 0x2f, 85296465Sdelphij 0xd7, 0xb1, 0x69, 0xbb, 0x8d, 0xc1, 0x67, 0x87}, 86296465Sdelphij {0xdc, 0x49, 0xdb, 0x13, 0x75, 0xa5, 0x58, 0x4f, 87296465Sdelphij 0x64, 0x85, 0xb4, 0x13, 0xb5, 0xf1, 0x2b, 0xaf}, 88296465Sdelphij {0x52, 0x69, 0xf1, 0x49, 0xd4, 0x1b, 0xa0, 0x15, 89296465Sdelphij 0x24, 0x97, 0x57, 0x4d, 0x7f, 0x15, 0x31, 0x25}, 90296465Sdelphij}; 9155714Skris 92296465Sdelphijstatic unsigned char RC5plain[5][8] = { 93296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 94296465Sdelphij {0x21, 0xA5, 0xDB, 0xEE, 0x15, 0x4B, 0x8F, 0x6D}, 95296465Sdelphij {0xF7, 0xC0, 0x13, 0xAC, 0x5B, 0x2B, 0x89, 0x52}, 96296465Sdelphij {0x2F, 0x42, 0xB3, 0xB7, 0x03, 0x69, 0xFC, 0x92}, 97296465Sdelphij {0x65, 0xC1, 0x78, 0xB2, 0x84, 0xD1, 0x97, 0xCC}, 98296465Sdelphij}; 9955714Skris 100296465Sdelphijstatic unsigned char RC5cipher[5][8] = { 101296465Sdelphij {0x21, 0xA5, 0xDB, 0xEE, 0x15, 0x4B, 0x8F, 0x6D}, 102296465Sdelphij {0xF7, 0xC0, 0x13, 0xAC, 0x5B, 0x2B, 0x89, 0x52}, 103296465Sdelphij {0x2F, 0x42, 0xB3, 0xB7, 0x03, 0x69, 0xFC, 0x92}, 104296465Sdelphij {0x65, 0xC1, 0x78, 0xB2, 0x84, 0xD1, 0x97, 0xCC}, 105296465Sdelphij {0xEB, 0x44, 0xE4, 0x15, 0xDA, 0x31, 0x98, 0x24}, 106296465Sdelphij}; 10755714Skris 108296465Sdelphij# define RC5_CBC_NUM 27 109296465Sdelphijstatic unsigned char rc5_cbc_cipher[RC5_CBC_NUM][8] = { 110296465Sdelphij {0x7a, 0x7b, 0xba, 0x4d, 0x79, 0x11, 0x1d, 0x1e}, 111296465Sdelphij {0x79, 0x7b, 0xba, 0x4d, 0x78, 0x11, 0x1d, 0x1e}, 112296465Sdelphij {0x7a, 0x7b, 0xba, 0x4d, 0x79, 0x11, 0x1d, 0x1f}, 113296465Sdelphij {0x7a, 0x7b, 0xba, 0x4d, 0x79, 0x11, 0x1d, 0x1f}, 114296465Sdelphij {0x8b, 0x9d, 0xed, 0x91, 0xce, 0x77, 0x94, 0xa6}, 115296465Sdelphij {0x2f, 0x75, 0x9f, 0xe7, 0xad, 0x86, 0xa3, 0x78}, 116296465Sdelphij {0xdc, 0xa2, 0x69, 0x4b, 0xf4, 0x0e, 0x07, 0x88}, 117296465Sdelphij {0xdc, 0xa2, 0x69, 0x4b, 0xf4, 0x0e, 0x07, 0x88}, 118296465Sdelphij {0xdc, 0xfe, 0x09, 0x85, 0x77, 0xec, 0xa5, 0xff}, 119296465Sdelphij {0x96, 0x46, 0xfb, 0x77, 0x63, 0x8f, 0x9c, 0xa8}, 120296465Sdelphij {0xb2, 0xb3, 0x20, 0x9d, 0xb6, 0x59, 0x4d, 0xa4}, 121296465Sdelphij {0x54, 0x5f, 0x7f, 0x32, 0xa5, 0xfc, 0x38, 0x36}, 122296465Sdelphij {0x82, 0x85, 0xe7, 0xc1, 0xb5, 0xbc, 0x74, 0x02}, 123296465Sdelphij {0xfc, 0x58, 0x6f, 0x92, 0xf7, 0x08, 0x09, 0x34}, 124296465Sdelphij {0xcf, 0x27, 0x0e, 0xf9, 0x71, 0x7f, 0xf7, 0xc4}, 125296465Sdelphij {0xe4, 0x93, 0xf1, 0xc1, 0xbb, 0x4d, 0x6e, 0x8c}, 126296465Sdelphij {0x5c, 0x4c, 0x04, 0x1e, 0x0f, 0x21, 0x7a, 0xc3}, 127296465Sdelphij {0x92, 0x1f, 0x12, 0x48, 0x53, 0x73, 0xb4, 0xf7}, 128296465Sdelphij {0x5b, 0xa0, 0xca, 0x6b, 0xbe, 0x7f, 0x5f, 0xad}, 129296465Sdelphij {0xc5, 0x33, 0x77, 0x1c, 0xd0, 0x11, 0x0e, 0x63}, 130296465Sdelphij {0x29, 0x4d, 0xdb, 0x46, 0xb3, 0x27, 0x8d, 0x60}, 131296465Sdelphij {0xda, 0xd6, 0xbd, 0xa9, 0xdf, 0xe8, 0xf7, 0xe8}, 132296465Sdelphij {0x97, 0xe0, 0x78, 0x78, 0x37, 0xed, 0x31, 0x7f}, 133296465Sdelphij {0x78, 0x75, 0xdb, 0xf6, 0x73, 0x8c, 0x64, 0x78}, 134296465Sdelphij {0x8f, 0x34, 0xc3, 0xc6, 0x81, 0xc9, 0x96, 0x95}, 135296465Sdelphij {0x7c, 0xb3, 0xf1, 0xdf, 0x34, 0xf9, 0x48, 0x11}, 136296465Sdelphij {0x7f, 0xd1, 0xa0, 0x23, 0xa5, 0xbb, 0xa2, 0x17}, 137296465Sdelphij}; 13855714Skris 139296465Sdelphijstatic unsigned char rc5_cbc_key[RC5_CBC_NUM][17] = { 140296465Sdelphij {1, 0x00}, 141296465Sdelphij {1, 0x00}, 142296465Sdelphij {1, 0x00}, 143296465Sdelphij {1, 0x00}, 144296465Sdelphij {1, 0x00}, 145296465Sdelphij {1, 0x11}, 146296465Sdelphij {1, 0x00}, 147296465Sdelphij {4, 0x00, 0x00, 0x00, 0x00}, 148296465Sdelphij {1, 0x00}, 149296465Sdelphij {1, 0x00}, 150296465Sdelphij {1, 0x00}, 151296465Sdelphij {1, 0x00}, 152296465Sdelphij {4, 0x01, 0x02, 0x03, 0x04}, 153296465Sdelphij {4, 0x01, 0x02, 0x03, 0x04}, 154296465Sdelphij {4, 0x01, 0x02, 0x03, 0x04}, 155296465Sdelphij {8, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 156296465Sdelphij {8, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 157296465Sdelphij {8, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 158296465Sdelphij {8, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 159296465Sdelphij {16, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 160296465Sdelphij 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 161296465Sdelphij {16, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 162296465Sdelphij 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 163296465Sdelphij {16, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 164296465Sdelphij 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 165296465Sdelphij {5, 0x01, 0x02, 0x03, 0x04, 0x05}, 166296465Sdelphij {5, 0x01, 0x02, 0x03, 0x04, 0x05}, 167296465Sdelphij {5, 0x01, 0x02, 0x03, 0x04, 0x05}, 168296465Sdelphij {5, 0x01, 0x02, 0x03, 0x04, 0x05}, 169296465Sdelphij {5, 0x01, 0x02, 0x03, 0x04, 0x05}, 170296465Sdelphij}; 17155714Skris 172296465Sdelphijstatic unsigned char rc5_cbc_plain[RC5_CBC_NUM][8] = { 173296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 174296465Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 175296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 176296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, 177296465Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 178296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 179296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 180296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 181296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 182296465Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 183296465Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 184296465Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 185296465Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 186296465Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 187296465Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 188296465Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 189296465Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 190296465Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 191296465Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 192296465Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 193296465Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 194296465Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 195296465Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 196296465Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 197296465Sdelphij {0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08}, 198296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 199296465Sdelphij {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x01}, 200296465Sdelphij}; 20155714Skris 202296465Sdelphijstatic int rc5_cbc_rounds[RC5_CBC_NUM] = { 203296465Sdelphij 0, 0, 0, 0, 0, 1, 2, 2, 204296465Sdelphij 8, 8, 12, 16, 8, 12, 16, 12, 205296465Sdelphij 8, 12, 16, 8, 12, 16, 12, 8, 206296465Sdelphij 8, 8, 8, 207296465Sdelphij}; 20855714Skris 209296465Sdelphijstatic unsigned char rc5_cbc_iv[RC5_CBC_NUM][8] = { 210296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 211296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 212296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, 213296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 214296465Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 215296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 216296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 217296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 218296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 219296465Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 220296465Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 221296465Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 222296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 223296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 224296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 225296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 226296465Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 227296465Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 228296465Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 229296465Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 230296465Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 231296465Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 232296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 233296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 234296465Sdelphij {0x78, 0x75, 0xdb, 0xf6, 0x73, 0x8c, 0x64, 0x78}, 235296465Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 236296465Sdelphij {0x7c, 0xb3, 0xf1, 0xdf, 0x34, 0xf9, 0x48, 0x11}, 237296465Sdelphij}; 23855714Skris 23955714Skrisint main(int argc, char *argv[]) 240296465Sdelphij{ 241296465Sdelphij int i, n, err = 0; 242296465Sdelphij RC5_32_KEY key; 243296465Sdelphij unsigned char buf[8], buf2[8], ivb[8]; 24455714Skris 245296465Sdelphij for (n = 0; n < 5; n++) { 246296465Sdelphij RC5_32_set_key(&key, 16, &(RC5key[n][0]), 12); 24755714Skris 248296465Sdelphij RC5_32_ecb_encrypt(&(RC5plain[n][0]), buf, &key, RC5_ENCRYPT); 249296465Sdelphij if (memcmp(&(RC5cipher[n][0]), buf, 8) != 0) { 250296465Sdelphij printf("ecb RC5 error encrypting (%d)\n", n + 1); 251296465Sdelphij printf("got :"); 252296465Sdelphij for (i = 0; i < 8; i++) 253296465Sdelphij printf("%02X ", buf[i]); 254296465Sdelphij printf("\n"); 255296465Sdelphij printf("expected:"); 256296465Sdelphij for (i = 0; i < 8; i++) 257296465Sdelphij printf("%02X ", RC5cipher[n][i]); 258296465Sdelphij err = 20; 259296465Sdelphij printf("\n"); 260296465Sdelphij } 26155714Skris 262296465Sdelphij RC5_32_ecb_encrypt(buf, buf2, &key, RC5_DECRYPT); 263296465Sdelphij if (memcmp(&(RC5plain[n][0]), buf2, 8) != 0) { 264296465Sdelphij printf("ecb RC5 error decrypting (%d)\n", n + 1); 265296465Sdelphij printf("got :"); 266296465Sdelphij for (i = 0; i < 8; i++) 267296465Sdelphij printf("%02X ", buf2[i]); 268296465Sdelphij printf("\n"); 269296465Sdelphij printf("expected:"); 270296465Sdelphij for (i = 0; i < 8; i++) 271296465Sdelphij printf("%02X ", RC5plain[n][i]); 272296465Sdelphij printf("\n"); 273296465Sdelphij err = 3; 274296465Sdelphij } 275296465Sdelphij } 276296465Sdelphij if (err == 0) 277296465Sdelphij printf("ecb RC5 ok\n"); 27855714Skris 279296465Sdelphij for (n = 0; n < RC5_CBC_NUM; n++) { 280296465Sdelphij i = rc5_cbc_rounds[n]; 281296465Sdelphij if (i < 8) 282296465Sdelphij continue; 28355714Skris 284296465Sdelphij RC5_32_set_key(&key, rc5_cbc_key[n][0], &(rc5_cbc_key[n][1]), i); 28555714Skris 286296465Sdelphij memcpy(ivb, &(rc5_cbc_iv[n][0]), 8); 287296465Sdelphij RC5_32_cbc_encrypt(&(rc5_cbc_plain[n][0]), buf, 8, 288296465Sdelphij &key, &(ivb[0]), RC5_ENCRYPT); 28955714Skris 290296465Sdelphij if (memcmp(&(rc5_cbc_cipher[n][0]), buf, 8) != 0) { 291296465Sdelphij printf("cbc RC5 error encrypting (%d)\n", n + 1); 292296465Sdelphij printf("got :"); 293296465Sdelphij for (i = 0; i < 8; i++) 294296465Sdelphij printf("%02X ", buf[i]); 295296465Sdelphij printf("\n"); 296296465Sdelphij printf("expected:"); 297296465Sdelphij for (i = 0; i < 8; i++) 298296465Sdelphij printf("%02X ", rc5_cbc_cipher[n][i]); 299296465Sdelphij err = 30; 300296465Sdelphij printf("\n"); 301296465Sdelphij } 30255714Skris 303296465Sdelphij memcpy(ivb, &(rc5_cbc_iv[n][0]), 8); 304296465Sdelphij RC5_32_cbc_encrypt(buf, buf2, 8, &key, &(ivb[0]), RC5_DECRYPT); 305296465Sdelphij if (memcmp(&(rc5_cbc_plain[n][0]), buf2, 8) != 0) { 306296465Sdelphij printf("cbc RC5 error decrypting (%d)\n", n + 1); 307296465Sdelphij printf("got :"); 308296465Sdelphij for (i = 0; i < 8; i++) 309296465Sdelphij printf("%02X ", buf2[i]); 310296465Sdelphij printf("\n"); 311296465Sdelphij printf("expected:"); 312296465Sdelphij for (i = 0; i < 8; i++) 313296465Sdelphij printf("%02X ", rc5_cbc_plain[n][i]); 314296465Sdelphij printf("\n"); 315296465Sdelphij err = 3; 316296465Sdelphij } 317296465Sdelphij } 318296465Sdelphij if (err == 0) 319296465Sdelphij printf("cbc RC5 ok\n"); 32055714Skris 321296465Sdelphij EXIT(err); 322296465Sdelphij return (err); 323296465Sdelphij} 32455714Skris 325296465Sdelphij# ifdef undef 32655714Skrisstatic int cfb64_test(unsigned char *cfb_cipher) 327296465Sdelphij{ 328296465Sdelphij IDEA_KEY_SCHEDULE eks, dks; 329296465Sdelphij int err = 0, i, n; 33055714Skris 331296465Sdelphij idea_set_encrypt_key(cfb_key, &eks); 332296465Sdelphij idea_set_decrypt_key(&eks, &dks); 333296465Sdelphij memcpy(cfb_tmp, cfb_iv, 8); 334296465Sdelphij n = 0; 335296465Sdelphij idea_cfb64_encrypt(plain, cfb_buf1, (long)12, &eks, 336296465Sdelphij cfb_tmp, &n, IDEA_ENCRYPT); 337296465Sdelphij idea_cfb64_encrypt(&(plain[12]), &(cfb_buf1[12]), 338296465Sdelphij (long)CFB_TEST_SIZE - 12, &eks, 339296465Sdelphij cfb_tmp, &n, IDEA_ENCRYPT); 340296465Sdelphij if (memcmp(cfb_cipher, cfb_buf1, CFB_TEST_SIZE) != 0) { 341296465Sdelphij err = 1; 342296465Sdelphij printf("idea_cfb64_encrypt encrypt error\n"); 343296465Sdelphij for (i = 0; i < CFB_TEST_SIZE; i += 8) 344296465Sdelphij printf("%s\n", pt(&(cfb_buf1[i]))); 345296465Sdelphij } 346296465Sdelphij memcpy(cfb_tmp, cfb_iv, 8); 347296465Sdelphij n = 0; 348296465Sdelphij idea_cfb64_encrypt(cfb_buf1, cfb_buf2, (long)17, &eks, 349296465Sdelphij cfb_tmp, &n, IDEA_DECRYPT); 350296465Sdelphij idea_cfb64_encrypt(&(cfb_buf1[17]), &(cfb_buf2[17]), 351296465Sdelphij (long)CFB_TEST_SIZE - 17, &dks, 352296465Sdelphij cfb_tmp, &n, IDEA_DECRYPT); 353296465Sdelphij if (memcmp(plain, cfb_buf2, CFB_TEST_SIZE) != 0) { 354296465Sdelphij err = 1; 355296465Sdelphij printf("idea_cfb_encrypt decrypt error\n"); 356296465Sdelphij for (i = 0; i < 24; i += 8) 357296465Sdelphij printf("%s\n", pt(&(cfb_buf2[i]))); 358296465Sdelphij } 359296465Sdelphij return (err); 360296465Sdelphij} 36155714Skris 36255714Skrisstatic char *pt(unsigned char *p) 363296465Sdelphij{ 364296465Sdelphij static char bufs[10][20]; 365296465Sdelphij static int bnum = 0; 366296465Sdelphij char *ret; 367296465Sdelphij int i; 368296465Sdelphij static char *f = "0123456789ABCDEF"; 36955714Skris 370296465Sdelphij ret = &(bufs[bnum++][0]); 371296465Sdelphij bnum %= 10; 372296465Sdelphij for (i = 0; i < 8; i++) { 373296465Sdelphij ret[i * 2] = f[(p[i] >> 4) & 0xf]; 374296465Sdelphij ret[i * 2 + 1] = f[p[i] & 0xf]; 375296465Sdelphij } 376296465Sdelphij ret[16] = '\0'; 377296465Sdelphij return (ret); 378296465Sdelphij} 379296465Sdelphij 380296465Sdelphij# endif 38155714Skris#endif 382