summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/cast/casttest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/cast/casttest.c')
-rw-r--r--src/lib/libcrypto/cast/casttest.c183
1 files changed, 95 insertions, 88 deletions
diff --git a/src/lib/libcrypto/cast/casttest.c b/src/lib/libcrypto/cast/casttest.c
index 8b009bc249..3244b119e9 100644
--- a/src/lib/libcrypto/cast/casttest.c
+++ b/src/lib/libcrypto/cast/casttest.c
@@ -59,9 +59,17 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include <stdlib.h> 61#include <stdlib.h>
62#include "cast.h"
63 62
64/* #define FULL_TEST */ 63#ifdef NO_CAST
64int main(int argc, char *argv[])
65{
66 printf("No CAST support\n");
67 return(0);
68}
69#else
70#include <openssl/cast.h>
71
72#define FULL_TEST
65 73
66unsigned char k[16]={ 74unsigned char k[16]={
67 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, 75 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
@@ -70,7 +78,7 @@ unsigned char k[16]={
70 78
71unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; 79unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
72 80
73int k_len[3]={16,10}; 81int k_len[3]={16,10,5};
74unsigned char c[3][8]={ 82unsigned char c[3][8]={
75 {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2}, 83 {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2},
76 {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B}, 84 {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B},
@@ -120,104 +128,103 @@ static unsigned char cfb_cipher64[CFB_TEST_SIZE]={
120 }; 128 };
121#endif 129#endif
122 130
123int main(argc,argv) 131int main(int argc, char *argv[])
124int argc; 132 {
125char *argv[];
126 {
127#ifdef FULL_TEST 133#ifdef FULL_TEST
128 long l; 134 long l;
129 CAST_KEY key_b; 135 CAST_KEY key_b;
130#endif 136#endif
131 int i,z,err=0; 137 int i,z,err=0;
132 CAST_KEY key; 138 CAST_KEY key;
133 139
134 for (z=0; z<1; z++) 140 for (z=0; z<3; z++)
135 { 141 {
136 CAST_set_key(&key,k_len[z],k); 142 CAST_set_key(&key,k_len[z],k);
137 143
138 CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT); 144 CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT);
139 if (memcmp(out,&(c[z][0]),8) != 0) 145 if (memcmp(out,&(c[z][0]),8) != 0)
140 { 146 {
141 printf("ecb cast error encrypting\n"); 147 printf("ecb cast error encrypting for keysize %d\n",k_len[z]*8);
142 printf("got :"); 148 printf("got :");
143 for (i=0; i<8; i++) 149 for (i=0; i<8; i++)
144 printf("%02X ",out[i]); 150 printf("%02X ",out[i]);
145 printf("\n"); 151 printf("\n");
146 printf("expected:"); 152 printf("expected:");
147 for (i=0; i<8; i++) 153 for (i=0; i<8; i++)
148 printf("%02X ",c[z][i]); 154 printf("%02X ",c[z][i]);
149 err=20; 155 err=20;
150 printf("\n"); 156 printf("\n");
151 } 157 }
152 158
153 CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT); 159 CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT);
154 if (memcmp(out,in,8) != 0) 160 if (memcmp(out,in,8) != 0)
155 { 161 {
156 printf("ecb cast error decrypting\n"); 162 printf("ecb cast error decrypting for keysize %d\n",k_len[z]*8);
157 printf("got :"); 163 printf("got :");
158 for (i=0; i<8; i++) 164 for (i=0; i<8; i++)
159 printf("%02X ",out[i]); 165 printf("%02X ",out[i]);
160 printf("\n"); 166 printf("\n");
161 printf("expected:"); 167 printf("expected:");
162 for (i=0; i<8; i++) 168 for (i=0; i<8; i++)
163 printf("%02X ",in[i]); 169 printf("%02X ",in[i]);
164 printf("\n"); 170 printf("\n");
165 err=3; 171 err=3;
166 } 172 }
167 } 173 }
168 if (err == 0) printf("ecb cast5 ok\n"); 174 if (err == 0)
175 printf("ecb cast5 ok\n");
169 176
170#ifdef FULL_TEST 177#ifdef FULL_TEST
171 { 178 {
172 unsigned char out_a[16],out_b[16]; 179 unsigned char out_a[16],out_b[16];
173 static char *hex="0123456789ABCDEF"; 180 static char *hex="0123456789ABCDEF";
174 181
175 printf("This test will take some time...."); 182 printf("This test will take some time....");
176 fflush(stdout); 183 fflush(stdout);
177 memcpy(out_a,in_a,sizeof(in_a)); 184 memcpy(out_a,in_a,sizeof(in_a));
178 memcpy(out_b,in_b,sizeof(in_b)); 185 memcpy(out_b,in_b,sizeof(in_b));
179 i=1; 186 i=1;
180 187
181 for (l=0; l<1000000L; l++) 188 for (l=0; l<1000000L; l++)
182 { 189 {
183 CAST_set_key(&key_b,16,out_b); 190 CAST_set_key(&key_b,16,out_b);
184 CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT); 191 CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT);
185 CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT); 192 CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT);
186 CAST_set_key(&key,16,out_a); 193 CAST_set_key(&key,16,out_a);
187 CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT); 194 CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT);
188 CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT); 195 CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT);
189 if ((l & 0xffff) == 0xffff) 196 if ((l & 0xffff) == 0xffff)
190 { 197 {
191 printf("%c",hex[i&0x0f]); 198 printf("%c",hex[i&0x0f]);
192 fflush(stdout); 199 fflush(stdout);
193 i++; 200 i++;
194 } 201 }
195 } 202 }
196 203
197 if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) || 204 if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) ||
198 (memcmp(out_b,c_b,sizeof(c_b)) != 0)) 205 (memcmp(out_b,c_b,sizeof(c_b)) != 0))
199 { 206 {
200 printf("\n"); 207 printf("\n");
201 printf("Error\n"); 208 printf("Error\n");
202 209
203 printf("A out ="); 210 printf("A out =");
204 for (i=0; i<16; i++) printf("%02X ",out_a[i]); 211 for (i=0; i<16; i++) printf("%02X ",out_a[i]);
205 printf("\nactual="); 212 printf("\nactual=");
206 for (i=0; i<16; i++) printf("%02X ",c_a[i]); 213 for (i=0; i<16; i++) printf("%02X ",c_a[i]);
207 printf("\n"); 214 printf("\n");
208 215
209 printf("B out ="); 216 printf("B out =");
210 for (i=0; i<16; i++) printf("%02X ",out_b[i]); 217 for (i=0; i<16; i++) printf("%02X ",out_b[i]);
211 printf("\nactual="); 218 printf("\nactual=");
212 for (i=0; i<16; i++) printf("%02X ",c_b[i]); 219 for (i=0; i<16; i++) printf("%02X ",c_b[i]);
213 printf("\n"); 220 printf("\n");
214 } 221 }
215 else 222 else
216 printf(" ok\n"); 223 printf(" ok\n");
217 } 224 }
218#endif 225#endif
219 226
220 exit(err); 227 exit(err);
221 return(err); 228 return(err);
222 } 229 }
223 230#endif