summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bf/bftest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bf/bftest.c')
-rw-r--r--src/lib/libcrypto/bf/bftest.c61
1 files changed, 37 insertions, 24 deletions
diff --git a/src/lib/libcrypto/bf/bftest.c b/src/lib/libcrypto/bf/bftest.c
index 9266cf813a..09895f2542 100644
--- a/src/lib/libcrypto/bf/bftest.c
+++ b/src/lib/libcrypto/bf/bftest.c
@@ -62,20 +62,32 @@
62#include <stdio.h> 62#include <stdio.h>
63#include <string.h> 63#include <string.h>
64#include <stdlib.h> 64#include <stdlib.h>
65#include "blowfish.h"
66 65
67char *bf_key[2]={ 66#ifdef OPENSSL_NO_BF
67int main(int argc, char *argv[])
68{
69 printf("No BF support\n");
70 return(0);
71}
72#else
73#include <openssl/blowfish.h>
74
75#ifdef CHARSET_EBCDIC
76#include <openssl/ebcdic.h>
77#endif
78
79static char *bf_key[2]={
68 "abcdefghijklmnopqrstuvwxyz", 80 "abcdefghijklmnopqrstuvwxyz",
69 "Who is John Galt?" 81 "Who is John Galt?"
70 }; 82 };
71 83
72/* big endian */ 84/* big endian */
73BF_LONG bf_plain[2][2]={ 85static BF_LONG bf_plain[2][2]={
74 {0x424c4f57L,0x46495348L}, 86 {0x424c4f57L,0x46495348L},
75 {0xfedcba98L,0x76543210L} 87 {0xfedcba98L,0x76543210L}
76 }; 88 };
77 89
78BF_LONG bf_cipher[2][2]={ 90static BF_LONG bf_cipher[2][2]={
79 {0x324ed0feL,0xf413a203L}, 91 {0x324ed0feL,0xf413a203L},
80 {0xcc91732bL,0x8022f684L} 92 {0xcc91732bL,0x8022f684L}
81 }; 93 };
@@ -216,16 +228,16 @@ static unsigned char ofb64_ok[]={
216 0x63,0xC2,0xCF,0x80,0xDA}; 228 0x63,0xC2,0xCF,0x80,0xDA};
217 229
218#define KEY_TEST_NUM 25 230#define KEY_TEST_NUM 25
219unsigned char key_test[KEY_TEST_NUM]={ 231static unsigned char key_test[KEY_TEST_NUM]={
220 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87, 232 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87,
221 0x78,0x69,0x5a,0x4b,0x3c,0x2d,0x1e,0x0f, 233 0x78,0x69,0x5a,0x4b,0x3c,0x2d,0x1e,0x0f,
222 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77, 234 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
223 0x88}; 235 0x88};
224 236
225unsigned char key_data[8]= 237static unsigned char key_data[8]=
226 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}; 238 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10};
227 239
228unsigned char key_out[KEY_TEST_NUM][8]={ 240static unsigned char key_out[KEY_TEST_NUM][8]={
229 {0xF9,0xAD,0x59,0x7C,0x49,0xDB,0x00,0x5E}, 241 {0xF9,0xAD,0x59,0x7C,0x49,0xDB,0x00,0x5E},
230 {0xE9,0x1D,0x21,0xC1,0xD9,0x61,0xA6,0xD6}, 242 {0xE9,0x1D,0x21,0xC1,0xD9,0x61,0xA6,0xD6},
231 {0xE9,0xC2,0xB7,0x0A,0x1B,0xC6,0x5C,0xF3}, 243 {0xE9,0xC2,0xB7,0x0A,0x1B,0xC6,0x5C,0xF3},
@@ -252,17 +264,9 @@ unsigned char key_out[KEY_TEST_NUM][8]={
252 {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80}, 264 {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80},
253 }; 265 };
254 266
255#ifndef NOPROTO
256static int test(void ); 267static int test(void );
257static int print_test_data(void ); 268static int print_test_data(void );
258#else 269int main(int argc, char *argv[])
259static int test();
260static int print_test_data();
261#endif
262
263int main(argc,argv)
264int argc;
265char *argv[];
266 { 270 {
267 int ret; 271 int ret;
268 272
@@ -275,7 +279,7 @@ char *argv[];
275 return(0); 279 return(0);
276 } 280 }
277 281
278static int print_test_data() 282static int print_test_data(void)
279 { 283 {
280 unsigned int i,j; 284 unsigned int i,j;
281 285
@@ -304,7 +308,7 @@ static int print_test_data()
304 printf("c="); 308 printf("c=");
305 for (j=0; j<8; j++) 309 for (j=0; j<8; j++)
306 printf("%02X",key_out[i][j]); 310 printf("%02X",key_out[i][j]);
307 printf(" k[%2d]=",i+1); 311 printf(" k[%2u]=",i+1);
308 for (j=0; j<i+1; j++) 312 for (j=0; j<i+1; j++)
309 printf("%02X",key_test[j]); 313 printf("%02X",key_test[j]);
310 printf("\n"); 314 printf("\n");
@@ -342,7 +346,7 @@ static int print_test_data()
342 return(0); 346 return(0);
343 } 347 }
344 348
345static int test() 349static int test(void)
346 { 350 {
347 unsigned char cbc_in[40],cbc_out[40],iv[8]; 351 unsigned char cbc_in[40],cbc_out[40],iv[8];
348 int i,n,err=0; 352 int i,n,err=0;
@@ -351,9 +355,16 @@ static int test()
351 unsigned char out[8]; 355 unsigned char out[8];
352 BF_LONG len; 356 BF_LONG len;
353 357
358#ifdef CHARSET_EBCDIC
359 ebcdic2ascii(cbc_data, cbc_data, strlen(cbc_data));
360#endif
361
354 printf("testing blowfish in raw ecb mode\n"); 362 printf("testing blowfish in raw ecb mode\n");
355 for (n=0; n<2; n++) 363 for (n=0; n<2; n++)
356 { 364 {
365#ifdef CHARSET_EBCDIC
366 ebcdic2ascii(bf_key[n], bf_key[n], strlen(bf_key[n]));
367#endif
357 BF_set_key(&key,strlen(bf_key[n]),(unsigned char *)bf_key[n]); 368 BF_set_key(&key,strlen(bf_key[n]),(unsigned char *)bf_key[n]);
358 369
359 data[0]=bf_plain[n][0]; 370 data[0]=bf_plain[n][0];
@@ -364,11 +375,11 @@ static int test()
364 printf("BF_encrypt error encrypting\n"); 375 printf("BF_encrypt error encrypting\n");
365 printf("got :"); 376 printf("got :");
366 for (i=0; i<2; i++) 377 for (i=0; i<2; i++)
367 printf("%08lX ",data[i]); 378 printf("%08lX ",(unsigned long)data[i]);
368 printf("\n"); 379 printf("\n");
369 printf("expected:"); 380 printf("expected:");
370 for (i=0; i<2; i++) 381 for (i=0; i<2; i++)
371 printf("%08lX ",bf_cipher[n][i]); 382 printf("%08lX ",(unsigned long)bf_cipher[n][i]);
372 err=1; 383 err=1;
373 printf("\n"); 384 printf("\n");
374 } 385 }
@@ -379,11 +390,11 @@ static int test()
379 printf("BF_encrypt error decrypting\n"); 390 printf("BF_encrypt error decrypting\n");
380 printf("got :"); 391 printf("got :");
381 for (i=0; i<2; i++) 392 for (i=0; i<2; i++)
382 printf("%08lX ",data[i]); 393 printf("%08lX ",(unsigned long)data[i]);
383 printf("\n"); 394 printf("\n");
384 printf("expected:"); 395 printf("expected:");
385 for (i=0; i<2; i++) 396 for (i=0; i<2; i++)
386 printf("%08lX ",bf_plain[n][i]); 397 printf("%08lX ",(unsigned long)bf_plain[n][i]);
387 printf("\n"); 398 printf("\n");
388 err=1; 399 err=1;
389 } 400 }
@@ -431,7 +442,8 @@ static int test()
431 { 442 {
432 BF_set_key(&key,n,key_test); 443 BF_set_key(&key,n,key_test);
433 BF_ecb_encrypt(key_data,out,&key,BF_ENCRYPT); 444 BF_ecb_encrypt(key_data,out,&key,BF_ENCRYPT);
434 if (memcmp(out,&(key_out[n-1][0]),8) != 0) 445 /* mips-sgi-irix6.5-gcc vv -mabi=64 bug workaround */
446 if (memcmp(out,&(key_out[i=n-1][0]),8) != 0)
435 { 447 {
436 printf("blowfish setkey error\n"); 448 printf("blowfish setkey error\n");
437 err=1; 449 err=1;
@@ -519,3 +531,4 @@ static int test()
519 531
520 return(err); 532 return(err);
521 } 533 }
534#endif