diff options
Diffstat (limited to 'src/lib/libcrypto/des/destest.c')
-rw-r--r-- | src/lib/libcrypto/des/destest.c | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c index 5a04fc9298..9ad4ecb072 100644 --- a/src/lib/libcrypto/des/destest.c +++ b/src/lib/libcrypto/des/destest.c | |||
@@ -234,7 +234,7 @@ static unsigned char cipher_ecb2[NUM_TESTS-1][8]={ | |||
234 | {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}}; | 234 | {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}}; |
235 | 235 | ||
236 | static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; | 236 | static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; |
237 | static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; | 237 | static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86}; |
238 | static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; | 238 | static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; |
239 | static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; | 239 | static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; |
240 | /* Changed the following text constant to binary so it will work on ebcdic | 240 | /* Changed the following text constant to binary so it will work on ebcdic |
@@ -254,12 +254,24 @@ static unsigned char cbc_ok[32]={ | |||
254 | 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68, | 254 | 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68, |
255 | 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; | 255 | 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; |
256 | 256 | ||
257 | #ifdef SCREW_THE_PARITY | ||
258 | #error "SCREW_THE_PARITY is not ment to be defined." | ||
259 | #error "Original vectors are preserved for reference only." | ||
260 | static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; | ||
257 | static unsigned char xcbc_ok[32]={ | 261 | static unsigned char xcbc_ok[32]={ |
258 | 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48, | 262 | 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48, |
259 | 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD, | 263 | 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD, |
260 | 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76, | 264 | 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76, |
261 | 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2, | 265 | 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2, |
262 | }; | 266 | }; |
267 | #else | ||
268 | static unsigned char xcbc_ok[32]={ | ||
269 | 0x84,0x6B,0x29,0x14,0x85,0x1E,0x9A,0x29, | ||
270 | 0x54,0x73,0x2F,0x8A,0xA0,0xA6,0x11,0xC1, | ||
271 | 0x15,0xCD,0xC2,0xD7,0x95,0x1B,0x10,0x53, | ||
272 | 0xA6,0x3C,0x5E,0x03,0xB2,0x1A,0xA3,0xC4, | ||
273 | }; | ||
274 | #endif | ||
263 | 275 | ||
264 | static unsigned char cbc3_ok[32]={ | 276 | static unsigned char cbc3_ok[32]={ |
265 | 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0, | 277 | 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0, |
@@ -309,8 +321,8 @@ static unsigned char ofb_cipher[24]= | |||
309 | 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3 | 321 | 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3 |
310 | }; | 322 | }; |
311 | 323 | ||
312 | DES_LONG cbc_cksum_ret=0xB462FEF7L; | 324 | static DES_LONG cbc_cksum_ret=0xB462FEF7L; |
313 | unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; | 325 | static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; |
314 | 326 | ||
315 | static char *pt(unsigned char *p); | 327 | static char *pt(unsigned char *p); |
316 | static int cfb_test(int bits, unsigned char *cfb_cipher); | 328 | static int cfb_test(int bits, unsigned char *cfb_cipher); |
@@ -331,17 +343,17 @@ int main(int argc, char *argv[]) | |||
331 | 343 | ||
332 | #ifndef NO_DESCBCM | 344 | #ifndef NO_DESCBCM |
333 | printf("Doing cbcm\n"); | 345 | printf("Doing cbcm\n"); |
334 | if ((j=des_key_sched(&cbc_key,ks)) != 0) | 346 | if ((j=des_set_key_checked(&cbc_key,ks)) != 0) |
335 | { | 347 | { |
336 | printf("Key error %d\n",j); | 348 | printf("Key error %d\n",j); |
337 | err=1; | 349 | err=1; |
338 | } | 350 | } |
339 | if ((j=des_key_sched(&cbc2_key,ks2)) != 0) | 351 | if ((j=des_set_key_checked(&cbc2_key,ks2)) != 0) |
340 | { | 352 | { |
341 | printf("Key error %d\n",j); | 353 | printf("Key error %d\n",j); |
342 | err=1; | 354 | err=1; |
343 | } | 355 | } |
344 | if ((j=des_key_sched(&cbc3_key,ks3)) != 0) | 356 | if ((j=des_set_key_checked(&cbc3_key,ks3)) != 0) |
345 | { | 357 | { |
346 | printf("Key error %d\n",j); | 358 | printf("Key error %d\n",j); |
347 | err=1; | 359 | err=1; |
@@ -385,11 +397,7 @@ int main(int argc, char *argv[]) | |||
385 | printf("Doing ecb\n"); | 397 | printf("Doing ecb\n"); |
386 | for (i=0; i<NUM_TESTS; i++) | 398 | for (i=0; i<NUM_TESTS; i++) |
387 | { | 399 | { |
388 | if ((j=des_key_sched(&key_data[i],ks)) != 0) | 400 | des_set_key_unchecked(&key_data[i],ks); |
389 | { | ||
390 | printf("Key error %2d:%d\n",i+1,j); | ||
391 | err=1; | ||
392 | } | ||
393 | memcpy(in,plain_data[i],8); | 401 | memcpy(in,plain_data[i],8); |
394 | memset(out,0,8); | 402 | memset(out,0,8); |
395 | memset(outin,0,8); | 403 | memset(outin,0,8); |
@@ -415,21 +423,9 @@ int main(int argc, char *argv[]) | |||
415 | printf("Doing ede ecb\n"); | 423 | printf("Doing ede ecb\n"); |
416 | for (i=0; i<(NUM_TESTS-1); i++) | 424 | for (i=0; i<(NUM_TESTS-1); i++) |
417 | { | 425 | { |
418 | if ((j=des_key_sched(&key_data[i],ks)) != 0) | 426 | des_set_key_unchecked(&key_data[i],ks); |
419 | { | 427 | des_set_key_unchecked(&key_data[i+1],ks2); |
420 | err=1; | 428 | des_set_key_unchecked(&key_data[i+2],ks3); |
421 | printf("Key error %2d:%d\n",i+1,j); | ||
422 | } | ||
423 | if ((j=des_key_sched(&key_data[i+1],ks2)) != 0) | ||
424 | { | ||
425 | printf("Key error %2d:%d\n",i+2,j); | ||
426 | err=1; | ||
427 | } | ||
428 | if ((j=des_key_sched(&key_data[i+2],ks3)) != 0) | ||
429 | { | ||
430 | printf("Key error %2d:%d\n",i+3,j); | ||
431 | err=1; | ||
432 | } | ||
433 | memcpy(in,plain_data[i],8); | 429 | memcpy(in,plain_data[i],8); |
434 | memset(out,0,8); | 430 | memset(out,0,8); |
435 | memset(outin,0,8); | 431 | memset(outin,0,8); |
@@ -453,7 +449,7 @@ int main(int argc, char *argv[]) | |||
453 | #endif | 449 | #endif |
454 | 450 | ||
455 | printf("Doing cbc\n"); | 451 | printf("Doing cbc\n"); |
456 | if ((j=des_key_sched(&cbc_key,ks)) != 0) | 452 | if ((j=des_set_key_checked(&cbc_key,ks)) != 0) |
457 | { | 453 | { |
458 | printf("Key error %d\n",j); | 454 | printf("Key error %d\n",j); |
459 | err=1; | 455 | err=1; |
@@ -464,7 +460,10 @@ int main(int argc, char *argv[]) | |||
464 | des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks, | 460 | des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks, |
465 | &iv3,DES_ENCRYPT); | 461 | &iv3,DES_ENCRYPT); |
466 | if (memcmp(cbc_out,cbc_ok,32) != 0) | 462 | if (memcmp(cbc_out,cbc_ok,32) != 0) |
463 | { | ||
467 | printf("cbc_encrypt encrypt error\n"); | 464 | printf("cbc_encrypt encrypt error\n"); |
465 | err=1; | ||
466 | } | ||
468 | 467 | ||
469 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | 468 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); |
470 | des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks, | 469 | des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks, |
@@ -477,7 +476,7 @@ int main(int argc, char *argv[]) | |||
477 | 476 | ||
478 | #ifndef LIBDES_LIT | 477 | #ifndef LIBDES_LIT |
479 | printf("Doing desx cbc\n"); | 478 | printf("Doing desx cbc\n"); |
480 | if ((j=des_key_sched(&cbc_key,ks)) != 0) | 479 | if ((j=des_set_key_checked(&cbc_key,ks)) != 0) |
481 | { | 480 | { |
482 | printf("Key error %d\n",j); | 481 | printf("Key error %d\n",j); |
483 | err=1; | 482 | err=1; |
@@ -490,6 +489,7 @@ int main(int argc, char *argv[]) | |||
490 | if (memcmp(cbc_out,xcbc_ok,32) != 0) | 489 | if (memcmp(cbc_out,xcbc_ok,32) != 0) |
491 | { | 490 | { |
492 | printf("des_xcbc_encrypt encrypt error\n"); | 491 | printf("des_xcbc_encrypt encrypt error\n"); |
492 | err=1; | ||
493 | } | 493 | } |
494 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | 494 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); |
495 | des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks, | 495 | des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks, |
@@ -502,17 +502,17 @@ int main(int argc, char *argv[]) | |||
502 | #endif | 502 | #endif |
503 | 503 | ||
504 | printf("Doing ede cbc\n"); | 504 | printf("Doing ede cbc\n"); |
505 | if ((j=des_key_sched(&cbc_key,ks)) != 0) | 505 | if ((j=des_set_key_checked(&cbc_key,ks)) != 0) |
506 | { | 506 | { |
507 | printf("Key error %d\n",j); | 507 | printf("Key error %d\n",j); |
508 | err=1; | 508 | err=1; |
509 | } | 509 | } |
510 | if ((j=des_key_sched(&cbc2_key,ks2)) != 0) | 510 | if ((j=des_set_key_checked(&cbc2_key,ks2)) != 0) |
511 | { | 511 | { |
512 | printf("Key error %d\n",j); | 512 | printf("Key error %d\n",j); |
513 | err=1; | 513 | err=1; |
514 | } | 514 | } |
515 | if ((j=des_key_sched(&cbc3_key,ks3)) != 0) | 515 | if ((j=des_set_key_checked(&cbc3_key,ks3)) != 0) |
516 | { | 516 | { |
517 | printf("Key error %d\n",j); | 517 | printf("Key error %d\n",j); |
518 | err=1; | 518 | err=1; |
@@ -543,7 +543,7 @@ int main(int argc, char *argv[]) | |||
543 | 543 | ||
544 | #ifndef LIBDES_LIT | 544 | #ifndef LIBDES_LIT |
545 | printf("Doing pcbc\n"); | 545 | printf("Doing pcbc\n"); |
546 | if ((j=des_key_sched(&cbc_key,ks)) != 0) | 546 | if ((j=des_set_key_checked(&cbc_key,ks)) != 0) |
547 | { | 547 | { |
548 | printf("Key error %d\n",j); | 548 | printf("Key error %d\n",j); |
549 | err=1; | 549 | err=1; |
@@ -606,7 +606,7 @@ int main(int argc, char *argv[]) | |||
606 | printf("done\n"); | 606 | printf("done\n"); |
607 | 607 | ||
608 | printf("Doing ofb\n"); | 608 | printf("Doing ofb\n"); |
609 | des_key_sched(&ofb_key,ks); | 609 | des_set_key_checked(&ofb_key,ks); |
610 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | 610 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); |
611 | des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp); | 611 | des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp); |
612 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) | 612 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) |
@@ -635,7 +635,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | |||
635 | } | 635 | } |
636 | 636 | ||
637 | printf("Doing ofb64\n"); | 637 | printf("Doing ofb64\n"); |
638 | des_key_sched(&ofb_key,ks); | 638 | des_set_key_checked(&ofb_key,ks); |
639 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | 639 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); |
640 | memset(ofb_buf1,0,sizeof(ofb_buf1)); | 640 | memset(ofb_buf1,0,sizeof(ofb_buf1)); |
641 | memset(ofb_buf2,0,sizeof(ofb_buf1)); | 641 | memset(ofb_buf2,0,sizeof(ofb_buf1)); |
@@ -660,7 +660,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | |||
660 | } | 660 | } |
661 | 661 | ||
662 | printf("Doing ede_ofb64\n"); | 662 | printf("Doing ede_ofb64\n"); |
663 | des_key_sched(&ofb_key,ks); | 663 | des_set_key_checked(&ofb_key,ks); |
664 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | 664 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); |
665 | memset(ofb_buf1,0,sizeof(ofb_buf1)); | 665 | memset(ofb_buf1,0,sizeof(ofb_buf1)); |
666 | memset(ofb_buf2,0,sizeof(ofb_buf1)); | 666 | memset(ofb_buf2,0,sizeof(ofb_buf1)); |
@@ -686,7 +686,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | |||
686 | } | 686 | } |
687 | 687 | ||
688 | printf("Doing cbc_cksum\n"); | 688 | printf("Doing cbc_cksum\n"); |
689 | des_key_sched(&cbc_key,ks); | 689 | des_set_key_checked(&cbc_key,ks); |
690 | cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv); | 690 | cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv); |
691 | if (cs != cbc_cksum_ret) | 691 | if (cs != cbc_cksum_ret) |
692 | { | 692 | { |
@@ -795,8 +795,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | |||
795 | err=1; | 795 | err=1; |
796 | } | 796 | } |
797 | printf("\n"); | 797 | printf("\n"); |
798 | exit(err); | 798 | return(err); |
799 | return(0); | ||
800 | } | 799 | } |
801 | 800 | ||
802 | static char *pt(unsigned char *p) | 801 | static char *pt(unsigned char *p) |
@@ -825,7 +824,7 @@ static int cfb_test(int bits, unsigned char *cfb_cipher) | |||
825 | des_key_schedule ks; | 824 | des_key_schedule ks; |
826 | int i,err=0; | 825 | int i,err=0; |
827 | 826 | ||
828 | des_key_sched(&cfb_key,ks); | 827 | des_set_key_checked(&cfb_key,ks); |
829 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | 828 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); |
830 | des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp, | 829 | des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp, |
831 | DES_ENCRYPT); | 830 | DES_ENCRYPT); |
@@ -854,7 +853,7 @@ static int cfb64_test(unsigned char *cfb_cipher) | |||
854 | des_key_schedule ks; | 853 | des_key_schedule ks; |
855 | int err=0,i,n; | 854 | int err=0,i,n; |
856 | 855 | ||
857 | des_key_sched(&cfb_key,ks); | 856 | des_set_key_checked(&cfb_key,ks); |
858 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | 857 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); |
859 | n=0; | 858 | n=0; |
860 | des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT); | 859 | des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT); |
@@ -887,7 +886,7 @@ static int ede_cfb64_test(unsigned char *cfb_cipher) | |||
887 | des_key_schedule ks; | 886 | des_key_schedule ks; |
888 | int err=0,i,n; | 887 | int err=0,i,n; |
889 | 888 | ||
890 | des_key_sched(&cfb_key,ks); | 889 | des_set_key_checked(&cfb_key,ks); |
891 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | 890 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); |
892 | n=0; | 891 | n=0; |
893 | des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n, | 892 | des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n, |