home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / crypt / cert.c next >
Encoding:
C/C++ Source or Header  |  1992-09-02  |  1.4 KB  |  102 lines

  1.  
  2. /*
  3.  * This crypt(3) validation program shipped with UFC-crypt
  4.  * is derived from one distributed with Phil Karns PD DES package.
  5.  *
  6.  * @(#)cert.c    1.5 2/8/92
  7.  */
  8.  
  9. #include <stdio.h>
  10.  
  11. int totfails = 0;
  12.  
  13. void good_bye () 
  14. {
  15.   if(totfails == 0) {
  16.     printf("Passed DES validation suite\n");
  17.     exit(0);
  18.   } else {
  19.     printf("%d failures during DES validation suite!!!\n", totfails);
  20.     exit(1);
  21.   }
  22. }
  23.  
  24. main()
  25. {
  26.     char key[64],plain[64],cipher[64],answer[64];
  27.     int i;
  28.     int test;
  29.     int fail;
  30.  
  31.     for(test=0;!feof(stdin);test++){
  32.  
  33.         get8(key);
  34.         printf(" K: "); put8(key);
  35.         setkey(key);
  36.  
  37.         get8(plain);
  38.         printf(" P: "); put8(plain);
  39.  
  40.         get8(answer);
  41.         printf(" C: "); put8(answer);
  42.  
  43.         for(i=0;i<64;i++)
  44.             cipher[i] = plain[i];
  45.         encrypt(cipher, 0);
  46.  
  47.         for(i=0;i<64;i++)
  48.             if(cipher[i] != answer[i])
  49.                 break;
  50.         fail = 0;
  51.         if(i != 64){
  52.             printf(" Encrypt FAIL");
  53.             fail++; totfails++;
  54.         }
  55.  
  56.         encrypt(cipher, 1);
  57.  
  58.         for(i=0;i<64;i++)
  59.             if(cipher[i] != plain[i])
  60.                 break;
  61.         if(i != 64){
  62.             printf(" Decrypt FAIL");
  63.             fail++; totfails++;
  64.         }
  65.  
  66.         if(fail == 0)
  67.             printf(" OK");
  68.         printf("\n");
  69.     }
  70.     good_bye();
  71. }
  72. get8(cp)
  73. char *cp;
  74. {
  75.     int i,j,t;
  76.  
  77.     for(i=0;i<8;i++){
  78.         scanf("%2x",&t);
  79.         if(feof(stdin))
  80.           good_bye();
  81.         for(j=0; j<8 ; j++) {
  82.           *cp++ = (t & (0x01 << (7-j))) != 0;
  83.         }
  84.     }
  85. }
  86. put8(cp)
  87. char *cp;
  88. {
  89.     int i,j,t;
  90.  
  91.     for(i=0;i<8;i++){
  92.       t = 0;
  93.       for(j = 0; j<8; j++) 
  94.         t = (t<<1) | *cp++;
  95.       printf("%02x", t);
  96.     }
  97. }
  98.  
  99.  
  100.  
  101.  
  102.