mux/src/crypt/cert.cpp

Go to the documentation of this file.
00001 
00002 /*
00003  * This crypt(3) validation program shipped with UFC-crypt
00004  * is derived from one distributed with Phil Karns PD DES package.
00005  *
00006  * @(#)cert.c   1.8 11 Aug 1996
00007  */
00008 
00009 #include <stdio.h>
00010 #include "crypt.h"
00011 
00012 int totfails = 0;
00013 
00014 #if __STDC__ - 0
00015 int main (int argc, char *argv[]);
00016 void get8 (char *cp);
00017 void put8 (char *cp);
00018 void good_bye (void) __attribute__ ((noreturn));
00019 #else
00020 void get8(), put8();
00021 #endif
00022 
00023 void good_bye ()
00024 {
00025   if(totfails == 0) {
00026     printf("Passed DES validation suite\n");
00027     exit(0);
00028   } else {
00029     printf("%d failures during DES validation suite!!!\n", totfails);
00030     exit(1);
00031   }
00032 }
00033 
00034 int
00035 main(argc, argv)
00036      int argc;
00037      char *argv[];
00038 {
00039     char key[64],plain[64],cipher[64],answer[64];
00040     int i;
00041     int test;
00042     int fail;
00043 
00044     for(test=0;!feof(stdin);test++){
00045 
00046         get8(key);
00047         printf(" K: "); put8(key);
00048         setkey(key);
00049 
00050         get8(plain);
00051         printf(" P: "); put8(plain);
00052 
00053         get8(answer);
00054         printf(" C: "); put8(answer);
00055 
00056         for(i=0;i<64;i++)
00057             cipher[i] = plain[i];
00058         encrypt(cipher, 0);
00059 
00060         for(i=0;i<64;i++)
00061             if(cipher[i] != answer[i])
00062                 break;
00063         fail = 0;
00064         if(i != 64){
00065             printf(" Encrypt FAIL");
00066             fail++; totfails++;
00067         }
00068 
00069         encrypt(cipher, 1);
00070 
00071         for(i=0;i<64;i++)
00072             if(cipher[i] != plain[i])
00073                 break;
00074         if(i != 64){
00075             printf(" Decrypt FAIL");
00076             fail++; totfails++;
00077         }
00078 
00079         if(fail == 0)
00080             printf(" OK");
00081         printf("\n");
00082     }
00083     good_bye();
00084 }
00085 void
00086 get8(cp)
00087 char *cp;
00088 {
00089     int i,j,t;
00090 
00091     for(i=0;i<8;i++){
00092         scanf("%2x",&t);
00093         if(feof(stdin))
00094           good_bye();
00095         for(j=0; j<8 ; j++) {
00096           *cp++ = (t & (0x01 << (7-j))) != 0;
00097         }
00098     }
00099 }
00100 void
00101 put8(cp)
00102 char *cp;
00103 {
00104     int i,j,t;
00105 
00106     for(i=0;i<8;i++){
00107       t = 0;
00108       for(j = 0; j<8; j++)
00109         t = (t<<1) | *cp++;
00110       printf("%02x", t);
00111     }
00112 }

Generated on Mon May 28 04:40:08 2007 for MUX by  doxygen 1.4.7