Convert 24 more function definitions to prototype style (array parameters).
[glibc.git] / crypt / cert.c
blob80029e9078c1cdc04bf8c30c7f06d071be354fc0
2 /*
3 * This crypt(3) validation program shipped with UFC-crypt
4 * is derived from one distributed with Phil Karns PD DES package.
6 * @(#)cert.c 1.8 11 Aug 1996
7 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include "crypt.h"
13 int totfails = 0;
15 int main (int argc, char *argv[]);
16 void get8 (char *cp);
17 void put8 (char *cp);
18 void good_bye (void) __attribute__ ((noreturn));
20 void
21 good_bye (void)
23 if(totfails == 0) {
24 printf("Passed DES validation suite\n");
25 exit(0);
26 } else {
27 printf("%d failures during DES validation suite!!!\n", totfails);
28 exit(1);
32 int
33 main (int argc, char *argv[])
35 char key[64],plain[64],cipher[64],answer[64];
36 int i;
37 int test;
38 int fail;
40 for(test=0;!feof(stdin);test++){
42 get8(key);
43 printf(" K: "); put8(key);
44 setkey(key);
46 get8(plain);
47 printf(" P: "); put8(plain);
49 get8(answer);
50 printf(" C: "); put8(answer);
52 for(i=0;i<64;i++)
53 cipher[i] = plain[i];
54 encrypt(cipher, 0);
56 for(i=0;i<64;i++)
57 if(cipher[i] != answer[i])
58 break;
59 fail = 0;
60 if(i != 64){
61 printf(" Encrypt FAIL");
62 fail++; totfails++;
65 encrypt(cipher, 1);
67 for(i=0;i<64;i++)
68 if(cipher[i] != plain[i])
69 break;
70 if(i != 64){
71 printf(" Decrypt FAIL");
72 fail++; totfails++;
75 if(fail == 0)
76 printf(" OK");
77 printf("\n");
79 good_bye();
81 void
82 get8 (char *cp)
84 int i,j,t;
86 for(i=0;i<8;i++){
87 scanf("%2x",&t);
88 if(feof(stdin))
89 good_bye();
90 for(j=0; j<8 ; j++) {
91 *cp++ = (t & (0x01 << (7-j))) != 0;
95 void
96 put8 (char *cp)
98 int i,j,t;
100 for(i=0;i<8;i++){
101 t = 0;
102 for(j = 0; j<8; j++)
103 t = (t<<1) | *cp++;
104 printf("%02x", t);