diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/bf/bftest.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/src/lib/libcrypto/bf/bftest.c b/src/lib/libcrypto/bf/bftest.c index 9266cf813a..6ecd2609a9 100644 --- a/src/lib/libcrypto/bf/bftest.c +++ b/src/lib/libcrypto/bf/bftest.c | |||
| @@ -62,7 +62,19 @@ | |||
| 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" | 65 | |
| 66 | #ifdef NO_BF | ||
| 67 | int 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 | ||
| 66 | 78 | ||
| 67 | char *bf_key[2]={ | 79 | char *bf_key[2]={ |
| 68 | "abcdefghijklmnopqrstuvwxyz", | 80 | "abcdefghijklmnopqrstuvwxyz", |
| @@ -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 | ||
| 256 | static int test(void ); | 267 | static int test(void ); |
| 257 | static int print_test_data(void ); | 268 | static int print_test_data(void ); |
| 258 | #else | 269 | int main(int argc, char *argv[]) |
| 259 | static int test(); | ||
| 260 | static int print_test_data(); | ||
| 261 | #endif | ||
| 262 | |||
| 263 | int main(argc,argv) | ||
| 264 | int argc; | ||
| 265 | char *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 | ||
| 278 | static int print_test_data() | 282 | static 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 | ||
| 345 | static int test() | 349 | static 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 | } |
| @@ -519,3 +530,4 @@ static int test() | |||
| 519 | 530 | ||
| 520 | return(err); | 531 | return(err); |
| 521 | } | 532 | } |
| 533 | #endif | ||
