From cc9f1c6a9cb8c66f11569749b9f3363f6ed944e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Wed, 25 Feb 2004 20:50:25 +0100 Subject: [PATCH] (C_Block, Key_schedule): Deleted defines. Deleted some of the explicit casts. Rev: src/nettle/testsuite/des-compat-test.c:1.4 --- testsuite/des-compat-test.c | 75 ++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/testsuite/des-compat-test.c b/testsuite/des-compat-test.c index b77a3e3a..e8b2fca7 100644 --- a/testsuite/des-compat-test.c +++ b/testsuite/des-compat-test.c @@ -64,13 +64,10 @@ #include "des-compat.h" #include "testutils.h" -#define C_Block des_cblock -#define Key_schedule des_key_schedule - /* tisk tisk - the test keys don't all have odd parity :-( */ /* test data */ #define NUM_TESTS 34 -static unsigned char key_data[NUM_TESTS][8]={ +static des_cblock key_data[NUM_TESTS] = { {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, @@ -213,10 +210,10 @@ static unsigned char cipher_ecb2[NUM_TESTS-1][8]={ {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8}, {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}}; -static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; -static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; -static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; -static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; +static des_cblock cbc_key = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; +static des_cblock cbc2_key = {0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; +static des_cblock cbc3_key = {0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; +static des_cblock cbc_iv = {0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; static char cbc_data[32]="7654321 Now is the time for "; static unsigned char cbc_ok[32]={ @@ -318,7 +315,7 @@ test_main(void) printf("Doing ecb\n"); for (i=0; i<NUM_TESTS; i++) { - if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0) + if ((j=des_key_sched(&key_data[i], ks)) != 0) { printf("Key error %2d:%d\n",i+1,j); err=1; @@ -326,8 +323,8 @@ test_main(void) memcpy(in,plain_data[i],8); memset(out,0,8); memset(outin,0,8); - des_ecb_encrypt((C_Block *)in,(C_Block *)out,ks,DES_ENCRYPT); - des_ecb_encrypt((C_Block *)out,(C_Block *)outin,ks,DES_DECRYPT); + des_ecb_encrypt( (des_cblock *) in, (des_cblock *) out, ks, DES_ENCRYPT); + des_ecb_encrypt( (des_cblock *) out, (des_cblock *) outin, ks, DES_DECRYPT); if (memcmp(out,cipher_data[i],8) != 0) { @@ -348,17 +345,17 @@ test_main(void) printf("Doing ede ecb\n"); for (i=0; i<(NUM_TESTS-1); i++) { - if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0) + if ((j=des_key_sched(&key_data[i], ks)) != 0) { err=1; printf("Key error %2d:%d\n",i+1,j); } - if ((j=des_key_sched((C_Block *)(key_data[i+1]),ks2)) != 0) + if ((j=des_key_sched(&key_data[i+1],ks2)) != 0) { printf("Key error %2d:%d\n",i+2,j); err=1; } - if ((j=des_key_sched((C_Block *)(key_data[i+2]),ks3)) != 0) + if ((j=des_key_sched(&key_data[i+2],ks3)) != 0) { printf("Key error %2d:%d\n",i+3,j); err=1; @@ -366,9 +363,9 @@ test_main(void) memcpy(in,plain_data[i],8); memset(out,0,8); memset(outin,0,8); - des_ecb2_encrypt((C_Block *)in,(C_Block *)out,ks,ks2, + des_ecb2_encrypt( (des_cblock *) in, (des_cblock *) out, ks, ks2, DES_ENCRYPT); - des_ecb2_encrypt((C_Block *)out,(C_Block *)outin,ks,ks2, + des_ecb2_encrypt( (des_cblock *) out, (des_cblock *) outin, ks, ks2, DES_DECRYPT); if (memcmp(out,cipher_ecb2[i],8) != 0) @@ -388,7 +385,7 @@ test_main(void) #endif printf("Doing cbc\n"); - if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) + if ((j=des_key_sched(&cbc_key, ks)) != 0) { printf("Key error %d\n",j); err=1; @@ -396,16 +393,16 @@ test_main(void) memset(cbc_out,0,sizeof(cbc_data)); memset(cbc_in,0,sizeof(cbc_data)); memcpy(iv3,cbc_iv,sizeof(cbc_iv)); - des_ncbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, - sizeof(cbc_data),ks, - (C_Block *)iv3,DES_ENCRYPT); + des_ncbc_encrypt( (des_cblock *) cbc_data, (des_cblock *) cbc_out, + sizeof(cbc_data), ks, + &iv3, DES_ENCRYPT); if (memcmp(cbc_out,cbc_ok,32) != 0) printf("cbc_encrypt encrypt error\n"); memcpy(iv3,cbc_iv,sizeof(cbc_iv)); - des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, + des_ncbc_encrypt( (des_cblock *) cbc_out, (des_cblock *) cbc_in, sizeof(cbc_data),ks, - (C_Block *)iv3,DES_DECRYPT); + &iv3,DES_DECRYPT); if (memcmp(cbc_in,cbc_data,sizeof(cbc_data)) != 0) { printf("cbc_encrypt decrypt error\n"); @@ -445,17 +442,17 @@ test_main(void) #endif /* LIBDES_LIT */ printf("Doing ede cbc\n"); - if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) + if ((j=des_key_sched(&cbc_key,ks)) != 0) { printf("Key error %d\n",j); err=1; } - if ((j=des_key_sched((C_Block *)cbc2_key,ks2)) != 0) + if ((j=des_key_sched(&cbc2_key,ks2)) != 0) { printf("Key error %d\n",j); err=1; } - if ((j=des_key_sched((C_Block *)cbc3_key,ks3)) != 0) + if ((j=des_key_sched(&cbc3_key,ks3)) != 0) { printf("Key error %d\n",j); err=1; @@ -466,11 +463,11 @@ test_main(void) /* i=((i+7)/8)*8; */ memcpy(iv3,cbc_iv,sizeof(cbc_iv)); - des_ede3_cbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, - 16L,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT); - des_ede3_cbc_encrypt((C_Block *)&(cbc_data[16]), - (C_Block *)&(cbc_out[16]), - (long)i-16,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT); + des_ede3_cbc_encrypt( (des_cblock *)cbc_data, (des_cblock *) cbc_out, + 16L, ks, ks2, ks3, &iv3, DES_ENCRYPT); + des_ede3_cbc_encrypt( (des_cblock *)&(cbc_data[16]), + (des_cblock *)&(cbc_out[16]), + (long)i-16, ks, ks2, ks3, &iv3, DES_ENCRYPT); if (memcmp(cbc_out,cbc3_ok, sizeof(cbc_data)) != 0) { printf("des_ede3_cbc_encrypt encrypt error\n"); @@ -478,8 +475,8 @@ test_main(void) } memcpy(iv3,cbc_iv,sizeof(cbc_iv)); - des_ede3_cbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, - (long)i,ks,ks2,ks3,(C_Block *)iv3,DES_DECRYPT); + des_ede3_cbc_encrypt( (des_cblock *) cbc_out, (des_cblock *) cbc_in, + (long)i,ks, ks2, ks3, &iv3, DES_DECRYPT); if (memcmp(cbc_in,cbc_data,sizeof(cbc_data)) != 0) { printf("des_ede3_cbc_encrypt decrypt error\n"); @@ -636,9 +633,9 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); #endif printf("Doing cbc_cksum\n"); - des_key_sched((C_Block *)cbc_key,ks); - cs=des_cbc_cksum((C_Block *)cbc_data,(C_Block *)cret, - sizeof(cbc_data),ks,(C_Block *)cbc_iv); + des_key_sched( (des_cblock *) cbc_key,ks); + cs=des_cbc_cksum( (des_cblock *) cbc_data, (des_cblock *) cret, + sizeof(cbc_data), ks, &cbc_iv); if (cs != cbc_cksum_ret) { printf("bad return value (%08lX), should be %08lX\n", @@ -712,16 +709,16 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); for (i=0; i<4; i++) { printf(" %d",i); - des_ncbc_encrypt((C_Block *)&(cbc_out[i]),(C_Block *)cbc_in, - sizeof(cbc_data),ks,(C_Block *)cbc_iv, + des_ncbc_encrypt( (des_cblock *) &(cbc_out[i]), (des_cblock *) cbc_in, + sizeof(cbc_data), ks, &cbc_iv, DES_ENCRYPT); } printf("\noutput word alignment test"); for (i=0; i<4; i++) { printf(" %d",i); - des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)&(cbc_in[i]), - sizeof(cbc_data),ks,(C_Block *)cbc_iv, + des_ncbc_encrypt( (des_cblock *) cbc_out, (des_cblock *) &(cbc_in[i]), + sizeof(cbc_data), ks, &cbc_iv, DES_ENCRYPT); } printf("\n"); -- GitLab