Moved to math/e_gammal_r.c.
[kopensolaris-gnu/glibc.git] / crypt / cert.c
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.8 11 Aug 1996
7  */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include "crypt.h"
12
13 int totfails = 0;
14
15 #if __STDC__ - 0
16 int main (int argc, char *argv[]);
17 void get8 (char *cp);
18 void put8 (char *cp);
19 void good_bye (void) __attribute__ ((noreturn));
20 #else
21 void get8(), put8();
22 #endif
23
24 void good_bye ()
25 {
26   if(totfails == 0) {
27     printf("Passed DES validation suite\n");
28     exit(0);
29   } else {
30     printf("%d failures during DES validation suite!!!\n", totfails);
31     exit(1);
32   }
33 }
34
35 int
36 main(argc, argv)
37      int argc;
38      char *argv[];
39 {
40         char key[64],plain[64],cipher[64],answer[64];
41         int i;
42         int test;
43         int fail;
44
45         for(test=0;!feof(stdin);test++){
46
47                 get8(key);
48                 printf(" K: "); put8(key);
49                 setkey(key);
50
51                 get8(plain);
52                 printf(" P: "); put8(plain);
53
54                 get8(answer);
55                 printf(" C: "); put8(answer);
56
57                 for(i=0;i<64;i++)
58                         cipher[i] = plain[i];
59                 encrypt(cipher, 0);
60
61                 for(i=0;i<64;i++)
62                         if(cipher[i] != answer[i])
63                                 break;
64                 fail = 0;
65                 if(i != 64){
66                         printf(" Encrypt FAIL");
67                         fail++; totfails++;
68                 }
69
70                 encrypt(cipher, 1);
71
72                 for(i=0;i<64;i++)
73                         if(cipher[i] != plain[i])
74                                 break;
75                 if(i != 64){
76                         printf(" Decrypt FAIL");
77                         fail++; totfails++;
78                 }
79
80                 if(fail == 0)
81                         printf(" OK");
82                 printf("\n");
83         }
84         good_bye();
85 }
86 void
87 get8(cp)
88 char *cp;
89 {
90         int i,j,t;
91
92         for(i=0;i<8;i++){
93                 scanf("%2x",&t);
94                 if(feof(stdin))
95                   good_bye();
96                 for(j=0; j<8 ; j++) {
97                   *cp++ = (t & (0x01 << (7-j))) != 0;
98                 }
99         }
100 }
101 void
102 put8(cp)
103 char *cp;
104 {
105         int i,j,t;
106
107         for(i=0;i<8;i++){
108           t = 0;
109           for(j = 0; j<8; j++)
110             t = (t<<1) | *cp++;
111           printf("%02x", t);
112         }
113 }