69 int main(
int argc,
char *argv[])
71 printf(
"No RC2 support\n");
77 static unsigned char RC2key[4][16]={
78 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
79 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
80 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
81 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
82 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
83 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
84 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
85 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F},
88 static unsigned char RC2plain[4][8]={
89 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
90 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
91 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
92 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
95 static unsigned char RC2cipher[4][8]={
96 {0x1C,0x19,0x8A,0x83,0x8D,0xF0,0x28,0xB7},
97 {0x21,0x82,0x9C,0x78,0xA9,0xF9,0xC0,0x74},
98 {0x13,0xDB,0x35,0x17,0xD3,0x21,0x86,0x9E},
99 {0x50,0xDC,0x01,0x62,0xBD,0x75,0x7F,0x31},
103 unsigned char k[16]={
104 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04,
105 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08};
107 unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03};
108 unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5};
109 unsigned char out[80];
111 char *
text=
"Hello to all people out there";
113 static unsigned char cfb_key[16]={
114 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96,
115 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e,
117 static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd};
118 static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
119 #define CFB_TEST_SIZE 24
122 0x4e,0x6f,0x77,0x20,0x69,0x73,
123 0x20,0x74,0x68,0x65,0x20,0x74,
124 0x69,0x6d,0x65,0x20,0x66,0x6f,
125 0x72,0x20,0x61,0x6c,0x6c,0x20
128 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F,
129 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A,
130 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45
139 static char *
pt(
unsigned char *
p);
142 int main(
int argc,
char *argv[])
146 unsigned char buf[8],buf2[8];
153 if (memcmp(&(RC2cipher[n][0]),buf,8) != 0)
155 printf(
"ecb rc2 error encrypting\n");
158 printf(
"%02X ",buf[i]);
162 printf(
"%02X ",RC2cipher[n][i]);
168 if (memcmp(&(RC2plain[n][0]),buf2,8) != 0)
170 printf(
"ecb RC2 error decrypting\n");
173 printf(
"%02X ",buf[i]);
177 printf(
"%02X ",RC2plain[n][i]);
183 if (err == 0) printf(
"ecb RC2 ok\n");
190 if (memcmp(text,out,strlen(text)+1) != 0)
192 printf(
"cbc idea bad\n");
196 printf(
"cbc idea ok\n");
198 printf(
"cfb64 idea ");
199 if (cfb64_test(cfb_cipher64))
208 #ifdef OPENSSL_SYS_NETWARE
209 if (err) printf(
"ERROR: %d\n", err);
216 static int cfb64_test(
unsigned char *cfb_cipher)
223 memcpy(cfb_tmp,cfb_iv,8);
233 printf(
"idea_cfb64_encrypt encrypt error\n");
235 printf(
"%s\n",
pt(&(cfb_buf1[i])));
237 memcpy(cfb_tmp,cfb_iv,8);
242 (
long)CFB_TEST_SIZE-17,&dks,
244 if (memcmp(plain,cfb_buf2,CFB_TEST_SIZE) != 0)
247 printf(
"idea_cfb_encrypt decrypt error\n");
248 for (i=0; i<24; i+=8)
249 printf(
"%s\n",
pt(&(cfb_buf2[i])));
254 static char *
pt(
unsigned char *
p)
256 static char bufs[10][20];
260 static char *
f=
"0123456789ABCDEF";
262 ret= &(bufs[bnum++][0]);
266 ret[i*2]=f[(p[i]>>4)&0xf];
267 ret[i*2+1]=f[p[i]&0xf];