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. 8296341Sdelphij * 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). 15296341Sdelphij * 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. 22296341Sdelphij * 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 :-). 37296341Sdelphij * 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)" 40296341Sdelphij * 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. 52296341Sdelphij * 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 59296341Sdelphij/* 60296341Sdelphij * This has been a quickly hacked 'ideatest.c'. When I add tests for other 61296341Sdelphij * RC5 modes, more of the code will be uncommented. 62296341Sdelphij */ 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"); 74296341Sdelphij return (0); 7555714Skris} 7655714Skris#else 77296341Sdelphij# include <openssl/rc5.h> 7855714Skris 79296341Sdelphijstatic unsigned char RC5key[5][16] = { 80296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 81296341Sdelphij 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 82296341Sdelphij {0x91, 0x5f, 0x46, 0x19, 0xbe, 0x41, 0xb2, 0x51, 83296341Sdelphij 0x63, 0x55, 0xa5, 0x01, 0x10, 0xa9, 0xce, 0x91}, 84296341Sdelphij {0x78, 0x33, 0x48, 0xe7, 0x5a, 0xeb, 0x0f, 0x2f, 85296341Sdelphij 0xd7, 0xb1, 0x69, 0xbb, 0x8d, 0xc1, 0x67, 0x87}, 86296341Sdelphij {0xdc, 0x49, 0xdb, 0x13, 0x75, 0xa5, 0x58, 0x4f, 87296341Sdelphij 0x64, 0x85, 0xb4, 0x13, 0xb5, 0xf1, 0x2b, 0xaf}, 88296341Sdelphij {0x52, 0x69, 0xf1, 0x49, 0xd4, 0x1b, 0xa0, 0x15, 89296341Sdelphij 0x24, 0x97, 0x57, 0x4d, 0x7f, 0x15, 0x31, 0x25}, 90296341Sdelphij}; 9155714Skris 92296341Sdelphijstatic unsigned char RC5plain[5][8] = { 93296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 94296341Sdelphij {0x21, 0xA5, 0xDB, 0xEE, 0x15, 0x4B, 0x8F, 0x6D}, 95296341Sdelphij {0xF7, 0xC0, 0x13, 0xAC, 0x5B, 0x2B, 0x89, 0x52}, 96296341Sdelphij {0x2F, 0x42, 0xB3, 0xB7, 0x03, 0x69, 0xFC, 0x92}, 97296341Sdelphij {0x65, 0xC1, 0x78, 0xB2, 0x84, 0xD1, 0x97, 0xCC}, 98296341Sdelphij}; 9955714Skris 100296341Sdelphijstatic unsigned char RC5cipher[5][8] = { 101296341Sdelphij {0x21, 0xA5, 0xDB, 0xEE, 0x15, 0x4B, 0x8F, 0x6D}, 102296341Sdelphij {0xF7, 0xC0, 0x13, 0xAC, 0x5B, 0x2B, 0x89, 0x52}, 103296341Sdelphij {0x2F, 0x42, 0xB3, 0xB7, 0x03, 0x69, 0xFC, 0x92}, 104296341Sdelphij {0x65, 0xC1, 0x78, 0xB2, 0x84, 0xD1, 0x97, 0xCC}, 105296341Sdelphij {0xEB, 0x44, 0xE4, 0x15, 0xDA, 0x31, 0x98, 0x24}, 106296341Sdelphij}; 10755714Skris 108296341Sdelphij# define RC5_CBC_NUM 27 109296341Sdelphijstatic unsigned char rc5_cbc_cipher[RC5_CBC_NUM][8] = { 110296341Sdelphij {0x7a, 0x7b, 0xba, 0x4d, 0x79, 0x11, 0x1d, 0x1e}, 111296341Sdelphij {0x79, 0x7b, 0xba, 0x4d, 0x78, 0x11, 0x1d, 0x1e}, 112296341Sdelphij {0x7a, 0x7b, 0xba, 0x4d, 0x79, 0x11, 0x1d, 0x1f}, 113296341Sdelphij {0x7a, 0x7b, 0xba, 0x4d, 0x79, 0x11, 0x1d, 0x1f}, 114296341Sdelphij {0x8b, 0x9d, 0xed, 0x91, 0xce, 0x77, 0x94, 0xa6}, 115296341Sdelphij {0x2f, 0x75, 0x9f, 0xe7, 0xad, 0x86, 0xa3, 0x78}, 116296341Sdelphij {0xdc, 0xa2, 0x69, 0x4b, 0xf4, 0x0e, 0x07, 0x88}, 117296341Sdelphij {0xdc, 0xa2, 0x69, 0x4b, 0xf4, 0x0e, 0x07, 0x88}, 118296341Sdelphij {0xdc, 0xfe, 0x09, 0x85, 0x77, 0xec, 0xa5, 0xff}, 119296341Sdelphij {0x96, 0x46, 0xfb, 0x77, 0x63, 0x8f, 0x9c, 0xa8}, 120296341Sdelphij {0xb2, 0xb3, 0x20, 0x9d, 0xb6, 0x59, 0x4d, 0xa4}, 121296341Sdelphij {0x54, 0x5f, 0x7f, 0x32, 0xa5, 0xfc, 0x38, 0x36}, 122296341Sdelphij {0x82, 0x85, 0xe7, 0xc1, 0xb5, 0xbc, 0x74, 0x02}, 123296341Sdelphij {0xfc, 0x58, 0x6f, 0x92, 0xf7, 0x08, 0x09, 0x34}, 124296341Sdelphij {0xcf, 0x27, 0x0e, 0xf9, 0x71, 0x7f, 0xf7, 0xc4}, 125296341Sdelphij {0xe4, 0x93, 0xf1, 0xc1, 0xbb, 0x4d, 0x6e, 0x8c}, 126296341Sdelphij {0x5c, 0x4c, 0x04, 0x1e, 0x0f, 0x21, 0x7a, 0xc3}, 127296341Sdelphij {0x92, 0x1f, 0x12, 0x48, 0x53, 0x73, 0xb4, 0xf7}, 128296341Sdelphij {0x5b, 0xa0, 0xca, 0x6b, 0xbe, 0x7f, 0x5f, 0xad}, 129296341Sdelphij {0xc5, 0x33, 0x77, 0x1c, 0xd0, 0x11, 0x0e, 0x63}, 130296341Sdelphij {0x29, 0x4d, 0xdb, 0x46, 0xb3, 0x27, 0x8d, 0x60}, 131296341Sdelphij {0xda, 0xd6, 0xbd, 0xa9, 0xdf, 0xe8, 0xf7, 0xe8}, 132296341Sdelphij {0x97, 0xe0, 0x78, 0x78, 0x37, 0xed, 0x31, 0x7f}, 133296341Sdelphij {0x78, 0x75, 0xdb, 0xf6, 0x73, 0x8c, 0x64, 0x78}, 134296341Sdelphij {0x8f, 0x34, 0xc3, 0xc6, 0x81, 0xc9, 0x96, 0x95}, 135296341Sdelphij {0x7c, 0xb3, 0xf1, 0xdf, 0x34, 0xf9, 0x48, 0x11}, 136296341Sdelphij {0x7f, 0xd1, 0xa0, 0x23, 0xa5, 0xbb, 0xa2, 0x17}, 137296341Sdelphij}; 13855714Skris 139296341Sdelphijstatic unsigned char rc5_cbc_key[RC5_CBC_NUM][17] = { 140296341Sdelphij {1, 0x00}, 141296341Sdelphij {1, 0x00}, 142296341Sdelphij {1, 0x00}, 143296341Sdelphij {1, 0x00}, 144296341Sdelphij {1, 0x00}, 145296341Sdelphij {1, 0x11}, 146296341Sdelphij {1, 0x00}, 147296341Sdelphij {4, 0x00, 0x00, 0x00, 0x00}, 148296341Sdelphij {1, 0x00}, 149296341Sdelphij {1, 0x00}, 150296341Sdelphij {1, 0x00}, 151296341Sdelphij {1, 0x00}, 152296341Sdelphij {4, 0x01, 0x02, 0x03, 0x04}, 153296341Sdelphij {4, 0x01, 0x02, 0x03, 0x04}, 154296341Sdelphij {4, 0x01, 0x02, 0x03, 0x04}, 155296341Sdelphij {8, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 156296341Sdelphij {8, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 157296341Sdelphij {8, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 158296341Sdelphij {8, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 159296341Sdelphij {16, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 160296341Sdelphij 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 161296341Sdelphij {16, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 162296341Sdelphij 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 163296341Sdelphij {16, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 164296341Sdelphij 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 165296341Sdelphij {5, 0x01, 0x02, 0x03, 0x04, 0x05}, 166296341Sdelphij {5, 0x01, 0x02, 0x03, 0x04, 0x05}, 167296341Sdelphij {5, 0x01, 0x02, 0x03, 0x04, 0x05}, 168296341Sdelphij {5, 0x01, 0x02, 0x03, 0x04, 0x05}, 169296341Sdelphij {5, 0x01, 0x02, 0x03, 0x04, 0x05}, 170296341Sdelphij}; 17155714Skris 172296341Sdelphijstatic unsigned char rc5_cbc_plain[RC5_CBC_NUM][8] = { 173296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 174296341Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 175296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 176296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, 177296341Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 178296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 179296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 180296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 181296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 182296341Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 183296341Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 184296341Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 185296341Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 186296341Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 187296341Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 188296341Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 189296341Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 190296341Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 191296341Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 192296341Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 193296341Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 194296341Sdelphij {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}, 195296341Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 196296341Sdelphij {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 197296341Sdelphij {0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08}, 198296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 199296341Sdelphij {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x01}, 200296341Sdelphij}; 20155714Skris 202296341Sdelphijstatic int rc5_cbc_rounds[RC5_CBC_NUM] = { 203296341Sdelphij 0, 0, 0, 0, 0, 1, 2, 2, 204296341Sdelphij 8, 8, 12, 16, 8, 12, 16, 12, 205296341Sdelphij 8, 12, 16, 8, 12, 16, 12, 8, 206296341Sdelphij 8, 8, 8, 207296341Sdelphij}; 20855714Skris 209296341Sdelphijstatic unsigned char rc5_cbc_iv[RC5_CBC_NUM][8] = { 210296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 211296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 212296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, 213296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 214296341Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 215296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 216296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 217296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 218296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 219296341Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 220296341Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 221296341Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 222296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 223296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 224296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 225296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 226296341Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 227296341Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 228296341Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 229296341Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 230296341Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 231296341Sdelphij {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, 232296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 233296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 234296341Sdelphij {0x78, 0x75, 0xdb, 0xf6, 0x73, 0x8c, 0x64, 0x78}, 235296341Sdelphij {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 236296341Sdelphij {0x7c, 0xb3, 0xf1, 0xdf, 0x34, 0xf9, 0x48, 0x11}, 237296341Sdelphij}; 23855714Skris 23955714Skrisint main(int argc, char *argv[]) 240296341Sdelphij{ 241296341Sdelphij int i, n, err = 0; 242296341Sdelphij RC5_32_KEY key; 243296341Sdelphij unsigned char buf[8], buf2[8], ivb[8]; 24455714Skris 245296341Sdelphij for (n = 0; n < 5; n++) { 246296341Sdelphij RC5_32_set_key(&key, 16, &(RC5key[n][0]), 12); 24755714Skris 248296341Sdelphij RC5_32_ecb_encrypt(&(RC5plain[n][0]), buf, &key, RC5_ENCRYPT); 249296341Sdelphij if (memcmp(&(RC5cipher[n][0]), buf, 8) != 0) { 250296341Sdelphij printf("ecb RC5 error encrypting (%d)\n", n + 1); 251296341Sdelphij printf("got :"); 252296341Sdelphij for (i = 0; i < 8; i++) 253296341Sdelphij printf("%02X ", buf[i]); 254296341Sdelphij printf("\n"); 255296341Sdelphij printf("expected:"); 256296341Sdelphij for (i = 0; i < 8; i++) 257296341Sdelphij printf("%02X ", RC5cipher[n][i]); 258296341Sdelphij err = 20; 259296341Sdelphij printf("\n"); 260296341Sdelphij } 26155714Skris 262296341Sdelphij RC5_32_ecb_encrypt(buf, buf2, &key, RC5_DECRYPT); 263296341Sdelphij if (memcmp(&(RC5plain[n][0]), buf2, 8) != 0) { 264296341Sdelphij printf("ecb RC5 error decrypting (%d)\n", n + 1); 265296341Sdelphij printf("got :"); 266296341Sdelphij for (i = 0; i < 8; i++) 267296341Sdelphij printf("%02X ", buf2[i]); 268296341Sdelphij printf("\n"); 269296341Sdelphij printf("expected:"); 270296341Sdelphij for (i = 0; i < 8; i++) 271296341Sdelphij printf("%02X ", RC5plain[n][i]); 272296341Sdelphij printf("\n"); 273296341Sdelphij err = 3; 274296341Sdelphij } 275296341Sdelphij } 276296341Sdelphij if (err == 0) 277296341Sdelphij printf("ecb RC5 ok\n"); 27855714Skris 279296341Sdelphij for (n = 0; n < RC5_CBC_NUM; n++) { 280296341Sdelphij i = rc5_cbc_rounds[n]; 281296341Sdelphij if (i < 8) 282296341Sdelphij continue; 28355714Skris 284296341Sdelphij RC5_32_set_key(&key, rc5_cbc_key[n][0], &(rc5_cbc_key[n][1]), i); 28555714Skris 286296341Sdelphij memcpy(ivb, &(rc5_cbc_iv[n][0]), 8); 287296341Sdelphij RC5_32_cbc_encrypt(&(rc5_cbc_plain[n][0]), buf, 8, 288296341Sdelphij &key, &(ivb[0]), RC5_ENCRYPT); 28955714Skris 290296341Sdelphij if (memcmp(&(rc5_cbc_cipher[n][0]), buf, 8) != 0) { 291296341Sdelphij printf("cbc RC5 error encrypting (%d)\n", n + 1); 292296341Sdelphij printf("got :"); 293296341Sdelphij for (i = 0; i < 8; i++) 294296341Sdelphij printf("%02X ", buf[i]); 295296341Sdelphij printf("\n"); 296296341Sdelphij printf("expected:"); 297296341Sdelphij for (i = 0; i < 8; i++) 298296341Sdelphij printf("%02X ", rc5_cbc_cipher[n][i]); 299296341Sdelphij err = 30; 300296341Sdelphij printf("\n"); 301296341Sdelphij } 30255714Skris 303296341Sdelphij memcpy(ivb, &(rc5_cbc_iv[n][0]), 8); 304296341Sdelphij RC5_32_cbc_encrypt(buf, buf2, 8, &key, &(ivb[0]), RC5_DECRYPT); 305296341Sdelphij if (memcmp(&(rc5_cbc_plain[n][0]), buf2, 8) != 0) { 306296341Sdelphij printf("cbc RC5 error decrypting (%d)\n", n + 1); 307296341Sdelphij printf("got :"); 308296341Sdelphij for (i = 0; i < 8; i++) 309296341Sdelphij printf("%02X ", buf2[i]); 310296341Sdelphij printf("\n"); 311296341Sdelphij printf("expected:"); 312296341Sdelphij for (i = 0; i < 8; i++) 313296341Sdelphij printf("%02X ", rc5_cbc_plain[n][i]); 314296341Sdelphij printf("\n"); 315296341Sdelphij err = 3; 316296341Sdelphij } 317296341Sdelphij } 318296341Sdelphij if (err == 0) 319296341Sdelphij printf("cbc RC5 ok\n"); 32055714Skris 321296341Sdelphij EXIT(err); 322296341Sdelphij return (err); 323296341Sdelphij} 32455714Skris 325296341Sdelphij# ifdef undef 32655714Skrisstatic int cfb64_test(unsigned char *cfb_cipher) 327296341Sdelphij{ 328296341Sdelphij IDEA_KEY_SCHEDULE eks, dks; 329296341Sdelphij int err = 0, i, n; 33055714Skris 331296341Sdelphij idea_set_encrypt_key(cfb_key, &eks); 332296341Sdelphij idea_set_decrypt_key(&eks, &dks); 333296341Sdelphij memcpy(cfb_tmp, cfb_iv, 8); 334296341Sdelphij n = 0; 335296341Sdelphij idea_cfb64_encrypt(plain, cfb_buf1, (long)12, &eks, 336296341Sdelphij cfb_tmp, &n, IDEA_ENCRYPT); 337296341Sdelphij idea_cfb64_encrypt(&(plain[12]), &(cfb_buf1[12]), 338296341Sdelphij (long)CFB_TEST_SIZE - 12, &eks, 339296341Sdelphij cfb_tmp, &n, IDEA_ENCRYPT); 340296341Sdelphij if (memcmp(cfb_cipher, cfb_buf1, CFB_TEST_SIZE) != 0) { 341296341Sdelphij err = 1; 342296341Sdelphij printf("idea_cfb64_encrypt encrypt error\n"); 343296341Sdelphij for (i = 0; i < CFB_TEST_SIZE; i += 8) 344296341Sdelphij printf("%s\n", pt(&(cfb_buf1[i]))); 345296341Sdelphij } 346296341Sdelphij memcpy(cfb_tmp, cfb_iv, 8); 347296341Sdelphij n = 0; 348296341Sdelphij idea_cfb64_encrypt(cfb_buf1, cfb_buf2, (long)17, &eks, 349296341Sdelphij cfb_tmp, &n, IDEA_DECRYPT); 350296341Sdelphij idea_cfb64_encrypt(&(cfb_buf1[17]), &(cfb_buf2[17]), 351296341Sdelphij (long)CFB_TEST_SIZE - 17, &dks, 352296341Sdelphij cfb_tmp, &n, IDEA_DECRYPT); 353296341Sdelphij if (memcmp(plain, cfb_buf2, CFB_TEST_SIZE) != 0) { 354296341Sdelphij err = 1; 355296341Sdelphij printf("idea_cfb_encrypt decrypt error\n"); 356296341Sdelphij for (i = 0; i < 24; i += 8) 357296341Sdelphij printf("%s\n", pt(&(cfb_buf2[i]))); 358296341Sdelphij } 359296341Sdelphij return (err); 360296341Sdelphij} 36155714Skris 36255714Skrisstatic char *pt(unsigned char *p) 363296341Sdelphij{ 364296341Sdelphij static char bufs[10][20]; 365296341Sdelphij static int bnum = 0; 366296341Sdelphij char *ret; 367296341Sdelphij int i; 368296341Sdelphij static char *f = "0123456789ABCDEF"; 36955714Skris 370296341Sdelphij ret = &(bufs[bnum++][0]); 371296341Sdelphij bnum %= 10; 372296341Sdelphij for (i = 0; i < 8; i++) { 373296341Sdelphij ret[i * 2] = f[(p[i] >> 4) & 0xf]; 374296341Sdelphij ret[i * 2 + 1] = f[p[i] & 0xf]; 375296341Sdelphij } 376296341Sdelphij ret[16] = '\0'; 377296341Sdelphij return (ret); 378296341Sdelphij} 379296341Sdelphij 380296341Sdelphij# endif 38155714Skris#endif 382