home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / ufc / cert.c next >
Encoding:
C/C++ Source or Header  |  1992-02-12  |  1.4 KB  |  104 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.  * Michael Glad, email: glad@daimi.aau.dk
  7.  *
  8.  * @(#)cert.c    1.4 01/13/92
  9.  */
  10.  
  11. #include <stdio.h>
  12.  
  13. int totfails = 0;
  14.  
  15. void good_bye () 
  16. {
  17.   if(totfails == 0) {
  18.     printf("Passed DES validation suite\n");
  19.     exit(0);
  20.   } else {
  21.     printf("%d failures during DES validation suite!!!\n", totfails);
  22.     exit(1);
  23.   }
  24. }
  25.  
  26. main()
  27. {
  28.     char key[64],plain[64],cipher[64],answer[64];
  29.     int i;
  30.     int test;
  31.     int fail;
  32.  
  33.     for(test=0;!feof(stdin);test++){
  34.  
  35.         get8(key);
  36.         printf(" K: "); put8(key);
  37.         setkey(key);
  38.  
  39.         get8(plain);
  40.         printf(" P: "); put8(plain);
  41.  
  42.         get8(answer);
  43.         printf(" C: "); put8(answer);
  44.  
  45.         for(i=0;i<64;i++)
  46.             cipher[i] = plain[i];
  47.         encrypt(cipher, 0);
  48.  
  49.         for(i=0;i<64;i++)
  50.             if(cipher[i] != answer[i])
  51.                 break;
  52.         fail = 0;
  53.         if(i != 64){
  54.             printf(" Encrypt FAIL");
  55.             fail++; totfails++;
  56.         }
  57.  
  58.         encrypt(cipher, 1);
  59.  
  60.         for(i=0;i<64;i++)
  61.             if(cipher[i] != plain[i])
  62.                 break;
  63.         if(i != 64){
  64.             printf(" Decrypt FAIL");
  65.             fail++; totfails++;
  66.         }
  67.  
  68.         if(fail == 0)
  69.             printf(" OK");
  70.         printf("\n");
  71.     }
  72.     good_bye();
  73. }
  74. get8(cp)
  75. char *cp;
  76. {
  77.     int i,j,t;
  78.  
  79.     for(i=0;i<8;i++){
  80.         scanf("%2x",&t);
  81.         if(feof(stdin))
  82.           good_bye();
  83.         for(j=0; j<8 ; j++) {
  84.           *cp++ = (t & (0x01 << (7-j))) != 0;
  85.         }
  86.     }
  87. }
  88. put8(cp)
  89. char *cp;
  90. {
  91.     int i,j,t;
  92.  
  93.     for(i=0;i<8;i++){
  94.       t = 0;
  95.       for(j = 0; j<8; j++) 
  96.         t = (t<<1) | *cp++;
  97.       printf("%02x", t);
  98.     }
  99. }
  100.  
  101.  
  102.  
  103.  
  104.