des-support-alpha-bsd-and-fix-test-programs-20020119
[openafs.git] / src / des / test / key_test.c
1 /*
2  * Copyright 1988 by the Massachusetts Institute of Technology.
3  *
4  * For copying and distribution information, please see the file
5  * <mit-cpyright.h>.
6  *
7  * exit status:          0 ==> success
8  *                      -1 ==> error
9  */
10
11 #include <afsconfig.h>
12 #include <afs/param.h>
13
14 RCSID("$Header$");
15
16 #include <mit-cpyright.h>
17 #include <stdio.h>
18 #include <errno.h>
19 #include <des.h>
20
21 #define MIN_ARGC        0       /* min # args, not incl flags */
22 #define MAX_ARGC        99      /* max # args, not incl flags */
23
24 extern char *errmsg();
25 extern int des_key_sched();
26 char *progname;
27 int sflag;
28 int vflag;
29 int kflag;
30 int mflag;
31 int pid;
32 extern int des_debug;
33
34 afs_int32 dummy[2];
35 unsigned char dum_c[8] = { 0x80,1,1,1,1,1,1,1 };
36 des_key_schedule KS;
37 des_cblock kk;
38
39 main(argc,argv)
40     int argc;
41     char *argv[];
42 {
43     /*  Local Declarations */
44
45     int i;
46     progname=argv[0];           /* salt away invoking program */
47
48     while (--argc > 0 && (*++argv)[0] == '-')
49         for (i=1; argv[0][i] != '\0'; i++) {
50             switch (argv[0][i]) {
51
52                 /* debug flag */
53             case 'd':
54                 des_debug=1;
55                 continue;
56
57                 /* keys flag */
58             case 'k':
59                 kflag = 1;
60                 continue;
61
62                 /* test ANSI msb only key */
63             case 'm':
64                 mflag = 1;
65                 continue;
66
67             default:
68                 printf("%s: illegal flag \"%c\" ",
69                        progname,argv[0][i]);
70                 exit(1);
71             }
72         };
73
74     if (argc < MIN_ARGC || argc >MAX_ARGC) {
75         printf("Usage: xxx [-xxx]  xxx xxx\n");
76         exit(1);
77     }
78
79     /*  argv[0] now points to first non-option arg, if any */
80
81
82     if (des_debug) {
83         if (mflag) {
84             fprintf(stderr,"\nChecking a key 0x 80 01 01 01 01 01 01 01 ");
85             fprintf(stderr,"\nKey = ");
86             des_key_sched(dum_c,KS);
87             des_cblock_print (dum_c);
88             return;
89         }
90
91         if (kflag) {
92             printf("\nCHecking a weak key...");
93             dummy[0] =  0x01fe01fe;
94             dummy[1] =  0x01fe01fe;
95             des_key_sched(dummy,KS);
96 #ifdef BSDUNIX
97             fprintf(stderr,"\nKey[0] = %x Key[1] = %x",dummy[0],dummy[1]);
98 #endif
99 #ifdef CROSSMSDOS
100             fprintf(stderr,"\nKey[0] = %X Key[1] = %X",dummy[0],dummy[1]);
101 #endif
102
103             dummy[0] = 0x01010101;
104             dummy[1] = 0x01010101;
105 #ifdef BSDUNIX
106             fprintf(stderr,"\nKey[0] = %x Key[1] = %x",dummy[0],dummy[1]);
107 #endif
108 #ifdef CROSSMSDOS
109             fprintf(stderr,"\nKey[0] = %X Key[1] = %X",dummy[0],dummy[1]);
110 #endif
111             des_key_sched(dummy,KS);
112 #ifdef BSDUNIX
113             fprintf(stderr,"\nKS= %x",* (afs_int32 *)KS);
114 #endif
115 #ifdef CROSSMSDOS
116             fprintf(stderr,"\nKS= %X",* (afs_int32 *)KS);
117 #endif
118             dummy[0] = 0x01010101;
119             dummy[1] = 0x01010101;
120 #ifdef BSDUNIX
121             fprintf(stderr,"\nKey[0] = %x Key[1] = %x",dummy[0],dummy[1]);
122 #endif
123 #ifdef CROSSMSDOS
124             fprintf(stderr,"\nKey[0] = %X Key[1] = %X",dummy[0],dummy[1]);
125 #endif
126             des_key_sched(dummy,KS);
127 #ifdef BSDUNIX
128             fprintf(stderr,"\nKS= %x",  *(afs_int32 *)KS);
129 #endif
130 #ifdef CROSSMSDOS
131             fprintf(stderr,"\nKS= %X",  *(afs_int32 *)KS);
132 #endif
133
134             dummy[0] = 0x80808080;
135             dummy[1] = 0x80808080;
136 #ifdef BSDUNIX
137             fprintf(stderr,"\nKey[0] = %x Key[1] = %x",dummy[0],dummy[1]);
138 #endif
139 #ifdef CROSSMSDOS
140             fprintf(stderr,"\nKey[0] = %X Key[1] = %X",dummy[0],dummy[1]);
141 #endif
142             des_key_sched(dummy,KS);
143 #ifdef BSDUNIX
144             fprintf(stderr,"\nKS[0]= %x",* (afs_int32 * ) KS);
145 #endif
146 #ifdef CROSSMSDOS
147             fprintf(stderr,"\nKS[0]= %X",* (afs_int32 * ) KS);
148 #endif
149
150             printf("\nstring to key 'a'");
151             des_string_to_key("a",dummy);
152 #ifdef BSDUNIX
153             fprintf(stderr,"\nKey[0] = %x Key[1] = %x",dummy[0],dummy[1]);
154 #endif
155 #ifdef CROSSMSDOS
156             fprintf(stderr,"\nKey[0] = %X Key[1] = %X",dummy[0],dummy[1]);
157 #endif
158             des_key_sched(dummy,KS);
159 #ifdef BSDUNIX
160             fprintf(stderr,"\nKS= %x",* (afs_int32 *) KS);
161 #endif
162 #ifdef CROSSMSDOS
163             fprintf(stderr,"\nKS= %X",* (afs_int32 *) KS);
164 #endif
165
166             printf("\nstring to key 'c'");
167             des_string_to_key("c",dummy);
168 #ifdef BSDUNIX
169             fprintf(stderr,"\nKey[0] = %x Key[1] = %x",dummy[0],dummy[1]);
170 #endif
171 #ifdef CROSSMSDOS
172             fprintf(stderr,"\nKey[0] = %X Key[1] = %X",dummy[0],dummy[1]);
173 #endif
174             des_key_sched(dummy,KS);
175 #ifdef BSDUNIX
176             fprintf(stderr,"\nKS= %x", * (afs_int32 * ) KS);
177 #endif
178 #ifdef CROSSMSDOS
179             fprintf(stderr,"\nKS= %X", * (afs_int32 * ) KS);
180 #endif
181         }
182
183         printf("\nstring to key 'e'");
184         des_string_to_key("e",dummy);
185 #ifdef BSDUNIX
186         fprintf(stderr,"\nKey[0] = %x Key[1] = %x",dummy[0],dummy[1]);
187 #endif
188 #ifdef CROSSMSDOS
189         fprintf(stderr,"\nKey[0] = %X Key[1] = %X",dummy[0],dummy[1]);
190 #endif
191         des_key_sched(dummy,KS);
192 #ifdef BSDUNIX
193         fprintf(stderr,"\nKS= %x",KS[0]);
194 #endif
195 #ifdef CROSSMSDOS
196         fprintf(stderr,"\nKS= %X",KS[0]);
197 #endif
198
199         printf("\ndes_string_to_key '%s'",argv[0]);
200         des_string_to_key(argv[0],dummy);
201 #ifdef notdef
202         des_string_to_key(argv[0],dummy);
203
204         for (i =0; i<1; i++)
205             des_key_sched(dummy,KS);
206     }
207     else
208     {
209         for (i =0; i<1000; i++) {
210             des_string_to_key(argv[0],kk);
211             des_key_sched(kk,KS);
212         }
213 #endif
214     }
215 }