Skip to content
Snippets Groups Projects
Commit e7f7f2ad authored by Niels Möller's avatar Niels Möller
Browse files

* testsuite/des-compat-test.c: Use des_cblock for typing more of

the variables. Use const. Got rid of most of the explicit casts.
Disabled the input/output alignment tests.

Rev: src/nettle/testsuite/des-compat-test.c:1.5
parent a4fa0f78
No related branches found
No related tags found
No related merge requests found
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
/* tisk tisk - the test keys don't all have odd parity :-( */ /* tisk tisk - the test keys don't all have odd parity :-( */
/* test data */ /* test data */
#define NUM_TESTS 34 #define NUM_TESTS 34
static des_cblock key_data[NUM_TESTS] = { static const des_cblock key_data[NUM_TESTS] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
{0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
...@@ -210,11 +210,11 @@ static unsigned char cipher_ecb2[NUM_TESTS-1][8]={ ...@@ -210,11 +210,11 @@ static unsigned char cipher_ecb2[NUM_TESTS-1][8]={
{0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8}, {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8},
{0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}}; {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}};
static des_cblock cbc_key = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; static const 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 const 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 const 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 const des_cblock cbc_iv = {0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
static char cbc_data[32]="7654321 Now is the time for "; static const des_cblock cbc_data[4] ={ "7654321 ", "Now is t", "he time ", "for " };
static unsigned char cbc_ok[32]={ static unsigned char cbc_ok[32]={
0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4, 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
...@@ -287,7 +287,7 @@ DES_LONG cbc_cksum_ret=0xB462FEF7L; ...@@ -287,7 +287,7 @@ DES_LONG cbc_cksum_ret=0xB462FEF7L;
unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
#ifndef NOPROTO #ifndef NOPROTO
static char *pt(unsigned char *p); static char *pt(const unsigned char *p);
static int cfb_test(int bits, unsigned char *cfb_cipher); static int cfb_test(int bits, unsigned char *cfb_cipher);
static int cfb64_test(unsigned char *cfb_cipher); static int cfb64_test(unsigned char *cfb_cipher);
static int ede_cfb64_test(unsigned char *cfb_cipher); static int ede_cfb64_test(unsigned char *cfb_cipher);
...@@ -304,8 +304,8 @@ test_main(void) ...@@ -304,8 +304,8 @@ test_main(void)
int i,j,err=0; int i,j,err=0;
des_cblock in, out, outin, iv3; des_cblock in, out, outin, iv3;
des_key_schedule ks,ks2,ks3; des_key_schedule ks,ks2,ks3;
unsigned char cbc_in[40]; des_cblock cbc_in[5];
unsigned char cbc_out[40]; des_cblock cbc_out[5];
DES_LONG cs; DES_LONG cs;
unsigned char qret[4][4],cret[8]; unsigned char qret[4][4],cret[8];
DES_LONG lqret[4]; DES_LONG lqret[4];
...@@ -323,8 +323,8 @@ test_main(void) ...@@ -323,8 +323,8 @@ test_main(void)
memcpy(in,plain_data[i],8); memcpy(in,plain_data[i],8);
memset(out,0,8); memset(out,0,8);
memset(outin,0,8); memset(outin,0,8);
des_ecb_encrypt( (des_cblock *) in, (des_cblock *) out, ks, DES_ENCRYPT); des_ecb_encrypt( (const des_cblock *) &in, &out, ks, DES_ENCRYPT);
des_ecb_encrypt( (des_cblock *) out, (des_cblock *) outin, ks, DES_DECRYPT); des_ecb_encrypt( (const des_cblock *) &out, &outin, ks, DES_DECRYPT);
if (memcmp(out,cipher_data[i],8) != 0) if (memcmp(out,cipher_data[i],8) != 0)
{ {
...@@ -363,9 +363,9 @@ test_main(void) ...@@ -363,9 +363,9 @@ test_main(void)
memcpy(in,plain_data[i],8); memcpy(in,plain_data[i],8);
memset(out,0,8); memset(out,0,8);
memset(outin,0,8); memset(outin,0,8);
des_ecb2_encrypt( (des_cblock *) in, (des_cblock *) out, ks, ks2, des_ecb2_encrypt( (const des_cblock *) &in, &out, ks, ks2,
DES_ENCRYPT); DES_ENCRYPT);
des_ecb2_encrypt( (des_cblock *) out, (des_cblock *) outin, ks, ks2, des_ecb2_encrypt( (const des_cblock *) &out, &outin, ks, ks2,
DES_DECRYPT); DES_DECRYPT);
if (memcmp(out,cipher_ecb2[i],8) != 0) if (memcmp(out,cipher_ecb2[i],8) != 0)
...@@ -393,14 +393,14 @@ test_main(void) ...@@ -393,14 +393,14 @@ test_main(void)
memset(cbc_out,0,sizeof(cbc_data)); memset(cbc_out,0,sizeof(cbc_data));
memset(cbc_in,0,sizeof(cbc_data)); memset(cbc_in,0,sizeof(cbc_data));
memcpy(iv3,cbc_iv,sizeof(cbc_iv)); memcpy(iv3,cbc_iv,sizeof(cbc_iv));
des_ncbc_encrypt( (des_cblock *) cbc_data, (des_cblock *) cbc_out, des_ncbc_encrypt(cbc_data, cbc_out,
sizeof(cbc_data), ks, sizeof(cbc_data), ks,
&iv3, DES_ENCRYPT); &iv3, DES_ENCRYPT);
if (memcmp(cbc_out,cbc_ok,32) != 0) if (memcmp(cbc_out,cbc_ok,32) != 0)
printf("cbc_encrypt encrypt error\n"); printf("cbc_encrypt encrypt error\n");
memcpy(iv3,cbc_iv,sizeof(cbc_iv)); memcpy(iv3,cbc_iv,sizeof(cbc_iv));
des_ncbc_encrypt( (des_cblock *) cbc_out, (des_cblock *) cbc_in, des_ncbc_encrypt( (const des_cblock *) cbc_out, cbc_in,
sizeof(cbc_data),ks, sizeof(cbc_data),ks,
&iv3,DES_DECRYPT); &iv3,DES_DECRYPT);
if (memcmp(cbc_in,cbc_data,sizeof(cbc_data)) != 0) if (memcmp(cbc_in,cbc_data,sizeof(cbc_data)) != 0)
...@@ -463,10 +463,10 @@ test_main(void) ...@@ -463,10 +463,10 @@ test_main(void)
/* i=((i+7)/8)*8; */ /* i=((i+7)/8)*8; */
memcpy(iv3,cbc_iv,sizeof(cbc_iv)); memcpy(iv3,cbc_iv,sizeof(cbc_iv));
des_ede3_cbc_encrypt( (des_cblock *)cbc_data, (des_cblock *) cbc_out, des_ede3_cbc_encrypt( cbc_data, cbc_out,
16L, ks, ks2, ks3, &iv3, DES_ENCRYPT); 16L, ks, ks2, ks3, &iv3, DES_ENCRYPT);
des_ede3_cbc_encrypt( (des_cblock *)&(cbc_data[16]), des_ede3_cbc_encrypt( &cbc_data[2],
(des_cblock *)&(cbc_out[16]), &cbc_out[2],
(long)i-16, ks, ks2, ks3, &iv3, DES_ENCRYPT); (long)i-16, ks, ks2, ks3, &iv3, DES_ENCRYPT);
if (memcmp(cbc_out,cbc3_ok, sizeof(cbc_data)) != 0) if (memcmp(cbc_out,cbc3_ok, sizeof(cbc_data)) != 0)
{ {
...@@ -475,7 +475,7 @@ test_main(void) ...@@ -475,7 +475,7 @@ test_main(void)
} }
memcpy(iv3,cbc_iv,sizeof(cbc_iv)); memcpy(iv3,cbc_iv,sizeof(cbc_iv));
des_ede3_cbc_encrypt( (des_cblock *) cbc_out, (des_cblock *) cbc_in, des_ede3_cbc_encrypt( (const des_cblock *) cbc_out, cbc_in,
(long)i, ks, ks2, ks3, &iv3, DES_DECRYPT); (long)i, ks, ks2, ks3, &iv3, DES_DECRYPT);
if (memcmp(cbc_in,cbc_data,sizeof(cbc_data)) != 0) if (memcmp(cbc_in,cbc_data,sizeof(cbc_data)) != 0)
{ {
...@@ -633,8 +633,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); ...@@ -633,8 +633,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
#endif #endif
printf("Doing cbc_cksum\n"); printf("Doing cbc_cksum\n");
des_key_sched( (des_cblock *) cbc_key,ks); des_key_sched(&cbc_key,ks);
cs=des_cbc_cksum( (des_cblock *) cbc_data, (des_cblock *) cret, cs=des_cbc_cksum(cbc_data, &cret,
sizeof(cbc_data), ks, &cbc_iv); sizeof(cbc_data), ks, &cbc_iv);
if (cs != cbc_cksum_ret) if (cs != cbc_cksum_ret)
{ {
...@@ -704,7 +704,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); ...@@ -704,7 +704,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
} }
#endif #endif
#endif /* LIBDES_LIT */ #endif /* LIBDES_LIT */
#if 0
printf("input word alignment test"); printf("input word alignment test");
for (i=0; i<4; i++) for (i=0; i<4; i++)
{ {
...@@ -722,7 +722,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); ...@@ -722,7 +722,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
DES_ENCRYPT); DES_ENCRYPT);
} }
printf("\n"); printf("\n");
#if 0
printf("fast crypt test "); printf("fast crypt test ");
str=crypt("testing","ef"); str=crypt("testing","ef");
if (strcmp("efGnQx2725bI2",str) != 0) if (strcmp("efGnQx2725bI2",str) != 0)
...@@ -743,7 +743,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); ...@@ -743,7 +743,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
} }
static char *pt(p) static char *pt(p)
unsigned char *p; const unsigned char *p;
{ {
static char bufs[10][20]; static char bufs[10][20];
static int bnum=0; static int bnum=0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment