Revert "Use pragmas rather than makefiles for necessary options for unwind code."
[glibc.git] / crypt / cert.c
blob8c838e919ac9fd389e133fc72f776e98291c2eb0
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 good_bye ()
22 if(totfails == 0) {
23 printf("Passed DES validation suite\n");
24 exit(0);
25 } else {
26 printf("%d failures during DES validation suite!!!\n", totfails);
27 exit(1);
31 int
32 main(argc, argv)
33 int argc;
34 char *argv[];
36 char key[64],plain[64],cipher[64],answer[64];
37 int i;
38 int test;
39 int fail;
41 for(test=0;!feof(stdin);test++){
43 get8(key);
44 printf(" K: "); put8(key);
45 setkey(key);
47 get8(plain);
48 printf(" P: "); put8(plain);
50 get8(answer);
51 printf(" C: "); put8(answer);
53 for(i=0;i<64;i++)
54 cipher[i] = plain[i];
55 encrypt(cipher, 0);
57 for(i=0;i<64;i++)
58 if(cipher[i] != answer[i])
59 break;
60 fail = 0;
61 if(i != 64){
62 printf(" Encrypt FAIL");
63 fail++; totfails++;
66 encrypt(cipher, 1);
68 for(i=0;i<64;i++)
69 if(cipher[i] != plain[i])
70 break;
71 if(i != 64){
72 printf(" Decrypt FAIL");
73 fail++; totfails++;
76 if(fail == 0)
77 printf(" OK");
78 printf("\n");
80 good_bye();
82 void
83 get8(cp)
84 char *cp;
86 int i,j,t;
88 for(i=0;i<8;i++){
89 scanf("%2x",&t);
90 if(feof(stdin))
91 good_bye();
92 for(j=0; j<8 ; j++) {
93 *cp++ = (t & (0x01 << (7-j))) != 0;
97 void
98 put8(cp)
99 char *cp;
101 int i,j,t;
103 for(i=0;i<8;i++){
104 t = 0;
105 for(j = 0; j<8; j++)
106 t = (t<<1) | *cp++;
107 printf("%02x", t);