Update to Unicode 15.1.0 [BZ #30854]
[glibc.git] / crypt / cert.c
blob5b4277f76d42ae09806d9f56b42e301c5c429b65
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 /* This file tests the deprecated setkey/encrypt interface. */
14 #include <shlib-compat.h>
15 #if TEST_COMPAT (libcrypt, GLIBC_2_0, GLIBC_2_28)
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)
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);
29 int totfails = 0;
31 int main (int argc, char *argv[]);
32 void get8 (char *cp);
33 void put8 (char *cp);
34 void good_bye (void) __attribute__ ((noreturn));
36 void
37 good_bye (void)
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);
48 int
49 main (int argc, char *argv[])
51 char key[64],plain[64],cipher[64],answer[64];
52 int i;
53 int fail;
55 for(;!feof(stdin);){
57 get8(key);
58 printf(" K: "); put8(key);
59 setkey(key);
61 get8(plain);
62 printf(" P: "); put8(plain);
64 get8(answer);
65 printf(" C: "); put8(answer);
67 for(i=0;i<64;i++)
68 cipher[i] = plain[i];
69 encrypt(cipher, 0);
71 for(i=0;i<64;i++)
72 if(cipher[i] != answer[i])
73 break;
74 fail = 0;
75 if(i != 64){
76 printf(" Encrypt FAIL");
77 fail++; totfails++;
80 encrypt(cipher, 1);
82 for(i=0;i<64;i++)
83 if(cipher[i] != plain[i])
84 break;
85 if(i != 64){
86 printf(" Decrypt FAIL");
87 fail++; totfails++;
90 if(fail == 0)
91 printf(" OK");
92 printf("\n");
94 good_bye();
96 void
97 get8 (char *cp)
99 int i,j,t;
101 for(i=0;i<8;i++){
102 if (scanf("%2x",&t) < 1)
104 if(ferror(stdin))
105 totfails++;
107 if(feof(stdin))
108 good_bye();
109 for(j=0; j<8 ; j++) {
110 *cp++ = (t & (0x01 << (7-j))) != 0;
114 void
115 put8 (char *cp)
117 int i,j,t;
119 for(i=0;i<8;i++){
120 t = 0;
121 for(j = 0; j<8; j++)
122 t = (t<<1) | *cp++;
123 printf("%02x", t);
127 #else /* encrypt and setkey are not available. */
130 main (void)
132 return 77; /* UNSUPPORTED */
135 #endif