Warning: That file was not part of the compilation database. It may have many parsing errors.

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/* This file tests the deprecated setkey/encrypt interface. */
14#include <shlib-compat.h>
15#if TEST_COMPAT (libcrypt, GLIBC_2_0, GLIBC_2_28)
16
17#define libcrypt_version_reference(symbol, version) \
18 _libcrypt_version_reference (symbol, VERSION_libcrypt_##version)
19#define _libcrypt_version_reference(symbol, version) \
20 __libcrypt_version_reference (symbol, version)
21#define __libcrypt_version_reference(symbol, version) \
22 __asm__ (".symver " #symbol ", " #symbol "@" #version)
23
24extern void setkey (const char *);
25extern void encrypt (const char *, int);
26libcrypt_version_reference (setkey, GLIBC_2_0);
27libcrypt_version_reference (encrypt, GLIBC_2_0);
28
29int totfails = 0;
30
31int main (int argc, char *argv[]);
32void get8 (char *cp);
33void put8 (char *cp);
34void good_bye (void) __attribute__ ((noreturn));
35
36void
37good_bye (void)
38{
39 if(totfails == 0) {
40 printf("Passed DES validation suite\n");
41 exit(0);
42 } else {
43 printf("%d failures during DES validation suite!!!\n", totfails);
44 exit(1);
45 }
46}
47
48int
49main (int argc, char *argv[])
50{
51 char key[64],plain[64],cipher[64],answer[64];
52 int i;
53 int test;
54 int fail;
55
56 for(test=0;!feof(stdin);test++){
57
58 get8(key);
59 printf(" K: "); put8(key);
60 setkey(key);
61
62 get8(plain);
63 printf(" P: "); put8(plain);
64
65 get8(answer);
66 printf(" C: "); put8(answer);
67
68 for(i=0;i<64;i++)
69 cipher[i] = plain[i];
70 encrypt(cipher, 0);
71
72 for(i=0;i<64;i++)
73 if(cipher[i] != answer[i])
74 break;
75 fail = 0;
76 if(i != 64){
77 printf(" Encrypt FAIL");
78 fail++; totfails++;
79 }
80
81 encrypt(cipher, 1);
82
83 for(i=0;i<64;i++)
84 if(cipher[i] != plain[i])
85 break;
86 if(i != 64){
87 printf(" Decrypt FAIL");
88 fail++; totfails++;
89 }
90
91 if(fail == 0)
92 printf(" OK");
93 printf("\n");
94 }
95 good_bye();
96}
97void
98get8 (char *cp)
99{
100 int i,j,t;
101
102 for(i=0;i<8;i++){
103 scanf("%2x",&t);
104 if(feof(stdin))
105 good_bye();
106 for(j=0; j<8 ; j++) {
107 *cp++ = (t & (0x01 << (7-j))) != 0;
108 }
109 }
110}
111void
112put8 (char *cp)
113{
114 int i,j,t;
115
116 for(i=0;i<8;i++){
117 t = 0;
118 for(j = 0; j<8; j++)
119 t = (t<<1) | *cp++;
120 printf("%02x", t);
121 }
122}
123
124#else /* encrypt and setkey are not available. */
125
126int
127main (void)
128{
129 return 77; /* UNSUPPORTED */
130}
131
132#endif
133

Warning: That file was not part of the compilation database. It may have many parsing errors.