summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des/destest.c
diff options
context:
space:
mode:
authorbeck <>1999-09-29 04:37:45 +0000
committerbeck <>1999-09-29 04:37:45 +0000
commitde8f24ea083384bb66b32ec105dc4743c5663cdf (patch)
tree1412176ae62a3cab2cf2b0b92150fcbceaac6092 /src/lib/libcrypto/des/destest.c
parentcb929d29896bcb87c2a97417fbd03e50078fc178 (diff)
downloadopenbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.gz
openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.bz2
openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.zip
OpenSSL 0.9.4 merge
Diffstat (limited to 'src/lib/libcrypto/des/destest.c')
-rw-r--r--src/lib/libcrypto/des/destest.c295
1 files changed, 168 insertions, 127 deletions
diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c
index 620c13ba6f..5a04fc9298 100644
--- a/src/lib/libcrypto/des/destest.c
+++ b/src/lib/libcrypto/des/destest.c
@@ -65,12 +65,27 @@
65#include <stdio.h> 65#include <stdio.h>
66#include <stdlib.h> 66#include <stdlib.h>
67#ifndef MSDOS 67#ifndef MSDOS
68#include <unistd.h> 68#if !defined(VMS) || defined(__DECC)
69#include <openssl/opensslconf.h>
70#include OPENSSL_UNISTD
71#endif /* VMS */
69#else 72#else
70#include <io.h> 73#include <io.h>
71#endif 74#endif
72#include <string.h> 75#include <string.h>
73#include "des.h" 76
77#ifdef NO_DES
78int main(int argc, char *argv[])
79{
80 printf("No DES support\n");
81 return(0);
82}
83#else
84#include <openssl/des.h>
85
86#if defined(PERL5) || defined(__FreeBSD__)
87#define crypt(c,s) (des_crypt((c),(s)))
88#endif
74 89
75/* tisk tisk - the test keys don't all have odd parity :-( */ 90/* tisk tisk - the test keys don't all have odd parity :-( */
76/* test data */ 91/* test data */
@@ -225,7 +240,7 @@ static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
225/* 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
226 * machines :-) */ 241 * machines :-) */
227/* static char cbc_data[40]="7654321 Now is the time for \0001"; */ 242/* static char cbc_data[40]="7654321 Now is the time for \0001"; */
228static char cbc_data[40]={ 243static unsigned char cbc_data[40]={
229 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20, 244 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20,
230 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74, 245 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74,
231 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20, 246 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20,
@@ -297,24 +312,14 @@ static unsigned char ofb_cipher[24]=
297DES_LONG cbc_cksum_ret=0xB462FEF7L; 312DES_LONG cbc_cksum_ret=0xB462FEF7L;
298unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; 313unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
299 314
300#ifndef NOPROTO
301static char *pt(unsigned char *p); 315static char *pt(unsigned char *p);
302static int cfb_test(int bits, unsigned char *cfb_cipher); 316static int cfb_test(int bits, unsigned char *cfb_cipher);
303static int cfb64_test(unsigned char *cfb_cipher); 317static int cfb64_test(unsigned char *cfb_cipher);
304static int ede_cfb64_test(unsigned char *cfb_cipher); 318static int ede_cfb64_test(unsigned char *cfb_cipher);
305#else 319int main(int argc, char *argv[])
306static char *pt();
307static int cfb_test();
308static int cfb64_test();
309static int ede_cfb64_test();
310#endif
311
312int main(argc,argv)
313int argc;
314char *argv[];
315 { 320 {
316 int i,j,err=0; 321 int i,j,err=0;
317 des_cblock in,out,outin,iv3; 322 des_cblock in,out,outin,iv3,iv2;
318 des_key_schedule ks,ks2,ks3; 323 des_key_schedule ks,ks2,ks3;
319 unsigned char cbc_in[40]; 324 unsigned char cbc_in[40];
320 unsigned char cbc_out[40]; 325 unsigned char cbc_out[40];
@@ -324,10 +329,63 @@ char *argv[];
324 int num; 329 int num;
325 char *str; 330 char *str;
326 331
332#ifndef NO_DESCBCM
333 printf("Doing cbcm\n");
334 if ((j=des_key_sched(&cbc_key,ks)) != 0)
335 {
336 printf("Key error %d\n",j);
337 err=1;
338 }
339 if ((j=des_key_sched(&cbc2_key,ks2)) != 0)
340 {
341 printf("Key error %d\n",j);
342 err=1;
343 }
344 if ((j=des_key_sched(&cbc3_key,ks3)) != 0)
345 {
346 printf("Key error %d\n",j);
347 err=1;
348 }
349 memset(cbc_out,0,40);
350 memset(cbc_in,0,40);
351 i=strlen((char *)cbc_data)+1;
352 /* i=((i+7)/8)*8; */
353 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
354 memset(iv2,'\0',sizeof iv2);
355
356 des_ede3_cbcm_encrypt(cbc_data,cbc_out,16L,ks,ks2,ks3,&iv3,&iv2,
357 DES_ENCRYPT);
358 des_ede3_cbcm_encrypt(&cbc_data[16],&cbc_out[16],i-16,ks,ks2,ks3,
359 &iv3,&iv2,DES_ENCRYPT);
360 /* if (memcmp(cbc_out,cbc3_ok,
361 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
362 {
363 printf("des_ede3_cbc_encrypt encrypt error\n");
364 err=1;
365 }
366 */
367 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
368 memset(iv2,'\0',sizeof iv2);
369 des_ede3_cbcm_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,&iv3,&iv2,DES_DECRYPT);
370 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
371 {
372 int n;
373
374 printf("des_ede3_cbcm_encrypt decrypt error\n");
375 for(n=0 ; n < i ; ++n)
376 printf(" %02x",cbc_data[n]);
377 printf("\n");
378 for(n=0 ; n < i ; ++n)
379 printf(" %02x",cbc_in[n]);
380 printf("\n");
381 err=1;
382 }
383#endif
384
327 printf("Doing ecb\n"); 385 printf("Doing ecb\n");
328 for (i=0; i<NUM_TESTS; i++) 386 for (i=0; i<NUM_TESTS; i++)
329 { 387 {
330 if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0) 388 if ((j=des_key_sched(&key_data[i],ks)) != 0)
331 { 389 {
332 printf("Key error %2d:%d\n",i+1,j); 390 printf("Key error %2d:%d\n",i+1,j);
333 err=1; 391 err=1;
@@ -335,8 +393,8 @@ char *argv[];
335 memcpy(in,plain_data[i],8); 393 memcpy(in,plain_data[i],8);
336 memset(out,0,8); 394 memset(out,0,8);
337 memset(outin,0,8); 395 memset(outin,0,8);
338 des_ecb_encrypt((C_Block *)in,(C_Block *)out,ks,DES_ENCRYPT); 396 des_ecb_encrypt(&in,&out,ks,DES_ENCRYPT);
339 des_ecb_encrypt((C_Block *)out,(C_Block *)outin,ks,DES_DECRYPT); 397 des_ecb_encrypt(&out,&outin,ks,DES_DECRYPT);
340 398
341 if (memcmp(out,cipher_data[i],8) != 0) 399 if (memcmp(out,cipher_data[i],8) != 0)
342 { 400 {
@@ -357,17 +415,17 @@ char *argv[];
357 printf("Doing ede ecb\n"); 415 printf("Doing ede ecb\n");
358 for (i=0; i<(NUM_TESTS-1); i++) 416 for (i=0; i<(NUM_TESTS-1); i++)
359 { 417 {
360 if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0) 418 if ((j=des_key_sched(&key_data[i],ks)) != 0)
361 { 419 {
362 err=1; 420 err=1;
363 printf("Key error %2d:%d\n",i+1,j); 421 printf("Key error %2d:%d\n",i+1,j);
364 } 422 }
365 if ((j=des_key_sched((C_Block *)(key_data[i+1]),ks2)) != 0) 423 if ((j=des_key_sched(&key_data[i+1],ks2)) != 0)
366 { 424 {
367 printf("Key error %2d:%d\n",i+2,j); 425 printf("Key error %2d:%d\n",i+2,j);
368 err=1; 426 err=1;
369 } 427 }
370 if ((j=des_key_sched((C_Block *)(key_data[i+2]),ks3)) != 0) 428 if ((j=des_key_sched(&key_data[i+2],ks3)) != 0)
371 { 429 {
372 printf("Key error %2d:%d\n",i+3,j); 430 printf("Key error %2d:%d\n",i+3,j);
373 err=1; 431 err=1;
@@ -375,10 +433,8 @@ char *argv[];
375 memcpy(in,plain_data[i],8); 433 memcpy(in,plain_data[i],8);
376 memset(out,0,8); 434 memset(out,0,8);
377 memset(outin,0,8); 435 memset(outin,0,8);
378 des_ecb2_encrypt((C_Block *)in,(C_Block *)out,ks,ks2, 436 des_ecb2_encrypt(&in,&out,ks,ks2,DES_ENCRYPT);
379 DES_ENCRYPT); 437 des_ecb2_encrypt(&out,&outin,ks,ks2,DES_DECRYPT);
380 des_ecb2_encrypt((C_Block *)out,(C_Block *)outin,ks,ks2,
381 DES_DECRYPT);
382 438
383 if (memcmp(out,cipher_ecb2[i],8) != 0) 439 if (memcmp(out,cipher_ecb2[i],8) != 0)
384 { 440 {
@@ -397,7 +453,7 @@ char *argv[];
397#endif 453#endif
398 454
399 printf("Doing cbc\n"); 455 printf("Doing cbc\n");
400 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) 456 if ((j=des_key_sched(&cbc_key,ks)) != 0)
401 { 457 {
402 printf("Key error %d\n",j); 458 printf("Key error %d\n",j);
403 err=1; 459 err=1;
@@ -405,16 +461,14 @@ char *argv[];
405 memset(cbc_out,0,40); 461 memset(cbc_out,0,40);
406 memset(cbc_in,0,40); 462 memset(cbc_in,0,40);
407 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 463 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
408 des_ncbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, 464 des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
409 (long)strlen((char *)cbc_data)+1,ks, 465 &iv3,DES_ENCRYPT);
410 (C_Block *)iv3,DES_ENCRYPT);
411 if (memcmp(cbc_out,cbc_ok,32) != 0) 466 if (memcmp(cbc_out,cbc_ok,32) != 0)
412 printf("cbc_encrypt encrypt error\n"); 467 printf("cbc_encrypt encrypt error\n");
413 468
414 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 469 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
415 des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, 470 des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
416 (long)strlen((char *)cbc_data)+1,ks, 471 &iv3,DES_DECRYPT);
417 (C_Block *)iv3,DES_DECRYPT);
418 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0) 472 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0)
419 { 473 {
420 printf("cbc_encrypt decrypt error\n"); 474 printf("cbc_encrypt decrypt error\n");
@@ -423,7 +477,7 @@ char *argv[];
423 477
424#ifndef LIBDES_LIT 478#ifndef LIBDES_LIT
425 printf("Doing desx cbc\n"); 479 printf("Doing desx cbc\n");
426 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) 480 if ((j=des_key_sched(&cbc_key,ks)) != 0)
427 { 481 {
428 printf("Key error %d\n",j); 482 printf("Key error %d\n",j);
429 err=1; 483 err=1;
@@ -431,19 +485,15 @@ char *argv[];
431 memset(cbc_out,0,40); 485 memset(cbc_out,0,40);
432 memset(cbc_in,0,40); 486 memset(cbc_in,0,40);
433 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 487 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
434 des_xcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, 488 des_xcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
435 (long)strlen((char *)cbc_data)+1,ks, 489 &iv3,&cbc2_key,&cbc3_key, DES_ENCRYPT);
436 (C_Block *)iv3,
437 (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_ENCRYPT);
438 if (memcmp(cbc_out,xcbc_ok,32) != 0) 490 if (memcmp(cbc_out,xcbc_ok,32) != 0)
439 { 491 {
440 printf("des_xcbc_encrypt encrypt error\n"); 492 printf("des_xcbc_encrypt encrypt error\n");
441 } 493 }
442 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 494 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
443 des_xcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, 495 des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
444 (long)strlen((char *)cbc_data)+1,ks, 496 &iv3,&cbc2_key,&cbc3_key, DES_DECRYPT);
445 (C_Block *)iv3,
446 (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_DECRYPT);
447 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) 497 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
448 { 498 {
449 printf("des_xcbc_encrypt decrypt error\n"); 499 printf("des_xcbc_encrypt decrypt error\n");
@@ -452,17 +502,17 @@ char *argv[];
452#endif 502#endif
453 503
454 printf("Doing ede cbc\n"); 504 printf("Doing ede cbc\n");
455 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) 505 if ((j=des_key_sched(&cbc_key,ks)) != 0)
456 { 506 {
457 printf("Key error %d\n",j); 507 printf("Key error %d\n",j);
458 err=1; 508 err=1;
459 } 509 }
460 if ((j=des_key_sched((C_Block *)cbc2_key,ks2)) != 0) 510 if ((j=des_key_sched(&cbc2_key,ks2)) != 0)
461 { 511 {
462 printf("Key error %d\n",j); 512 printf("Key error %d\n",j);
463 err=1; 513 err=1;
464 } 514 }
465 if ((j=des_key_sched((C_Block *)cbc3_key,ks3)) != 0) 515 if ((j=des_key_sched(&cbc3_key,ks3)) != 0)
466 { 516 {
467 printf("Key error %d\n",j); 517 printf("Key error %d\n",j);
468 err=1; 518 err=1;
@@ -473,11 +523,9 @@ char *argv[];
473 /* i=((i+7)/8)*8; */ 523 /* i=((i+7)/8)*8; */
474 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 524 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
475 525
476 des_ede3_cbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, 526 des_ede3_cbc_encrypt(cbc_data,cbc_out,16L,ks,ks2,ks3,&iv3,DES_ENCRYPT);
477 16L,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT); 527 des_ede3_cbc_encrypt(&(cbc_data[16]),&(cbc_out[16]),i-16,ks,ks2,ks3,
478 des_ede3_cbc_encrypt((C_Block *)&(cbc_data[16]), 528 &iv3,DES_ENCRYPT);
479 (C_Block *)&(cbc_out[16]),
480 (long)i-16,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT);
481 if (memcmp(cbc_out,cbc3_ok, 529 if (memcmp(cbc_out,cbc3_ok,
482 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0) 530 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
483 { 531 {
@@ -486,9 +534,8 @@ char *argv[];
486 } 534 }
487 535
488 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 536 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
489 des_ede3_cbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, 537 des_ede3_cbc_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,&iv3,DES_DECRYPT);
490 (long)i,ks,ks2,ks3,(C_Block *)iv3,DES_DECRYPT); 538 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
491 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
492 { 539 {
493 printf("des_ede3_cbc_encrypt decrypt error\n"); 540 printf("des_ede3_cbc_encrypt decrypt error\n");
494 err=1; 541 err=1;
@@ -496,23 +543,23 @@ char *argv[];
496 543
497#ifndef LIBDES_LIT 544#ifndef LIBDES_LIT
498 printf("Doing pcbc\n"); 545 printf("Doing pcbc\n");
499 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) 546 if ((j=des_key_sched(&cbc_key,ks)) != 0)
500 { 547 {
501 printf("Key error %d\n",j); 548 printf("Key error %d\n",j);
502 err=1; 549 err=1;
503 } 550 }
504 memset(cbc_out,0,40); 551 memset(cbc_out,0,40);
505 memset(cbc_in,0,40); 552 memset(cbc_in,0,40);
506 des_pcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, 553 des_pcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
507 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_ENCRYPT); 554 &cbc_iv,DES_ENCRYPT);
508 if (memcmp(cbc_out,pcbc_ok,32) != 0) 555 if (memcmp(cbc_out,pcbc_ok,32) != 0)
509 { 556 {
510 printf("pcbc_encrypt encrypt error\n"); 557 printf("pcbc_encrypt encrypt error\n");
511 err=1; 558 err=1;
512 } 559 }
513 des_pcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, 560 des_pcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,&cbc_iv,
514 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_DECRYPT); 561 DES_DECRYPT);
515 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0) 562 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
516 { 563 {
517 printf("pcbc_encrypt decrypt error\n"); 564 printf("pcbc_encrypt decrypt error\n");
518 err=1; 565 err=1;
@@ -536,7 +583,7 @@ char *argv[];
536 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 583 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
537 for (i=0; i<sizeof(plain); i++) 584 for (i=0; i<sizeof(plain); i++)
538 des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]), 585 des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]),
539 8,(long)1,ks,(C_Block *)cfb_tmp,DES_ENCRYPT); 586 8,1,ks,&cfb_tmp,DES_ENCRYPT);
540 if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0) 587 if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0)
541 { 588 {
542 printf("cfb_encrypt small encrypt error\n"); 589 printf("cfb_encrypt small encrypt error\n");
@@ -546,7 +593,7 @@ char *argv[];
546 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 593 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
547 for (i=0; i<sizeof(plain); i++) 594 for (i=0; i<sizeof(plain); i++)
548 des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]), 595 des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]),
549 8,(long)1,ks,(C_Block *)cfb_tmp,DES_DECRYPT); 596 8,1,ks,&cfb_tmp,DES_DECRYPT);
550 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) 597 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
551 { 598 {
552 printf("cfb_encrypt small decrypt error\n"); 599 printf("cfb_encrypt small decrypt error\n");
@@ -559,10 +606,9 @@ char *argv[];
559 printf("done\n"); 606 printf("done\n");
560 607
561 printf("Doing ofb\n"); 608 printf("Doing ofb\n");
562 des_key_sched((C_Block *)ofb_key,ks); 609 des_key_sched(&ofb_key,ks);
563 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 610 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
564 des_ofb_encrypt(plain,ofb_buf1,64,(long)sizeof(plain)/8,ks, 611 des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp);
565 (C_Block *)ofb_tmp);
566 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) 612 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
567 { 613 {
568 printf("ofb_encrypt encrypt error\n"); 614 printf("ofb_encrypt encrypt error\n");
@@ -575,8 +621,7 @@ ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]);
575 err=1; 621 err=1;
576 } 622 }
577 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 623 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
578 des_ofb_encrypt(ofb_buf1,ofb_buf2,64,(long)sizeof(ofb_buf1)/8,ks, 624 des_ofb_encrypt(ofb_buf1,ofb_buf2,64,sizeof(ofb_buf1)/8,ks,&ofb_tmp);
579 (C_Block *)ofb_tmp);
580 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) 625 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
581 { 626 {
582 printf("ofb_encrypt decrypt error\n"); 627 printf("ofb_encrypt decrypt error\n");
@@ -590,15 +635,15 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
590 } 635 }
591 636
592 printf("Doing ofb64\n"); 637 printf("Doing ofb64\n");
593 des_key_sched((C_Block *)ofb_key,ks); 638 des_key_sched(&ofb_key,ks);
594 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 639 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
595 memset(ofb_buf1,0,sizeof(ofb_buf1)); 640 memset(ofb_buf1,0,sizeof(ofb_buf1));
596 memset(ofb_buf2,0,sizeof(ofb_buf1)); 641 memset(ofb_buf2,0,sizeof(ofb_buf1));
597 num=0; 642 num=0;
598 for (i=0; i<sizeof(plain); i++) 643 for (i=0; i<sizeof(plain); i++)
599 { 644 {
600 des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks, 645 des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,&ofb_tmp,
601 (C_Block *)ofb_tmp,&num); 646 &num);
602 } 647 }
603 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) 648 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
604 { 649 {
@@ -607,8 +652,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
607 } 652 }
608 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 653 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
609 num=0; 654 num=0;
610 des_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks, 655 des_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,&ofb_tmp,&num);
611 (C_Block *)ofb_tmp,&num);
612 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) 656 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
613 { 657 {
614 printf("ofb64_encrypt decrypt error\n"); 658 printf("ofb64_encrypt decrypt error\n");
@@ -616,7 +660,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
616 } 660 }
617 661
618 printf("Doing ede_ofb64\n"); 662 printf("Doing ede_ofb64\n");
619 des_key_sched((C_Block *)ofb_key,ks); 663 des_key_sched(&ofb_key,ks);
620 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 664 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
621 memset(ofb_buf1,0,sizeof(ofb_buf1)); 665 memset(ofb_buf1,0,sizeof(ofb_buf1));
622 memset(ofb_buf2,0,sizeof(ofb_buf1)); 666 memset(ofb_buf2,0,sizeof(ofb_buf1));
@@ -624,7 +668,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
624 for (i=0; i<sizeof(plain); i++) 668 for (i=0; i<sizeof(plain); i++)
625 { 669 {
626 des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,ks, 670 des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,ks,
627 (C_Block *)ofb_tmp,&num); 671 &ofb_tmp,&num);
628 } 672 }
629 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) 673 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
630 { 674 {
@@ -633,8 +677,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
633 } 677 }
634 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 678 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
635 num=0; 679 num=0;
636 des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks, 680 des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,
637 ks,ks,(C_Block *)ofb_tmp,&num); 681 ks,ks,&ofb_tmp,&num);
638 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) 682 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
639 { 683 {
640 printf("ede_ofb64_encrypt decrypt error\n"); 684 printf("ede_ofb64_encrypt decrypt error\n");
@@ -642,9 +686,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
642 } 686 }
643 687
644 printf("Doing cbc_cksum\n"); 688 printf("Doing cbc_cksum\n");
645 des_key_sched((C_Block *)cbc_key,ks); 689 des_key_sched(&cbc_key,ks);
646 cs=des_cbc_cksum((C_Block *)cbc_data,(C_Block *)cret, 690 cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv);
647 (long)strlen(cbc_data),ks,(C_Block *)cbc_iv);
648 if (cs != cbc_cksum_ret) 691 if (cs != cbc_cksum_ret)
649 { 692 {
650 printf("bad return value (%08lX), should be %08lX\n", 693 printf("bad return value (%08lX), should be %08lX\n",
@@ -658,19 +701,26 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
658 } 701 }
659 702
660 printf("Doing quad_cksum\n"); 703 printf("Doing quad_cksum\n");
661 cs=quad_cksum((C_Block *)cbc_data,(C_Block *)qret, 704 /* This is obviously done this way especially to puzzle me. Although
662 (long)strlen(cbc_data),2,(C_Block *)cbc_iv); 705 quad_cksum returns up to 4 groups of 8 bytes, this test gets it to
706 produce 2 groups then treats them as 4 groups of 4 bytes.
707 Ben 13 Feb 1999 */
708 cs=quad_cksum(cbc_data,(des_cblock *)qret,strlen((char *)cbc_data),2,
709 &cbc_iv);
710
711 { /* Big-endian fix */
712 static DES_LONG l=1;
713 static unsigned char *c=(unsigned char *)&l;
714 DES_LONG ll;
715
663 j=sizeof(lqret[0])-4; 716 j=sizeof(lqret[0])-4;
664 for (i=0; i<4; i++) 717 for (i=0; i<4; i++)
665 { 718 {
666 lqret[i]=0; 719 lqret[i]=0;
667 memcpy(&(lqret[i]),&(qret[i][0]),4); 720 memcpy(&(lqret[i]),&(qret[i][0]),4);
668 if (j > 0) lqret[i]=lqret[i]>>(j*8); /* For Cray */ 721 if (!c[0] && (j > 0))
722 lqret[i]=lqret[i]>>(j*8); /* For Cray */
669 } 723 }
670 { /* Big-endian fix */
671 static DES_LONG l=1;
672 static unsigned char *c=(unsigned char *)&l;
673 DES_LONG ll;
674 724
675 if (!c[0]) 725 if (!c[0])
676 { 726 {
@@ -691,25 +741,25 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
691 if (lqret[0] != 0x327eba8dL) 741 if (lqret[0] != 0x327eba8dL)
692 { 742 {
693 printf("quad_cksum error, out[0] %08lx is not %08lx\n", 743 printf("quad_cksum error, out[0] %08lx is not %08lx\n",
694 (unsigned long)lqret[0],0x327eba8dL); 744 (unsigned long)lqret[0],0x327eba8dUL);
695 err=1; 745 err=1;
696 } 746 }
697 if (lqret[1] != 0x201a49ccL) 747 if (lqret[1] != 0x201a49ccL)
698 { 748 {
699 printf("quad_cksum error, out[1] %08lx is not %08lx\n", 749 printf("quad_cksum error, out[1] %08lx is not %08lx\n",
700 (unsigned long)lqret[1],0x201a49ccL); 750 (unsigned long)lqret[1],0x201a49ccUL);
701 err=1; 751 err=1;
702 } 752 }
703 if (lqret[2] != 0x70d7a63aL) 753 if (lqret[2] != 0x70d7a63aL)
704 { 754 {
705 printf("quad_cksum error, out[2] %08lx is not %08lx\n", 755 printf("quad_cksum error, out[2] %08lx is not %08lx\n",
706 (unsigned long)lqret[2],0x70d7a63aL); 756 (unsigned long)lqret[2],0x70d7a63aUL);
707 err=1; 757 err=1;
708 } 758 }
709 if (lqret[3] != 0x501c2c26L) 759 if (lqret[3] != 0x501c2c26L)
710 { 760 {
711 printf("quad_cksum error, out[3] %08lx is not %08lx\n", 761 printf("quad_cksum error, out[3] %08lx is not %08lx\n",
712 (unsigned long)lqret[3],0x501c2c26L); 762 (unsigned long)lqret[3],0x501c2c26UL);
713 err=1; 763 err=1;
714 } 764 }
715#endif 765#endif
@@ -718,17 +768,17 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
718 for (i=0; i<4; i++) 768 for (i=0; i<4; i++)
719 { 769 {
720 printf(" %d",i); 770 printf(" %d",i);
721 des_ncbc_encrypt((C_Block *)&(cbc_out[i]),(C_Block *)cbc_in, 771 des_ncbc_encrypt(&(cbc_out[i]),cbc_in,
722 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv, 772 strlen((char *)cbc_data)+1,ks,
723 DES_ENCRYPT); 773 &cbc_iv,DES_ENCRYPT);
724 } 774 }
725 printf("\noutput word alignment test"); 775 printf("\noutput word alignment test");
726 for (i=0; i<4; i++) 776 for (i=0; i<4; i++)
727 { 777 {
728 printf(" %d",i); 778 printf(" %d",i);
729 des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)&(cbc_in[i]), 779 des_ncbc_encrypt(cbc_out,&(cbc_in[i]),
730 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv, 780 strlen((char *)cbc_data)+1,ks,
731 DES_ENCRYPT); 781 &cbc_iv,DES_ENCRYPT);
732 } 782 }
733 printf("\n"); 783 printf("\n");
734 printf("fast crypt test "); 784 printf("fast crypt test ");
@@ -749,8 +799,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
749 return(0); 799 return(0);
750 } 800 }
751 801
752static char *pt(p) 802static char *pt(unsigned char *p)
753unsigned char *p;
754 { 803 {
755 static char bufs[10][20]; 804 static char bufs[10][20];
756 static int bnum=0; 805 static int bnum=0;
@@ -771,17 +820,15 @@ unsigned char *p;
771 820
772#ifndef LIBDES_LIT 821#ifndef LIBDES_LIT
773 822
774static int cfb_test(bits, cfb_cipher) 823static int cfb_test(int bits, unsigned char *cfb_cipher)
775int bits;
776unsigned char *cfb_cipher;
777 { 824 {
778 des_key_schedule ks; 825 des_key_schedule ks;
779 int i,err=0; 826 int i,err=0;
780 827
781 des_key_sched((C_Block *)cfb_key,ks); 828 des_key_sched(&cfb_key,ks);
782 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 829 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
783 des_cfb_encrypt(plain,cfb_buf1,bits,(long)sizeof(plain),ks, 830 des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp,
784 (C_Block *)cfb_tmp,DES_ENCRYPT); 831 DES_ENCRYPT);
785 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) 832 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
786 { 833 {
787 err=1; 834 err=1;
@@ -790,8 +837,8 @@ unsigned char *cfb_cipher;
790 printf("%s\n",pt(&(cfb_buf1[i]))); 837 printf("%s\n",pt(&(cfb_buf1[i])));
791 } 838 }
792 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 839 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
793 des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,(long)sizeof(plain),ks, 840 des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,&cfb_tmp,
794 (C_Block *)cfb_tmp,DES_DECRYPT); 841 DES_DECRYPT);
795 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) 842 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
796 { 843 {
797 err=1; 844 err=1;
@@ -802,20 +849,17 @@ unsigned char *cfb_cipher;
802 return(err); 849 return(err);
803 } 850 }
804 851
805static int cfb64_test(cfb_cipher) 852static int cfb64_test(unsigned char *cfb_cipher)
806unsigned char *cfb_cipher;
807 { 853 {
808 des_key_schedule ks; 854 des_key_schedule ks;
809 int err=0,i,n; 855 int err=0,i,n;
810 856
811 des_key_sched((C_Block *)cfb_key,ks); 857 des_key_sched(&cfb_key,ks);
812 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 858 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
813 n=0; 859 n=0;
814 des_cfb64_encrypt(plain,cfb_buf1,(long)12,ks, 860 des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT);
815 (C_Block *)cfb_tmp,&n,DES_ENCRYPT); 861 des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks,
816 des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), 862 &cfb_tmp,&n,DES_ENCRYPT);
817 (long)sizeof(plain)-12,ks,
818 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
819 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) 863 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
820 { 864 {
821 err=1; 865 err=1;
@@ -825,11 +869,9 @@ unsigned char *cfb_cipher;
825 } 869 }
826 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 870 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
827 n=0; 871 n=0;
828 des_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks, 872 des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,&cfb_tmp,&n,DES_DECRYPT);
829 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
830 des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), 873 des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
831 (long)sizeof(plain)-17,ks, 874 sizeof(plain)-17,ks,&cfb_tmp,&n,DES_DECRYPT);
832 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
833 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) 875 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
834 { 876 {
835 err=1; 877 err=1;
@@ -840,20 +882,19 @@ unsigned char *cfb_cipher;
840 return(err); 882 return(err);
841 } 883 }
842 884
843static int ede_cfb64_test(cfb_cipher) 885static int ede_cfb64_test(unsigned char *cfb_cipher)
844unsigned char *cfb_cipher;
845 { 886 {
846 des_key_schedule ks; 887 des_key_schedule ks;
847 int err=0,i,n; 888 int err=0,i,n;
848 889
849 des_key_sched((C_Block *)cfb_key,ks); 890 des_key_sched(&cfb_key,ks);
850 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 891 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
851 n=0; 892 n=0;
852 des_ede3_cfb64_encrypt(plain,cfb_buf1,(long)12,ks,ks,ks, 893 des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n,
853 (C_Block *)cfb_tmp,&n,DES_ENCRYPT); 894 DES_ENCRYPT);
854 des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), 895 des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
855 (long)sizeof(plain)-12,ks,ks,ks, 896 sizeof(plain)-12,ks,ks,ks,
856 (C_Block *)cfb_tmp,&n,DES_ENCRYPT); 897 &cfb_tmp,&n,DES_ENCRYPT);
857 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) 898 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
858 { 899 {
859 err=1; 900 err=1;
@@ -864,10 +905,10 @@ unsigned char *cfb_cipher;
864 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 905 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
865 n=0; 906 n=0;
866 des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks, 907 des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks,
867 (C_Block *)cfb_tmp,&n,DES_DECRYPT); 908 &cfb_tmp,&n,DES_DECRYPT);
868 des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), 909 des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
869 (long)sizeof(plain)-17,ks,ks,ks, 910 sizeof(plain)-17,ks,ks,ks,
870 (C_Block *)cfb_tmp,&n,DES_DECRYPT); 911 &cfb_tmp,&n,DES_DECRYPT);
871 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) 912 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
872 { 913 {
873 err=1; 914 err=1;
@@ -879,4 +920,4 @@ unsigned char *cfb_cipher;
879 } 920 }
880 921
881#endif 922#endif
882 923#endif