]>
Commit | Line | Data |
---|---|---|
63f791d3 GK |
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> | |
3e1f480e | 10 | #include <stdlib.h> |
63f791d3 GK |
11 | #include "crypt.h" |
12 | ||
b10a0acc ZW |
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 | ||
24 | extern void setkey (const char *); | |
25 | extern void encrypt (const char *, int); | |
26 | libcrypt_version_reference (setkey, GLIBC_2_0); | |
27 | libcrypt_version_reference (encrypt, GLIBC_2_0); | |
28 | ||
63f791d3 GK |
29 | int totfails = 0; |
30 | ||
63f791d3 GK |
31 | int main (int argc, char *argv[]); |
32 | void get8 (char *cp); | |
33 | void put8 (char *cp); | |
34 | void good_bye (void) __attribute__ ((noreturn)); | |
63f791d3 | 35 | |
9d46370c JM |
36 | void |
37 | good_bye (void) | |
63f791d3 GK |
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 | ||
48 | int | |
a72ddc14 | 49 | main (int argc, char *argv[]) |
63f791d3 GK |
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 | } | |
97 | void | |
9d46370c | 98 | get8 (char *cp) |
63f791d3 GK |
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 | } | |
111 | void | |
9d46370c | 112 | put8 (char *cp) |
63f791d3 GK |
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 | } | |
b10a0acc ZW |
123 | |
124 | #else /* encrypt and setkey are not available. */ | |
125 | ||
126 | int | |
127 | main (void) | |
128 | { | |
129 | return 77; /* UNSUPPORTED */ | |
130 | } | |
131 | ||
132 | #endif |