diff options
Diffstat (limited to 'src/lib/libcrypto/des/destest.c')
-rw-r--r-- | src/lib/libcrypto/des/destest.c | 410 |
1 files changed, 237 insertions, 173 deletions
diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c index 620c13ba6f..58e8c35dcb 100644 --- a/src/lib/libcrypto/des/destest.c +++ b/src/lib/libcrypto/des/destest.c | |||
@@ -56,21 +56,37 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #if defined(WIN32) || defined(WIN16) || defined(WINDOWS) | 59 | #include <stdio.h> |
60 | #ifndef MSDOS | 60 | #include <stdlib.h> |
61 | #define MSDOS | 61 | |
62 | #include <openssl/e_os2.h> | ||
63 | #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_WINDOWS) | ||
64 | #ifndef OPENSSL_SYS_MSDOS | ||
65 | #define OPENSSL_SYS_MSDOS | ||
62 | #endif | 66 | #endif |
63 | #endif | 67 | #endif |
64 | 68 | ||
65 | #include <stdio.h> | 69 | #ifndef OPENSSL_SYS_MSDOS |
66 | #include <stdlib.h> | 70 | #if !defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_VMS_DECC) |
67 | #ifndef MSDOS | 71 | #include OPENSSL_UNISTD |
68 | #include <unistd.h> | 72 | #endif |
69 | #else | 73 | #else |
70 | #include <io.h> | 74 | #include <io.h> |
71 | #endif | 75 | #endif |
72 | #include <string.h> | 76 | #include <string.h> |
73 | #include "des.h" | 77 | |
78 | #ifdef OPENSSL_NO_DES | ||
79 | int main(int argc, char *argv[]) | ||
80 | { | ||
81 | printf("No DES support\n"); | ||
82 | return(0); | ||
83 | } | ||
84 | #else | ||
85 | #include <openssl/des.h> | ||
86 | |||
87 | #if defined(PERL5) || defined(__FreeBSD__) || defined(NeXT) | ||
88 | #define crypt(c,s) (des_crypt((c),(s))) | ||
89 | #endif | ||
74 | 90 | ||
75 | /* tisk tisk - the test keys don't all have odd parity :-( */ | 91 | /* tisk tisk - the test keys don't all have odd parity :-( */ |
76 | /* test data */ | 92 | /* test data */ |
@@ -219,13 +235,13 @@ static unsigned char cipher_ecb2[NUM_TESTS-1][8]={ | |||
219 | {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}}; | 235 | {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}}; |
220 | 236 | ||
221 | static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; | 237 | static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; |
222 | static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; | 238 | static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86}; |
223 | static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; | 239 | static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; |
224 | static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; | 240 | static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; |
225 | /* Changed the following text constant to binary so it will work on ebcdic | 241 | /* Changed the following text constant to binary so it will work on ebcdic |
226 | * machines :-) */ | 242 | * machines :-) */ |
227 | /* static char cbc_data[40]="7654321 Now is the time for \0001"; */ | 243 | /* static char cbc_data[40]="7654321 Now is the time for \0001"; */ |
228 | static char cbc_data[40]={ | 244 | static unsigned char cbc_data[40]={ |
229 | 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20, | 245 | 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20, |
230 | 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74, | 246 | 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74, |
231 | 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20, | 247 | 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20, |
@@ -239,12 +255,24 @@ static unsigned char cbc_ok[32]={ | |||
239 | 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68, | 255 | 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68, |
240 | 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; | 256 | 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; |
241 | 257 | ||
258 | #ifdef SCREW_THE_PARITY | ||
259 | #error "SCREW_THE_PARITY is not ment to be defined." | ||
260 | #error "Original vectors are preserved for reference only." | ||
261 | static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; | ||
242 | static unsigned char xcbc_ok[32]={ | 262 | static unsigned char xcbc_ok[32]={ |
243 | 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48, | 263 | 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48, |
244 | 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD, | 264 | 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD, |
245 | 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76, | 265 | 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76, |
246 | 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2, | 266 | 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2, |
247 | }; | 267 | }; |
268 | #else | ||
269 | static unsigned char xcbc_ok[32]={ | ||
270 | 0x84,0x6B,0x29,0x14,0x85,0x1E,0x9A,0x29, | ||
271 | 0x54,0x73,0x2F,0x8A,0xA0,0xA6,0x11,0xC1, | ||
272 | 0x15,0xCD,0xC2,0xD7,0x95,0x1B,0x10,0x53, | ||
273 | 0xA6,0x3C,0x5E,0x03,0xB2,0x1A,0xA3,0xC4, | ||
274 | }; | ||
275 | #endif | ||
248 | 276 | ||
249 | static unsigned char cbc3_ok[32]={ | 277 | static unsigned char cbc3_ok[32]={ |
250 | 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0, | 278 | 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0, |
@@ -294,49 +322,95 @@ static unsigned char ofb_cipher[24]= | |||
294 | 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3 | 322 | 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3 |
295 | }; | 323 | }; |
296 | 324 | ||
297 | DES_LONG cbc_cksum_ret=0xB462FEF7L; | 325 | static DES_LONG cbc_cksum_ret=0xB462FEF7L; |
298 | unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; | 326 | static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; |
299 | 327 | ||
300 | #ifndef NOPROTO | ||
301 | static char *pt(unsigned char *p); | 328 | static char *pt(unsigned char *p); |
302 | static int cfb_test(int bits, unsigned char *cfb_cipher); | 329 | static int cfb_test(int bits, unsigned char *cfb_cipher); |
303 | static int cfb64_test(unsigned char *cfb_cipher); | 330 | static int cfb64_test(unsigned char *cfb_cipher); |
304 | static int ede_cfb64_test(unsigned char *cfb_cipher); | 331 | static int ede_cfb64_test(unsigned char *cfb_cipher); |
305 | #else | 332 | int main(int argc, char *argv[]) |
306 | static char *pt(); | ||
307 | static int cfb_test(); | ||
308 | static int cfb64_test(); | ||
309 | static int ede_cfb64_test(); | ||
310 | #endif | ||
311 | |||
312 | int main(argc,argv) | ||
313 | int argc; | ||
314 | char *argv[]; | ||
315 | { | 333 | { |
316 | int i,j,err=0; | 334 | int i,j,err=0; |
317 | des_cblock in,out,outin,iv3; | 335 | des_cblock in,out,outin,iv3,iv2; |
318 | des_key_schedule ks,ks2,ks3; | 336 | des_key_schedule ks,ks2,ks3; |
319 | unsigned char cbc_in[40]; | 337 | unsigned char cbc_in[40]; |
320 | unsigned char cbc_out[40]; | 338 | unsigned char cbc_out[40]; |
321 | DES_LONG cs; | 339 | DES_LONG cs; |
322 | unsigned char qret[4][4],cret[8]; | 340 | unsigned char cret[8]; |
323 | DES_LONG lqret[4]; | 341 | #ifdef _CRAY |
342 | struct { | ||
343 | int a:32; | ||
344 | int b:32; | ||
345 | } lqret[2]; | ||
346 | #else | ||
347 | DES_LONG lqret[4]; | ||
348 | #endif | ||
324 | int num; | 349 | int num; |
325 | char *str; | 350 | char *str; |
326 | 351 | ||
352 | #ifndef OPENSSL_NO_DESCBCM | ||
353 | printf("Doing cbcm\n"); | ||
354 | if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0) | ||
355 | { | ||
356 | printf("Key error %d\n",j); | ||
357 | err=1; | ||
358 | } | ||
359 | if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0) | ||
360 | { | ||
361 | printf("Key error %d\n",j); | ||
362 | err=1; | ||
363 | } | ||
364 | if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0) | ||
365 | { | ||
366 | printf("Key error %d\n",j); | ||
367 | err=1; | ||
368 | } | ||
369 | memset(cbc_out,0,40); | ||
370 | memset(cbc_in,0,40); | ||
371 | i=strlen((char *)cbc_data)+1; | ||
372 | /* i=((i+7)/8)*8; */ | ||
373 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
374 | memset(iv2,'\0',sizeof iv2); | ||
375 | |||
376 | DES_ede3_cbcm_encrypt(cbc_data,cbc_out,16L,&ks,&ks2,&ks3,&iv3,&iv2, | ||
377 | DES_ENCRYPT); | ||
378 | DES_ede3_cbcm_encrypt(&cbc_data[16],&cbc_out[16],i-16,&ks,&ks2,&ks3, | ||
379 | &iv3,&iv2,DES_ENCRYPT); | ||
380 | /* if (memcmp(cbc_out,cbc3_ok, | ||
381 | (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0) | ||
382 | { | ||
383 | printf("des_ede3_cbc_encrypt encrypt error\n"); | ||
384 | err=1; | ||
385 | } | ||
386 | */ | ||
387 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
388 | memset(iv2,'\0',sizeof iv2); | ||
389 | DES_ede3_cbcm_encrypt(cbc_out,cbc_in,i,&ks,&ks2,&ks3,&iv3,&iv2,DES_DECRYPT); | ||
390 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) | ||
391 | { | ||
392 | int n; | ||
393 | |||
394 | printf("des_ede3_cbcm_encrypt decrypt error\n"); | ||
395 | for(n=0 ; n < i ; ++n) | ||
396 | printf(" %02x",cbc_data[n]); | ||
397 | printf("\n"); | ||
398 | for(n=0 ; n < i ; ++n) | ||
399 | printf(" %02x",cbc_in[n]); | ||
400 | printf("\n"); | ||
401 | err=1; | ||
402 | } | ||
403 | #endif | ||
404 | |||
327 | printf("Doing ecb\n"); | 405 | printf("Doing ecb\n"); |
328 | for (i=0; i<NUM_TESTS; i++) | 406 | for (i=0; i<NUM_TESTS; i++) |
329 | { | 407 | { |
330 | if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0) | 408 | DES_set_key_unchecked(&key_data[i],&ks); |
331 | { | ||
332 | printf("Key error %2d:%d\n",i+1,j); | ||
333 | err=1; | ||
334 | } | ||
335 | memcpy(in,plain_data[i],8); | 409 | memcpy(in,plain_data[i],8); |
336 | memset(out,0,8); | 410 | memset(out,0,8); |
337 | memset(outin,0,8); | 411 | memset(outin,0,8); |
338 | des_ecb_encrypt((C_Block *)in,(C_Block *)out,ks,DES_ENCRYPT); | 412 | des_ecb_encrypt(&in,&out,ks,DES_ENCRYPT); |
339 | des_ecb_encrypt((C_Block *)out,(C_Block *)outin,ks,DES_DECRYPT); | 413 | des_ecb_encrypt(&out,&outin,ks,DES_DECRYPT); |
340 | 414 | ||
341 | if (memcmp(out,cipher_data[i],8) != 0) | 415 | if (memcmp(out,cipher_data[i],8) != 0) |
342 | { | 416 | { |
@@ -357,28 +431,14 @@ char *argv[]; | |||
357 | printf("Doing ede ecb\n"); | 431 | printf("Doing ede ecb\n"); |
358 | for (i=0; i<(NUM_TESTS-1); i++) | 432 | for (i=0; i<(NUM_TESTS-1); i++) |
359 | { | 433 | { |
360 | if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0) | 434 | DES_set_key_unchecked(&key_data[i],&ks); |
361 | { | 435 | DES_set_key_unchecked(&key_data[i+1],&ks2); |
362 | err=1; | 436 | DES_set_key_unchecked(&key_data[i+2],&ks3); |
363 | printf("Key error %2d:%d\n",i+1,j); | ||
364 | } | ||
365 | if ((j=des_key_sched((C_Block *)(key_data[i+1]),ks2)) != 0) | ||
366 | { | ||
367 | printf("Key error %2d:%d\n",i+2,j); | ||
368 | err=1; | ||
369 | } | ||
370 | if ((j=des_key_sched((C_Block *)(key_data[i+2]),ks3)) != 0) | ||
371 | { | ||
372 | printf("Key error %2d:%d\n",i+3,j); | ||
373 | err=1; | ||
374 | } | ||
375 | memcpy(in,plain_data[i],8); | 437 | memcpy(in,plain_data[i],8); |
376 | memset(out,0,8); | 438 | memset(out,0,8); |
377 | memset(outin,0,8); | 439 | memset(outin,0,8); |
378 | des_ecb2_encrypt((C_Block *)in,(C_Block *)out,ks,ks2, | 440 | des_ecb2_encrypt(&in,&out,ks,ks2,DES_ENCRYPT); |
379 | DES_ENCRYPT); | 441 | des_ecb2_encrypt(&out,&outin,ks,ks2,DES_DECRYPT); |
380 | des_ecb2_encrypt((C_Block *)out,(C_Block *)outin,ks,ks2, | ||
381 | DES_DECRYPT); | ||
382 | 442 | ||
383 | if (memcmp(out,cipher_ecb2[i],8) != 0) | 443 | if (memcmp(out,cipher_ecb2[i],8) != 0) |
384 | { | 444 | { |
@@ -397,7 +457,7 @@ char *argv[]; | |||
397 | #endif | 457 | #endif |
398 | 458 | ||
399 | printf("Doing cbc\n"); | 459 | printf("Doing cbc\n"); |
400 | if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) | 460 | if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0) |
401 | { | 461 | { |
402 | printf("Key error %d\n",j); | 462 | printf("Key error %d\n",j); |
403 | err=1; | 463 | err=1; |
@@ -405,16 +465,17 @@ char *argv[]; | |||
405 | memset(cbc_out,0,40); | 465 | memset(cbc_out,0,40); |
406 | memset(cbc_in,0,40); | 466 | memset(cbc_in,0,40); |
407 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | 467 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); |
408 | des_ncbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, | 468 | des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks, |
409 | (long)strlen((char *)cbc_data)+1,ks, | 469 | &iv3,DES_ENCRYPT); |
410 | (C_Block *)iv3,DES_ENCRYPT); | ||
411 | if (memcmp(cbc_out,cbc_ok,32) != 0) | 470 | if (memcmp(cbc_out,cbc_ok,32) != 0) |
471 | { | ||
412 | printf("cbc_encrypt encrypt error\n"); | 472 | printf("cbc_encrypt encrypt error\n"); |
473 | err=1; | ||
474 | } | ||
413 | 475 | ||
414 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | 476 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); |
415 | des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, | 477 | des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks, |
416 | (long)strlen((char *)cbc_data)+1,ks, | 478 | &iv3,DES_DECRYPT); |
417 | (C_Block *)iv3,DES_DECRYPT); | ||
418 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0) | 479 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0) |
419 | { | 480 | { |
420 | printf("cbc_encrypt decrypt error\n"); | 481 | printf("cbc_encrypt decrypt error\n"); |
@@ -423,7 +484,7 @@ char *argv[]; | |||
423 | 484 | ||
424 | #ifndef LIBDES_LIT | 485 | #ifndef LIBDES_LIT |
425 | printf("Doing desx cbc\n"); | 486 | printf("Doing desx cbc\n"); |
426 | if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) | 487 | if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0) |
427 | { | 488 | { |
428 | printf("Key error %d\n",j); | 489 | printf("Key error %d\n",j); |
429 | err=1; | 490 | err=1; |
@@ -431,19 +492,16 @@ char *argv[]; | |||
431 | memset(cbc_out,0,40); | 492 | memset(cbc_out,0,40); |
432 | memset(cbc_in,0,40); | 493 | memset(cbc_in,0,40); |
433 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | 494 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); |
434 | des_xcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, | 495 | des_xcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks, |
435 | (long)strlen((char *)cbc_data)+1,ks, | 496 | &iv3,&cbc2_key,&cbc3_key, DES_ENCRYPT); |
436 | (C_Block *)iv3, | ||
437 | (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_ENCRYPT); | ||
438 | if (memcmp(cbc_out,xcbc_ok,32) != 0) | 497 | if (memcmp(cbc_out,xcbc_ok,32) != 0) |
439 | { | 498 | { |
440 | printf("des_xcbc_encrypt encrypt error\n"); | 499 | printf("des_xcbc_encrypt encrypt error\n"); |
500 | err=1; | ||
441 | } | 501 | } |
442 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | 502 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); |
443 | des_xcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, | 503 | des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks, |
444 | (long)strlen((char *)cbc_data)+1,ks, | 504 | &iv3,&cbc2_key,&cbc3_key, DES_DECRYPT); |
445 | (C_Block *)iv3, | ||
446 | (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_DECRYPT); | ||
447 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) | 505 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) |
448 | { | 506 | { |
449 | printf("des_xcbc_encrypt decrypt error\n"); | 507 | printf("des_xcbc_encrypt decrypt error\n"); |
@@ -452,17 +510,17 @@ char *argv[]; | |||
452 | #endif | 510 | #endif |
453 | 511 | ||
454 | printf("Doing ede cbc\n"); | 512 | printf("Doing ede cbc\n"); |
455 | if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) | 513 | if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0) |
456 | { | 514 | { |
457 | printf("Key error %d\n",j); | 515 | printf("Key error %d\n",j); |
458 | err=1; | 516 | err=1; |
459 | } | 517 | } |
460 | if ((j=des_key_sched((C_Block *)cbc2_key,ks2)) != 0) | 518 | if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0) |
461 | { | 519 | { |
462 | printf("Key error %d\n",j); | 520 | printf("Key error %d\n",j); |
463 | err=1; | 521 | err=1; |
464 | } | 522 | } |
465 | if ((j=des_key_sched((C_Block *)cbc3_key,ks3)) != 0) | 523 | if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0) |
466 | { | 524 | { |
467 | printf("Key error %d\n",j); | 525 | printf("Key error %d\n",j); |
468 | err=1; | 526 | err=1; |
@@ -473,46 +531,60 @@ char *argv[]; | |||
473 | /* i=((i+7)/8)*8; */ | 531 | /* i=((i+7)/8)*8; */ |
474 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | 532 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); |
475 | 533 | ||
476 | des_ede3_cbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, | 534 | des_ede3_cbc_encrypt(cbc_data,cbc_out,16L,ks,ks2,ks3,&iv3, |
477 | 16L,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT); | 535 | DES_ENCRYPT); |
478 | des_ede3_cbc_encrypt((C_Block *)&(cbc_data[16]), | 536 | des_ede3_cbc_encrypt(&(cbc_data[16]),&(cbc_out[16]),i-16,ks,ks2,ks3, |
479 | (C_Block *)&(cbc_out[16]), | 537 | &iv3,DES_ENCRYPT); |
480 | (long)i-16,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT); | ||
481 | if (memcmp(cbc_out,cbc3_ok, | 538 | if (memcmp(cbc_out,cbc3_ok, |
482 | (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0) | 539 | (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0) |
483 | { | 540 | { |
541 | int n; | ||
542 | |||
484 | printf("des_ede3_cbc_encrypt encrypt error\n"); | 543 | printf("des_ede3_cbc_encrypt encrypt error\n"); |
544 | for(n=0 ; n < i ; ++n) | ||
545 | printf(" %02x",cbc_out[n]); | ||
546 | printf("\n"); | ||
547 | for(n=0 ; n < i ; ++n) | ||
548 | printf(" %02x",cbc3_ok[n]); | ||
549 | printf("\n"); | ||
485 | err=1; | 550 | err=1; |
486 | } | 551 | } |
487 | 552 | ||
488 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | 553 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); |
489 | des_ede3_cbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, | 554 | des_ede3_cbc_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,&iv3,DES_DECRYPT); |
490 | (long)i,ks,ks2,ks3,(C_Block *)iv3,DES_DECRYPT); | 555 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) |
491 | if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0) | ||
492 | { | 556 | { |
557 | int n; | ||
558 | |||
493 | printf("des_ede3_cbc_encrypt decrypt error\n"); | 559 | printf("des_ede3_cbc_encrypt decrypt error\n"); |
560 | for(n=0 ; n < i ; ++n) | ||
561 | printf(" %02x",cbc_data[n]); | ||
562 | printf("\n"); | ||
563 | for(n=0 ; n < i ; ++n) | ||
564 | printf(" %02x",cbc_in[n]); | ||
565 | printf("\n"); | ||
494 | err=1; | 566 | err=1; |
495 | } | 567 | } |
496 | 568 | ||
497 | #ifndef LIBDES_LIT | 569 | #ifndef LIBDES_LIT |
498 | printf("Doing pcbc\n"); | 570 | printf("Doing pcbc\n"); |
499 | if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) | 571 | if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0) |
500 | { | 572 | { |
501 | printf("Key error %d\n",j); | 573 | printf("Key error %d\n",j); |
502 | err=1; | 574 | err=1; |
503 | } | 575 | } |
504 | memset(cbc_out,0,40); | 576 | memset(cbc_out,0,40); |
505 | memset(cbc_in,0,40); | 577 | memset(cbc_in,0,40); |
506 | des_pcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, | 578 | des_pcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks, |
507 | (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_ENCRYPT); | 579 | &cbc_iv,DES_ENCRYPT); |
508 | if (memcmp(cbc_out,pcbc_ok,32) != 0) | 580 | if (memcmp(cbc_out,pcbc_ok,32) != 0) |
509 | { | 581 | { |
510 | printf("pcbc_encrypt encrypt error\n"); | 582 | printf("pcbc_encrypt encrypt error\n"); |
511 | err=1; | 583 | err=1; |
512 | } | 584 | } |
513 | des_pcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, | 585 | des_pcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,&cbc_iv, |
514 | (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_DECRYPT); | 586 | DES_DECRYPT); |
515 | if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0) | 587 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) |
516 | { | 588 | { |
517 | printf("pcbc_encrypt decrypt error\n"); | 589 | printf("pcbc_encrypt decrypt error\n"); |
518 | err=1; | 590 | err=1; |
@@ -536,7 +608,7 @@ char *argv[]; | |||
536 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | 608 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); |
537 | for (i=0; i<sizeof(plain); i++) | 609 | for (i=0; i<sizeof(plain); i++) |
538 | des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]), | 610 | des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]), |
539 | 8,(long)1,ks,(C_Block *)cfb_tmp,DES_ENCRYPT); | 611 | 8,1,ks,&cfb_tmp,DES_ENCRYPT); |
540 | if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0) | 612 | if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0) |
541 | { | 613 | { |
542 | printf("cfb_encrypt small encrypt error\n"); | 614 | printf("cfb_encrypt small encrypt error\n"); |
@@ -546,7 +618,7 @@ char *argv[]; | |||
546 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | 618 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); |
547 | for (i=0; i<sizeof(plain); i++) | 619 | for (i=0; i<sizeof(plain); i++) |
548 | des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]), | 620 | des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]), |
549 | 8,(long)1,ks,(C_Block *)cfb_tmp,DES_DECRYPT); | 621 | 8,1,ks,&cfb_tmp,DES_DECRYPT); |
550 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) | 622 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) |
551 | { | 623 | { |
552 | printf("cfb_encrypt small decrypt error\n"); | 624 | printf("cfb_encrypt small decrypt error\n"); |
@@ -559,10 +631,9 @@ char *argv[]; | |||
559 | printf("done\n"); | 631 | printf("done\n"); |
560 | 632 | ||
561 | printf("Doing ofb\n"); | 633 | printf("Doing ofb\n"); |
562 | des_key_sched((C_Block *)ofb_key,ks); | 634 | DES_set_key_checked(&ofb_key,&ks); |
563 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | 635 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); |
564 | des_ofb_encrypt(plain,ofb_buf1,64,(long)sizeof(plain)/8,ks, | 636 | des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp); |
565 | (C_Block *)ofb_tmp); | ||
566 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) | 637 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) |
567 | { | 638 | { |
568 | printf("ofb_encrypt encrypt error\n"); | 639 | printf("ofb_encrypt encrypt error\n"); |
@@ -575,8 +646,7 @@ ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]); | |||
575 | err=1; | 646 | err=1; |
576 | } | 647 | } |
577 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | 648 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); |
578 | des_ofb_encrypt(ofb_buf1,ofb_buf2,64,(long)sizeof(ofb_buf1)/8,ks, | 649 | des_ofb_encrypt(ofb_buf1,ofb_buf2,64,sizeof(ofb_buf1)/8,ks,&ofb_tmp); |
579 | (C_Block *)ofb_tmp); | ||
580 | if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) | 650 | if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) |
581 | { | 651 | { |
582 | printf("ofb_encrypt decrypt error\n"); | 652 | printf("ofb_encrypt decrypt error\n"); |
@@ -590,15 +660,15 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | |||
590 | } | 660 | } |
591 | 661 | ||
592 | printf("Doing ofb64\n"); | 662 | printf("Doing ofb64\n"); |
593 | des_key_sched((C_Block *)ofb_key,ks); | 663 | DES_set_key_checked(&ofb_key,&ks); |
594 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | 664 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); |
595 | memset(ofb_buf1,0,sizeof(ofb_buf1)); | 665 | memset(ofb_buf1,0,sizeof(ofb_buf1)); |
596 | memset(ofb_buf2,0,sizeof(ofb_buf1)); | 666 | memset(ofb_buf2,0,sizeof(ofb_buf1)); |
597 | num=0; | 667 | num=0; |
598 | for (i=0; i<sizeof(plain); i++) | 668 | for (i=0; i<sizeof(plain); i++) |
599 | { | 669 | { |
600 | des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks, | 670 | des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,&ofb_tmp, |
601 | (C_Block *)ofb_tmp,&num); | 671 | &num); |
602 | } | 672 | } |
603 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) | 673 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) |
604 | { | 674 | { |
@@ -607,8 +677,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | |||
607 | } | 677 | } |
608 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | 678 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); |
609 | num=0; | 679 | num=0; |
610 | des_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks, | 680 | des_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,&ofb_tmp, |
611 | (C_Block *)ofb_tmp,&num); | 681 | &num); |
612 | if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) | 682 | if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) |
613 | { | 683 | { |
614 | printf("ofb64_encrypt decrypt error\n"); | 684 | printf("ofb64_encrypt decrypt error\n"); |
@@ -616,15 +686,15 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | |||
616 | } | 686 | } |
617 | 687 | ||
618 | printf("Doing ede_ofb64\n"); | 688 | printf("Doing ede_ofb64\n"); |
619 | des_key_sched((C_Block *)ofb_key,ks); | 689 | DES_set_key_checked(&ofb_key,&ks); |
620 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | 690 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); |
621 | memset(ofb_buf1,0,sizeof(ofb_buf1)); | 691 | memset(ofb_buf1,0,sizeof(ofb_buf1)); |
622 | memset(ofb_buf2,0,sizeof(ofb_buf1)); | 692 | memset(ofb_buf2,0,sizeof(ofb_buf1)); |
623 | num=0; | 693 | num=0; |
624 | for (i=0; i<sizeof(plain); i++) | 694 | for (i=0; i<sizeof(plain); i++) |
625 | { | 695 | { |
626 | des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,ks, | 696 | des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks, |
627 | (C_Block *)ofb_tmp,&num); | 697 | ks,&ofb_tmp,&num); |
628 | } | 698 | } |
629 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) | 699 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) |
630 | { | 700 | { |
@@ -633,8 +703,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | |||
633 | } | 703 | } |
634 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | 704 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); |
635 | num=0; | 705 | num=0; |
636 | des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks, | 706 | des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,ks,ks, |
637 | ks,ks,(C_Block *)ofb_tmp,&num); | 707 | &ofb_tmp,&num); |
638 | if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) | 708 | if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) |
639 | { | 709 | { |
640 | printf("ede_ofb64_encrypt decrypt error\n"); | 710 | printf("ede_ofb64_encrypt decrypt error\n"); |
@@ -642,9 +712,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | |||
642 | } | 712 | } |
643 | 713 | ||
644 | printf("Doing cbc_cksum\n"); | 714 | printf("Doing cbc_cksum\n"); |
645 | des_key_sched((C_Block *)cbc_key,ks); | 715 | DES_set_key_checked(&cbc_key,&ks); |
646 | cs=des_cbc_cksum((C_Block *)cbc_data,(C_Block *)cret, | 716 | cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv); |
647 | (long)strlen(cbc_data),ks,(C_Block *)cbc_iv); | ||
648 | if (cs != cbc_cksum_ret) | 717 | if (cs != cbc_cksum_ret) |
649 | { | 718 | { |
650 | printf("bad return value (%08lX), should be %08lX\n", | 719 | printf("bad return value (%08lX), should be %08lX\n", |
@@ -658,77 +727,82 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | |||
658 | } | 727 | } |
659 | 728 | ||
660 | printf("Doing quad_cksum\n"); | 729 | printf("Doing quad_cksum\n"); |
661 | cs=quad_cksum((C_Block *)cbc_data,(C_Block *)qret, | 730 | cs=des_quad_cksum(cbc_data,(des_cblock *)lqret, |
662 | (long)strlen(cbc_data),2,(C_Block *)cbc_iv); | 731 | (long)strlen((char *)cbc_data),2,(des_cblock *)cbc_iv); |
663 | j=sizeof(lqret[0])-4; | 732 | if (cs != 0x70d7a63aL) |
664 | for (i=0; i<4; i++) | 733 | { |
734 | printf("quad_cksum error, ret %08lx should be 70d7a63a\n", | ||
735 | (unsigned long)cs); | ||
736 | err=1; | ||
737 | } | ||
738 | #ifdef _CRAY | ||
739 | if (lqret[0].a != 0x327eba8dL) | ||
665 | { | 740 | { |
666 | lqret[i]=0; | 741 | printf("quad_cksum error, out[0] %08lx is not %08lx\n", |
667 | memcpy(&(lqret[i]),&(qret[i][0]),4); | 742 | (unsigned long)lqret[0].a,0x327eba8dUL); |
668 | if (j > 0) lqret[i]=lqret[i]>>(j*8); /* For Cray */ | 743 | err=1; |
669 | } | 744 | } |
670 | { /* Big-endian fix */ | 745 | if (lqret[0].b != 0x201a49ccL) |
671 | static DES_LONG l=1; | ||
672 | static unsigned char *c=(unsigned char *)&l; | ||
673 | DES_LONG ll; | ||
674 | |||
675 | if (!c[0]) | ||
676 | { | 746 | { |
677 | ll=lqret[0]^lqret[3]; | 747 | printf("quad_cksum error, out[1] %08lx is not %08lx\n", |
678 | lqret[0]^=ll; | 748 | (unsigned long)lqret[0].b,0x201a49ccUL); |
679 | lqret[3]^=ll; | 749 | err=1; |
680 | ll=lqret[1]^lqret[2]; | ||
681 | lqret[1]^=ll; | ||
682 | lqret[2]^=ll; | ||
683 | } | 750 | } |
684 | } | 751 | if (lqret[1].a != 0x70d7a63aL) |
685 | if (cs != 0x70d7a63aL) | ||
686 | { | 752 | { |
687 | printf("quad_cksum error, ret %08lx should be 70d7a63a\n", | 753 | printf("quad_cksum error, out[2] %08lx is not %08lx\n", |
688 | (unsigned long)cs); | 754 | (unsigned long)lqret[1].a,0x70d7a63aUL); |
689 | err=1; | 755 | err=1; |
690 | } | 756 | } |
757 | if (lqret[1].b != 0x501c2c26L) | ||
758 | { | ||
759 | printf("quad_cksum error, out[3] %08lx is not %08lx\n", | ||
760 | (unsigned long)lqret[1].b,0x501c2c26UL); | ||
761 | err=1; | ||
762 | } | ||
763 | #else | ||
691 | if (lqret[0] != 0x327eba8dL) | 764 | if (lqret[0] != 0x327eba8dL) |
692 | { | 765 | { |
693 | printf("quad_cksum error, out[0] %08lx is not %08lx\n", | 766 | printf("quad_cksum error, out[0] %08lx is not %08lx\n", |
694 | (unsigned long)lqret[0],0x327eba8dL); | 767 | (unsigned long)lqret[0],0x327eba8dUL); |
695 | err=1; | 768 | err=1; |
696 | } | 769 | } |
697 | if (lqret[1] != 0x201a49ccL) | 770 | if (lqret[1] != 0x201a49ccL) |
698 | { | 771 | { |
699 | printf("quad_cksum error, out[1] %08lx is not %08lx\n", | 772 | printf("quad_cksum error, out[1] %08lx is not %08lx\n", |
700 | (unsigned long)lqret[1],0x201a49ccL); | 773 | (unsigned long)lqret[1],0x201a49ccUL); |
701 | err=1; | 774 | err=1; |
702 | } | 775 | } |
703 | if (lqret[2] != 0x70d7a63aL) | 776 | if (lqret[2] != 0x70d7a63aL) |
704 | { | 777 | { |
705 | printf("quad_cksum error, out[2] %08lx is not %08lx\n", | 778 | printf("quad_cksum error, out[2] %08lx is not %08lx\n", |
706 | (unsigned long)lqret[2],0x70d7a63aL); | 779 | (unsigned long)lqret[2],0x70d7a63aUL); |
707 | err=1; | 780 | err=1; |
708 | } | 781 | } |
709 | if (lqret[3] != 0x501c2c26L) | 782 | if (lqret[3] != 0x501c2c26L) |
710 | { | 783 | { |
711 | printf("quad_cksum error, out[3] %08lx is not %08lx\n", | 784 | printf("quad_cksum error, out[3] %08lx is not %08lx\n", |
712 | (unsigned long)lqret[3],0x501c2c26L); | 785 | (unsigned long)lqret[3],0x501c2c26UL); |
713 | err=1; | 786 | err=1; |
714 | } | 787 | } |
715 | #endif | 788 | #endif |
789 | #endif | ||
716 | 790 | ||
717 | printf("input word alignment test"); | 791 | printf("input word alignment test"); |
718 | for (i=0; i<4; i++) | 792 | for (i=0; i<4; i++) |
719 | { | 793 | { |
720 | printf(" %d",i); | 794 | printf(" %d",i); |
721 | des_ncbc_encrypt((C_Block *)&(cbc_out[i]),(C_Block *)cbc_in, | 795 | des_ncbc_encrypt(&(cbc_out[i]),cbc_in, |
722 | (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv, | 796 | strlen((char *)cbc_data)+1,ks, |
723 | DES_ENCRYPT); | 797 | &cbc_iv,DES_ENCRYPT); |
724 | } | 798 | } |
725 | printf("\noutput word alignment test"); | 799 | printf("\noutput word alignment test"); |
726 | for (i=0; i<4; i++) | 800 | for (i=0; i<4; i++) |
727 | { | 801 | { |
728 | printf(" %d",i); | 802 | printf(" %d",i); |
729 | des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)&(cbc_in[i]), | 803 | des_ncbc_encrypt(cbc_out,&(cbc_in[i]), |
730 | (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv, | 804 | strlen((char *)cbc_data)+1,ks, |
731 | DES_ENCRYPT); | 805 | &cbc_iv,DES_ENCRYPT); |
732 | } | 806 | } |
733 | printf("\n"); | 807 | printf("\n"); |
734 | printf("fast crypt test "); | 808 | printf("fast crypt test "); |
@@ -745,12 +819,10 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | |||
745 | err=1; | 819 | err=1; |
746 | } | 820 | } |
747 | printf("\n"); | 821 | printf("\n"); |
748 | exit(err); | 822 | return(err); |
749 | return(0); | ||
750 | } | 823 | } |
751 | 824 | ||
752 | static char *pt(p) | 825 | static char *pt(unsigned char *p) |
753 | unsigned char *p; | ||
754 | { | 826 | { |
755 | static char bufs[10][20]; | 827 | static char bufs[10][20]; |
756 | static int bnum=0; | 828 | static int bnum=0; |
@@ -771,17 +843,15 @@ unsigned char *p; | |||
771 | 843 | ||
772 | #ifndef LIBDES_LIT | 844 | #ifndef LIBDES_LIT |
773 | 845 | ||
774 | static int cfb_test(bits, cfb_cipher) | 846 | static int cfb_test(int bits, unsigned char *cfb_cipher) |
775 | int bits; | ||
776 | unsigned char *cfb_cipher; | ||
777 | { | 847 | { |
778 | des_key_schedule ks; | 848 | des_key_schedule ks; |
779 | int i,err=0; | 849 | int i,err=0; |
780 | 850 | ||
781 | des_key_sched((C_Block *)cfb_key,ks); | 851 | DES_set_key_checked(&cfb_key,&ks); |
782 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | 852 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); |
783 | des_cfb_encrypt(plain,cfb_buf1,bits,(long)sizeof(plain),ks, | 853 | des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp, |
784 | (C_Block *)cfb_tmp,DES_ENCRYPT); | 854 | DES_ENCRYPT); |
785 | if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) | 855 | if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) |
786 | { | 856 | { |
787 | err=1; | 857 | err=1; |
@@ -790,8 +860,8 @@ unsigned char *cfb_cipher; | |||
790 | printf("%s\n",pt(&(cfb_buf1[i]))); | 860 | printf("%s\n",pt(&(cfb_buf1[i]))); |
791 | } | 861 | } |
792 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | 862 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); |
793 | des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,(long)sizeof(plain),ks, | 863 | des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,&cfb_tmp, |
794 | (C_Block *)cfb_tmp,DES_DECRYPT); | 864 | DES_DECRYPT); |
795 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) | 865 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) |
796 | { | 866 | { |
797 | err=1; | 867 | err=1; |
@@ -802,20 +872,17 @@ unsigned char *cfb_cipher; | |||
802 | return(err); | 872 | return(err); |
803 | } | 873 | } |
804 | 874 | ||
805 | static int cfb64_test(cfb_cipher) | 875 | static int cfb64_test(unsigned char *cfb_cipher) |
806 | unsigned char *cfb_cipher; | ||
807 | { | 876 | { |
808 | des_key_schedule ks; | 877 | des_key_schedule ks; |
809 | int err=0,i,n; | 878 | int err=0,i,n; |
810 | 879 | ||
811 | des_key_sched((C_Block *)cfb_key,ks); | 880 | DES_set_key_checked(&cfb_key,&ks); |
812 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | 881 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); |
813 | n=0; | 882 | n=0; |
814 | des_cfb64_encrypt(plain,cfb_buf1,(long)12,ks, | 883 | des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT); |
815 | (C_Block *)cfb_tmp,&n,DES_ENCRYPT); | 884 | des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks, |
816 | des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), | 885 | &cfb_tmp,&n,DES_ENCRYPT); |
817 | (long)sizeof(plain)-12,ks, | ||
818 | (C_Block *)cfb_tmp,&n,DES_ENCRYPT); | ||
819 | if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) | 886 | if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) |
820 | { | 887 | { |
821 | err=1; | 888 | err=1; |
@@ -825,11 +892,9 @@ unsigned char *cfb_cipher; | |||
825 | } | 892 | } |
826 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | 893 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); |
827 | n=0; | 894 | n=0; |
828 | des_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks, | 895 | des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,&cfb_tmp,&n,DES_DECRYPT); |
829 | (C_Block *)cfb_tmp,&n,DES_DECRYPT); | ||
830 | des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), | 896 | des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), |
831 | (long)sizeof(plain)-17,ks, | 897 | sizeof(plain)-17,ks,&cfb_tmp,&n,DES_DECRYPT); |
832 | (C_Block *)cfb_tmp,&n,DES_DECRYPT); | ||
833 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) | 898 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) |
834 | { | 899 | { |
835 | err=1; | 900 | err=1; |
@@ -840,20 +905,19 @@ unsigned char *cfb_cipher; | |||
840 | return(err); | 905 | return(err); |
841 | } | 906 | } |
842 | 907 | ||
843 | static int ede_cfb64_test(cfb_cipher) | 908 | static int ede_cfb64_test(unsigned char *cfb_cipher) |
844 | unsigned char *cfb_cipher; | ||
845 | { | 909 | { |
846 | des_key_schedule ks; | 910 | des_key_schedule ks; |
847 | int err=0,i,n; | 911 | int err=0,i,n; |
848 | 912 | ||
849 | des_key_sched((C_Block *)cfb_key,ks); | 913 | DES_set_key_checked(&cfb_key,&ks); |
850 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | 914 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); |
851 | n=0; | 915 | n=0; |
852 | des_ede3_cfb64_encrypt(plain,cfb_buf1,(long)12,ks,ks,ks, | 916 | des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n, |
853 | (C_Block *)cfb_tmp,&n,DES_ENCRYPT); | 917 | DES_ENCRYPT); |
854 | des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), | 918 | des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), |
855 | (long)sizeof(plain)-12,ks,ks,ks, | 919 | sizeof(plain)-12,ks,ks,ks, |
856 | (C_Block *)cfb_tmp,&n,DES_ENCRYPT); | 920 | &cfb_tmp,&n,DES_ENCRYPT); |
857 | if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) | 921 | if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) |
858 | { | 922 | { |
859 | err=1; | 923 | err=1; |
@@ -864,10 +928,10 @@ unsigned char *cfb_cipher; | |||
864 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | 928 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); |
865 | n=0; | 929 | n=0; |
866 | des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks, | 930 | des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks, |
867 | (C_Block *)cfb_tmp,&n,DES_DECRYPT); | 931 | &cfb_tmp,&n,DES_DECRYPT); |
868 | des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), | 932 | des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), |
869 | (long)sizeof(plain)-17,ks,ks,ks, | 933 | sizeof(plain)-17,ks,ks,ks, |
870 | (C_Block *)cfb_tmp,&n,DES_DECRYPT); | 934 | &cfb_tmp,&n,DES_DECRYPT); |
871 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) | 935 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) |
872 | { | 936 | { |
873 | err=1; | 937 | err=1; |
@@ -879,4 +943,4 @@ unsigned char *cfb_cipher; | |||
879 | } | 943 | } |
880 | 944 | ||
881 | #endif | 945 | #endif |
882 | 946 | #endif | |