x86: Check RTM_ALWAYS_ABORT for RTM [BZ #28033]
[glibc.git] / crypt / cert.c
blobe070ca398d97911de07553316766cf9ef537fc0e
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 test;
54 int fail;
56 for(test=0;!feof(stdin);test++){
58 get8(key);
59 printf(" K: "); put8(key);
60 setkey(key);
62 get8(plain);
63 printf(" P: "); put8(plain);
65 get8(answer);
66 printf(" C: "); put8(answer);
68 for(i=0;i<64;i++)
69 cipher[i] = plain[i];
70 encrypt(cipher, 0);
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++;
81 encrypt(cipher, 1);
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++;
91 if(fail == 0)
92 printf(" OK");
93 printf("\n");
95 good_bye();
97 void
98 get8 (char *cp)
100 int i,j,t;
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;
111 void
112 put8 (char *cp)
114 int i,j,t;
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);
124 #else /* encrypt and setkey are not available. */
127 main (void)
129 return 77; /* UNSUPPORTED */
132 #endif