1656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* crypto/rc2/rc2test.c */ 2656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * All rights reserved. 4656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 5656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * This package is an SSL implementation written 6656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * by Eric Young (eay@cryptsoft.com). 7656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * The implementation was written so as to conform with Netscapes SSL. 8656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 9656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * This library is free for commercial and non-commercial use as long as 10656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * the following conditions are aheared to. The following conditions 11656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * apply to all code found in this distribution, be it the RC4, RSA, 12656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * included with this distribution is covered by the same copyright terms 14656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 16656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Copyright remains Eric Young's, and as such any Copyright notices in 17656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * the code are not to be removed. 18656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * If this package is used in a product, Eric Young should be given attribution 19656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * as the author of the parts of the library used. 20656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * This can be in the form of a textual message at program startup or 21656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * in documentation (online or textual) provided with the package. 22656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 23656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Redistribution and use in source and binary forms, with or without 24656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * modification, are permitted provided that the following conditions 25656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * are met: 26656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 1. Redistributions of source code must retain the copyright 27656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * notice, this list of conditions and the following disclaimer. 28656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright 29656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * notice, this list of conditions and the following disclaimer in the 30656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * documentation and/or other materials provided with the distribution. 31656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 3. All advertising materials mentioning features or use of this software 32656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * must display the following acknowledgement: 33656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * "This product includes cryptographic software written by 34656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Eric Young (eay@cryptsoft.com)" 35656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * The word 'cryptographic' can be left out if the rouines from the library 36656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * being used are not cryptographic related :-). 37656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 4. If you include any Windows specific code (or a derivative thereof) from 38656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * the apps directory (application code) you must include an acknowledgement: 39656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 41656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * SUCH DAMAGE. 52656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 53656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * The licence and distribution terms for any publically available version or 54656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * derivative of this code cannot be changed. i.e. this code cannot simply be 55656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * copied and put under another distribution licence 56656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * [including the GNU Public Licence.] 57656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */ 58656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 59656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* This has been a quickly hacked 'ideatest.c'. When I add tests for other 60656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * RC2 modes, more of the code will be uncommented. */ 61656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 62656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <stdio.h> 63656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <string.h> 64656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <stdlib.h> 65656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 66656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include "../e_os.h" 67656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 68656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifdef OPENSSL_NO_RC2 69656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint main(int argc, char *argv[]) 70656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project{ 71656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("No RC2 support\n"); 72656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return(0); 73656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project} 74656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#else 75656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <openssl/rc2.h> 76656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 77656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic unsigned char RC2key[4][16]={ 78656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 79656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 80656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 81656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, 82656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 83656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 84656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, 85656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F}, 86656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project }; 87656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 88656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic unsigned char RC2plain[4][8]={ 89656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 90656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 91656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, 92656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 93656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project }; 94656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 95656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic unsigned char RC2cipher[4][8]={ 96656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project {0x1C,0x19,0x8A,0x83,0x8D,0xF0,0x28,0xB7}, 97656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project {0x21,0x82,0x9C,0x78,0xA9,0xF9,0xC0,0x74}, 98656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project {0x13,0xDB,0x35,0x17,0xD3,0x21,0x86,0x9E}, 99656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project {0x50,0xDC,0x01,0x62,0xBD,0x75,0x7F,0x31}, 100656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project }; 101656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/************/ 102656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifdef undef 103656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectunsigned char k[16]={ 104656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04, 105656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08}; 106656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 107656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectunsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03}; 108656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectunsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5}; 109656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectunsigned char out[80]; 110656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 111656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectchar *text="Hello to all people out there"; 112656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 113656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic unsigned char cfb_key[16]={ 114656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96, 115656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e, 116656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project }; 117656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd}; 118656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; 119656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define CFB_TEST_SIZE 24 120656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic unsigned char plain[CFB_TEST_SIZE]= 121656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 122656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x4e,0x6f,0x77,0x20,0x69,0x73, 123656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x20,0x74,0x68,0x65,0x20,0x74, 124656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x69,0x6d,0x65,0x20,0x66,0x6f, 125656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x72,0x20,0x61,0x6c,0x6c,0x20 126656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project }; 127656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic unsigned char cfb_cipher64[CFB_TEST_SIZE]={ 128656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F, 129656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A, 130656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45 131656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 132656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, 133656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, 134656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ 135656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project }; 136656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 137656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 138656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/*static int cfb64_test(unsigned char *cfb_cipher);*/ 139656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic char *pt(unsigned char *p); 140656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif 141656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 142656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint main(int argc, char *argv[]) 143656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 144656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project int i,n,err=0; 145656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project RC2_KEY key; 146656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project unsigned char buf[8],buf2[8]; 147656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 148656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project for (n=0; n<4; n++) 149656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 150656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project RC2_set_key(&key,16,&(RC2key[n][0]),0 /* or 1024 */); 151656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 152656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project RC2_ecb_encrypt(&(RC2plain[n][0]),buf,&key,RC2_ENCRYPT); 153656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (memcmp(&(RC2cipher[n][0]),buf,8) != 0) 154656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 155656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("ecb rc2 error encrypting\n"); 156656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("got :"); 157656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project for (i=0; i<8; i++) 158656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("%02X ",buf[i]); 159656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("\n"); 160656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("expected:"); 161656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project for (i=0; i<8; i++) 162656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("%02X ",RC2cipher[n][i]); 163656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project err=20; 164656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("\n"); 165656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 166656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 167656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project RC2_ecb_encrypt(buf,buf2,&key,RC2_DECRYPT); 168656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (memcmp(&(RC2plain[n][0]),buf2,8) != 0) 169656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 170656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("ecb RC2 error decrypting\n"); 171656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("got :"); 172656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project for (i=0; i<8; i++) 173656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("%02X ",buf[i]); 174656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("\n"); 175656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("expected:"); 176656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project for (i=0; i<8; i++) 177656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("%02X ",RC2plain[n][i]); 178656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("\n"); 179656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project err=3; 180656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 181656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 182656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 183656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (err == 0) printf("ecb RC2 ok\n"); 184656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifdef undef 185656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project memcpy(iv,k,8); 186656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project idea_cbc_encrypt((unsigned char *)text,out,strlen(text)+1,&key,iv,1); 187656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project memcpy(iv,k,8); 188656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project idea_cbc_encrypt(out,out,8,&dkey,iv,0); 189656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project idea_cbc_encrypt(&(out[8]),&(out[8]),strlen(text)+1-8,&dkey,iv,0); 190656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (memcmp(text,out,strlen(text)+1) != 0) 191656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 192656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("cbc idea bad\n"); 193656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project err=4; 194656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 195656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project else 196656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("cbc idea ok\n"); 197656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 198656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("cfb64 idea "); 199656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (cfb64_test(cfb_cipher64)) 200656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 201656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("bad\n"); 202656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project err=5; 203656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 204656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project else 205656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("ok\n"); 206656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif 207656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 208656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifdef OPENSSL_SYS_NETWARE 209656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (err) printf("ERROR: %d\n", err); 210656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif 211656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project EXIT(err); 212656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return(err); 213656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 214656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 215656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifdef undef 216656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic int cfb64_test(unsigned char *cfb_cipher) 217656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 218656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project IDEA_KEY_SCHEDULE eks,dks; 219656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project int err=0,i,n; 220656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 221656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project idea_set_encrypt_key(cfb_key,&eks); 222656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project idea_set_decrypt_key(&eks,&dks); 223656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project memcpy(cfb_tmp,cfb_iv,8); 224656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project n=0; 225656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks, 226656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project cfb_tmp,&n,IDEA_ENCRYPT); 227656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), 228656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project (long)CFB_TEST_SIZE-12,&eks, 229656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project cfb_tmp,&n,IDEA_ENCRYPT); 230656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0) 231656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 232656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project err=1; 233656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("idea_cfb64_encrypt encrypt error\n"); 234656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project for (i=0; i<CFB_TEST_SIZE; i+=8) 235656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("%s\n",pt(&(cfb_buf1[i]))); 236656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 237656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project memcpy(cfb_tmp,cfb_iv,8); 238656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project n=0; 239656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project idea_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,&eks, 240656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project cfb_tmp,&n,IDEA_DECRYPT); 241656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project idea_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), 242656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project (long)CFB_TEST_SIZE-17,&dks, 243656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project cfb_tmp,&n,IDEA_DECRYPT); 244656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (memcmp(plain,cfb_buf2,CFB_TEST_SIZE) != 0) 245656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 246656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project err=1; 247656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("idea_cfb_encrypt decrypt error\n"); 248656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project for (i=0; i<24; i+=8) 249656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project printf("%s\n",pt(&(cfb_buf2[i]))); 250656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 251656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return(err); 252656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 253656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 254656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic char *pt(unsigned char *p) 255656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 256656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project static char bufs[10][20]; 257656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project static int bnum=0; 258656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project char *ret; 259656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project int i; 260656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project static char *f="0123456789ABCDEF"; 261656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 262656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ret= &(bufs[bnum++][0]); 263656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project bnum%=10; 264656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project for (i=0; i<8; i++) 265656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 266656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ret[i*2]=f[(p[i]>>4)&0xf]; 267656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ret[i*2+1]=f[p[i]&0xf]; 268656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 269656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ret[16]='\0'; 270656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return(ret); 271656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 272656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 273656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif 274656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif 275