2 * Copyright 1988 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
7 * exit returns 0 ==> success
12 static char rcsid_testit_c[] =
15 #include <mit-cpyright.h>
19 #include <afs/param.h>
21 #define MIN_ARGC 0 /* min # args, not incl flags */
22 #define MAX_ARGC 2 /* max # args, not incl flags */
24 /* MIN_ARGC == MAX_ARGC ==> required # args */
26 extern char *errmsg();
27 extern int des_string_to_key();
28 extern int des_key_sched();
29 extern int des_ecb_encrypt();
30 extern int des_cbc_encrypt();
31 extern int des_pcbc_encrypt();
33 #include "../../permit_xprt.h"
43 unsigned char cipher_text[64];
44 unsigned char clear_text[64] = "Now is the time for all " ;
45 unsigned char clear_text2[64] = "7654321 Now is the time for ";
46 unsigned char clear_text3[64] = {2,0,0,0, 1,0,0,0};
49 /* 0x0123456789abcdef */
50 des_cblock default_key = { 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef };
52 des_cblock default_ivec = { 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef };
54 des_cblock zero_key = {1};
61 /* Local Declarations */
65 progname=argv[0]; /* salt away invoking program */
67 /* Assume a long is four bytes */
68 if (sizeof(long) != 4) {
69 fprintf(stdout,"\nERROR, size of long is %d",sizeof(long));
73 while (--argc > 0 && (*++argv)[0] == '-')
74 for (i=1; argv[0][i] != '\0'; i++) {
92 /* string to key only flag */
97 /* test flag - use known key and cleartext */
102 /* iteration count */
104 sscanf(&argv[0][i+1],"%d",&nflag);
105 argv[0][i+1] = '\0'; /* force it to stop */
109 printf("%s: illegal flag \"%c\" ",
110 progname,argv[0][i]);
115 if (argc < MIN_ARGC || argc >MAX_ARGC) {
116 printf("Usage: xxx [-xxx] xxx xxx\n");
120 /* argv[0] now points to first non-option arg, if any */
123 /* use known input and key */
124 des_key_sched(default_key,KS);
126 ivec = (unsigned char *) default_ivec;
129 /*des_string_to_key(argv[0],s_key); */
130 des_string_to_key("test",s_key);
132 input = (unsigned char *) s_key;
133 fprintf(stdout,"\nstring = %s, key = ",argv[0]);
134 for (i = 0; i<=7 ; i++) fprintf(stdout,"%02x ",*input++);
136 des_string_to_key("test",s_key);
138 input = (unsigned char *) s_key;
139 fprintf(stdout,"\nstring = %s, key = ",argv[0]);
140 for (i = 0; i<=7 ; i++) fprintf(stdout,"%02x ",*input++);
142 des_key_sched(s_key,KS);
143 input = (unsigned char *) argv[1];
144 ivec = (unsigned char *) argv[2];
149 fprintf(stdout,"\nclear %s\n",input);
150 in_length = strlen(input);
151 des_cbc_encrypt(input,cipher_text,(long) in_length,KS,ivec,1);
153 "\n\nencrypted ciphertext = (low to high bytes)");
154 for (i = 0; i <= 7; i++) {
155 fprintf(stdout,"\n");
156 for (j = 0; j <= 7; j++)
157 fprintf(stdout,"%02x ",cipher_text[i*8+j]);
159 des_cbc_encrypt(cipher_text, clear_text,
160 (long) in_length, KS, ivec, 0);
161 fprintf(stdout,"\n\ndecrypted clear_text = %s",clear_text);
163 fprintf(stdout,"\nclear %s\n",input);
165 des_cbc_cksum(input,cipher_text,(long) strlen(input),KS,ivec,1);
167 "\n\nencrypted cksum = (low to high bytes)\n");
168 for (j = 0; j <= 7; j++)
169 fprintf(stdout,"%02x ",cipher_text[j]);
171 /* test out random number generator */
172 for (i = 0; i <= 7; i++) {
173 des_random_key(cipher_text);
174 des_key_sched(cipher_text,KS);
176 "\n\nrandom key = (low to high bytes)\n");
177 for (j = 0; j<=7; j++)
178 fprintf(stdout,"%02x ",cipher_text[j]);
183 fprintf(stdout,"\nclear %s\n",input);
184 do_encrypt(input,cipher_text);
185 do_decrypt(clear_text,cipher_text);
192 register old,new,i,j;
193 /* flips the bit order within each byte from 0 lsb to 0 msb */
194 for (i = 0; i <= 7; i++) {
197 for (j = 0; j <= 7; j++) {
198 if (old & 01) new = new | 01;
213 for (i = 1; i <= nflag; i++) {
214 des_ecb_encrypt(in,out,KS,1);
216 fprintf(stdout,"\nclear %s\n",in);
217 for (j = 0; j <= 7; j++)
218 fprintf(stdout,"%02 X ",in[j] & 0xff);
219 fprintf(stdout,"\tcipher ");
220 for (j = 0; j<=7; j++)
221 fprintf(stdout,"%02X ",out[j] & 0xff);
229 /* try to invert it */
231 for (i = 1; i <= nflag; i++) {
232 des_ecb_encrypt(out,in,KS,0);
234 fprintf(stdout,"\nclear %s\n",in);
235 for (j = 0; j <= 7; j++)
236 fprintf(stdout,"%02X ",in[j] & 0xff);
237 fprintf(stdout,"\tcipher ");
238 for (j = 0; j<=7; j++)
239 fprintf(stdout,"%02X ",out[j] & 0xff);