提交 4e31df2c 编写于 作者: B Ben Laurie

Fix ghastly DES declarations, and all consequential warnings.

上级 e4119b93
...@@ -5,6 +5,12 @@ ...@@ -5,6 +5,12 @@
Changes between 0.9.1c and 0.9.2 Changes between 0.9.1c and 0.9.2
*) Major rework of DES function declarations, in the pursuit of correctness
and purity. As a result, many evil casts evaporated, and some weirdness,
too. You may find this causes warnings in your code. Zapping your evil
casts will probably fix them. Mostly.
[Ben Laurie]
*) Fix for a typo in asn1.h. Bug fix to object creation script *) Fix for a typo in asn1.h. Bug fix to object creation script
obj_dat.pl. It considered a zero in an object definition to mean obj_dat.pl. It considered a zero in an object definition to mean
"end of object": none of the objects in objects.h have any zeros "end of object": none of the objects in objects.h have any zeros
......
...@@ -601,9 +601,9 @@ char **argv; ...@@ -601,9 +601,9 @@ char **argv;
#endif #endif
#ifndef NO_DES #ifndef NO_DES
des_set_key((C_Block *)key,sch); des_set_key(key,sch);
des_set_key((C_Block *)key2,sch2); des_set_key(key2,sch2);
des_set_key((C_Block *)key3,sch3); des_set_key(key3,sch3);
#endif #endif
#ifndef NO_IDEA #ifndef NO_IDEA
idea_set_encrypt_key(key16,&idea_ks); idea_set_encrypt_key(key16,&idea_ks);
...@@ -851,10 +851,8 @@ char **argv; ...@@ -851,10 +851,8 @@ char **argv;
print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]); print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
Time_F(START); Time_F(START);
for (count=0,run=1; COND(c[D_CBC_DES][j]); count++) for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
des_ncbc_encrypt((C_Block *)buf, des_ncbc_encrypt(buf,buf,lengths[j],sch,
(C_Block *)buf, &(iv[0]),DES_ENCRYPT);
(long)lengths[j],sch,
(C_Block *)&(iv[0]),DES_ENCRYPT);
d=Time_F(STOP); d=Time_F(STOP);
BIO_printf(bio_err,"%ld %s's in %.2fs\n", BIO_printf(bio_err,"%ld %s's in %.2fs\n",
count,names[D_CBC_DES],d); count,names[D_CBC_DES],d);
...@@ -869,10 +867,9 @@ char **argv; ...@@ -869,10 +867,9 @@ char **argv;
print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]); print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
Time_F(START); Time_F(START);
for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++) for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
des_ede3_cbc_encrypt((C_Block *)buf, des_ede3_cbc_encrypt(buf,buf,lengths[j],
(C_Block *)buf, sch,sch2,sch3,
(long)lengths[j],sch,sch2,sch3, &(iv[0]),DES_ENCRYPT);
(C_Block *)&(iv[0]),DES_ENCRYPT);
d=Time_F(STOP); d=Time_F(STOP);
BIO_printf(bio_err,"%ld %s's in %.2fs\n", BIO_printf(bio_err,"%ld %s's in %.2fs\n",
count,names[D_EDE3_DES],d); count,names[D_EDE3_DES],d);
......
...@@ -58,21 +58,16 @@ ...@@ -58,21 +58,16 @@
#include "des_locl.h" #include "des_locl.h"
DES_LONG des_cbc_cksum(input, output, length, schedule, ivec) DES_LONG des_cbc_cksum(in, out, length, schedule, iv)
des_cblock (*input); const unsigned char *in;
des_cblock (*output); des_cblock out;
long length; long length;
des_key_schedule schedule; des_key_schedule schedule;
des_cblock (*ivec); des_cblock iv;
{ {
register DES_LONG tout0,tout1,tin0,tin1; register DES_LONG tout0,tout1,tin0,tin1;
register long l=length; register long l=length;
DES_LONG tin[2]; DES_LONG tin[2];
unsigned char *in,*out,*iv;
in=(unsigned char *)input;
out=(unsigned char *)output;
iv=(unsigned char *)ivec;
c2l(iv,tout0); c2l(iv,tout0);
c2l(iv,tout1); c2l(iv,tout1);
......
...@@ -58,24 +58,23 @@ ...@@ -58,24 +58,23 @@
#include "des_locl.h" #include "des_locl.h"
void des_cbc_encrypt(input, output, length, schedule, ivec, enc) /* Note that this is inconsistent with other DES functions, in that it doesn't
des_cblock (*input); update ivec */
des_cblock (*output); void des_cbc_encrypt(in, out, length, schedule, ivec, enc)
const unsigned char *in;
unsigned char *out;
long length; long length;
des_key_schedule schedule; des_key_schedule schedule;
des_cblock (*ivec); des_cblock ivec;
int enc; int enc;
{ {
register DES_LONG tin0,tin1; register DES_LONG tin0,tin1;
register DES_LONG tout0,tout1,xor0,xor1; register DES_LONG tout0,tout1,xor0,xor1;
register unsigned char *in,*out;
register long l=length; register long l=length;
DES_LONG tin[2]; DES_LONG tin[2];
unsigned char *iv; unsigned char *iv;
in=(unsigned char *)input; iv=ivec;
out=(unsigned char *)output;
iv=(unsigned char *)ivec;
if (enc) if (enc)
{ {
......
...@@ -64,11 +64,11 @@ ...@@ -64,11 +64,11 @@
*/ */
void des_ede3_cfb64_encrypt(in, out, length, ks1,ks2,ks3, ivec, num, enc) void des_ede3_cfb64_encrypt(in, out, length, ks1,ks2,ks3, ivec, num, enc)
unsigned char *in; const unsigned char *in;
unsigned char *out; unsigned char *out;
long length; long length;
des_key_schedule ks1,ks2,ks3; des_key_schedule ks1,ks2,ks3;
des_cblock (*ivec); des_cblock ivec;
int *num; int *num;
int enc; int enc;
{ {
...@@ -78,7 +78,7 @@ int enc; ...@@ -78,7 +78,7 @@ int enc;
DES_LONG ti[2]; DES_LONG ti[2];
unsigned char *iv,c,cc; unsigned char *iv,c,cc;
iv=(unsigned char *)ivec; iv=ivec;
if (enc) if (enc)
{ {
while (l--) while (l--)
...@@ -90,14 +90,14 @@ int enc; ...@@ -90,14 +90,14 @@ int enc;
ti[0]=v0; ti[0]=v0;
ti[1]=v1; ti[1]=v1;
des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3); des_encrypt3(ti,ks1,ks2,ks3);
v0=ti[0]; v0=ti[0];
v1=ti[1]; v1=ti[1];
iv=(unsigned char *)ivec; iv=ivec;
l2c(v0,iv); l2c(v0,iv);
l2c(v1,iv); l2c(v1,iv);
iv=(unsigned char *)ivec; iv=ivec;
} }
c= *(in++)^iv[n]; c= *(in++)^iv[n];
*(out++)=c; *(out++)=c;
...@@ -116,14 +116,14 @@ int enc; ...@@ -116,14 +116,14 @@ int enc;
ti[0]=v0; ti[0]=v0;
ti[1]=v1; ti[1]=v1;
des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3); des_encrypt3(ti,ks1,ks2,ks3);
v0=ti[0]; v0=ti[0];
v1=ti[1]; v1=ti[1];
iv=(unsigned char *)ivec; iv=ivec;
l2c(v0,iv); l2c(v0,iv);
l2c(v1,iv); l2c(v1,iv);
iv=(unsigned char *)ivec; iv=ivec;
} }
cc= *(in++); cc= *(in++);
c=iv[n]; c=iv[n];
......
...@@ -64,11 +64,11 @@ ...@@ -64,11 +64,11 @@
*/ */
void des_cfb64_encrypt(in, out, length, schedule, ivec, num, enc) void des_cfb64_encrypt(in, out, length, schedule, ivec, num, enc)
unsigned char *in; const unsigned char *in;
unsigned char *out; unsigned char *out;
long length; long length;
des_key_schedule schedule; des_key_schedule schedule;
des_cblock (*ivec); des_cblock ivec;
int *num; int *num;
int enc; int enc;
{ {
...@@ -78,7 +78,7 @@ int enc; ...@@ -78,7 +78,7 @@ int enc;
DES_LONG ti[2]; DES_LONG ti[2];
unsigned char *iv,c,cc; unsigned char *iv,c,cc;
iv=(unsigned char *)ivec; iv=ivec;
if (enc) if (enc)
{ {
while (l--) while (l--)
...@@ -87,12 +87,11 @@ int enc; ...@@ -87,12 +87,11 @@ int enc;
{ {
c2l(iv,v0); ti[0]=v0; c2l(iv,v0); ti[0]=v0;
c2l(iv,v1); ti[1]=v1; c2l(iv,v1); ti[1]=v1;
des_encrypt((DES_LONG *)ti, des_encrypt(ti,schedule,DES_ENCRYPT);
schedule,DES_ENCRYPT); iv=ivec;
iv=(unsigned char *)ivec;
v0=ti[0]; l2c(v0,iv); v0=ti[0]; l2c(v0,iv);
v0=ti[1]; l2c(v0,iv); v0=ti[1]; l2c(v0,iv);
iv=(unsigned char *)ivec; iv=ivec;
} }
c= *(in++)^iv[n]; c= *(in++)^iv[n];
*(out++)=c; *(out++)=c;
...@@ -108,12 +107,11 @@ int enc; ...@@ -108,12 +107,11 @@ int enc;
{ {
c2l(iv,v0); ti[0]=v0; c2l(iv,v0); ti[0]=v0;
c2l(iv,v1); ti[1]=v1; c2l(iv,v1); ti[1]=v1;
des_encrypt((DES_LONG *)ti, des_encrypt(ti,schedule,DES_ENCRYPT);
schedule,DES_ENCRYPT); iv=ivec;
iv=(unsigned char *)ivec;
v0=ti[0]; l2c(v0,iv); v0=ti[0]; l2c(v0,iv);
v0=ti[1]; l2c(v0,iv); v0=ti[1]; l2c(v0,iv);
iv=(unsigned char *)ivec; iv=ivec;
} }
cc= *(in++); cc= *(in++);
c=iv[n]; c=iv[n];
......
...@@ -65,12 +65,12 @@ ...@@ -65,12 +65,12 @@
* byte. * byte.
*/ */
void des_cfb_encrypt(in, out, numbits, length, schedule, ivec, enc) void des_cfb_encrypt(in, out, numbits, length, schedule, ivec, enc)
unsigned char *in; const unsigned char *in;
unsigned char *out; unsigned char *out;
int numbits; int numbits;
long length; long length;
des_key_schedule schedule; des_key_schedule schedule;
des_cblock (*ivec); des_cblock ivec;
int enc; int enc;
{ {
register DES_LONG d0,d1,v0,v1,n=(numbits+7)/8; register DES_LONG d0,d1,v0,v1,n=(numbits+7)/8;
...@@ -96,7 +96,7 @@ int enc; ...@@ -96,7 +96,7 @@ int enc;
mask1=0x00000000L; mask1=0x00000000L;
} }
iv=(unsigned char *)ivec; iv=ivec;
c2l(iv,v0); c2l(iv,v0);
c2l(iv,v1); c2l(iv,v1);
if (enc) if (enc)
...@@ -163,7 +163,7 @@ int enc; ...@@ -163,7 +163,7 @@ int enc;
out+=n; out+=n;
} }
} }
iv=(unsigned char *)ivec; iv=ivec;
l2c(v0,iv); l2c(v0,iv);
l2c(v1,iv); l2c(v1,iv);
v0=v1=d0=d1=ti[0]=ti[1]=0; v0=v1=d0=d1=ti[0]=ti[1]=0;
......
...@@ -329,17 +329,17 @@ char *argv[]; ...@@ -329,17 +329,17 @@ char *argv[];
char *str; char *str;
printf("Doing cbcm\n"); printf("Doing cbcm\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); printf("Key error %d\n",j);
err=1; 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); printf("Key error %d\n",j);
err=1; 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); printf("Key error %d\n",j);
err=1; err=1;
...@@ -383,7 +383,7 @@ char *argv[]; ...@@ -383,7 +383,7 @@ char *argv[];
printf("Doing ecb\n"); printf("Doing ecb\n");
for (i=0; i<NUM_TESTS; i++) 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); printf("Key error %2d:%d\n",i+1,j);
err=1; err=1;
...@@ -391,8 +391,8 @@ char *argv[]; ...@@ -391,8 +391,8 @@ char *argv[];
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((C_Block *)in,(C_Block *)out,ks,DES_ENCRYPT); des_ecb_encrypt(in,out,ks,DES_ENCRYPT);
des_ecb_encrypt((C_Block *)out,(C_Block *)outin,ks,DES_DECRYPT); des_ecb_encrypt(out,outin,ks,DES_DECRYPT);
if (memcmp(out,cipher_data[i],8) != 0) if (memcmp(out,cipher_data[i],8) != 0)
{ {
...@@ -413,17 +413,17 @@ char *argv[]; ...@@ -413,17 +413,17 @@ char *argv[];
printf("Doing ede ecb\n"); printf("Doing ede ecb\n");
for (i=0; i<(NUM_TESTS-1); i++) 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; err=1;
printf("Key error %2d:%d\n",i+1,j); 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); printf("Key error %2d:%d\n",i+2,j);
err=1; 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); printf("Key error %2d:%d\n",i+3,j);
err=1; err=1;
...@@ -431,10 +431,8 @@ char *argv[]; ...@@ -431,10 +431,8 @@ char *argv[];
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((C_Block *)in,(C_Block *)out,ks,ks2, des_ecb2_encrypt(in,out,ks,ks2,DES_ENCRYPT);
DES_ENCRYPT); des_ecb2_encrypt(out,outin,ks,ks2,DES_DECRYPT);
des_ecb2_encrypt((C_Block *)out,(C_Block *)outin,ks,ks2,
DES_DECRYPT);
if (memcmp(out,cipher_ecb2[i],8) != 0) if (memcmp(out,cipher_ecb2[i],8) != 0)
{ {
...@@ -453,7 +451,7 @@ char *argv[]; ...@@ -453,7 +451,7 @@ char *argv[];
#endif #endif
printf("Doing cbc\n"); 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); printf("Key error %d\n",j);
err=1; err=1;
...@@ -461,16 +459,14 @@ char *argv[]; ...@@ -461,16 +459,14 @@ char *argv[];
memset(cbc_out,0,40); memset(cbc_out,0,40);
memset(cbc_in,0,40); memset(cbc_in,0,40);
memcpy(iv3,cbc_iv,sizeof(cbc_iv)); memcpy(iv3,cbc_iv,sizeof(cbc_iv));
des_ncbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
(long)strlen((char *)cbc_data)+1,ks, iv3,DES_ENCRYPT);
(C_Block *)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((C_Block *)cbc_out,(C_Block *)cbc_in, des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
(long)strlen((char *)cbc_data)+1,ks, iv3,DES_DECRYPT);
(C_Block *)iv3,DES_DECRYPT);
if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0) if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0)
{ {
printf("cbc_encrypt decrypt error\n"); printf("cbc_encrypt decrypt error\n");
...@@ -479,7 +475,7 @@ char *argv[]; ...@@ -479,7 +475,7 @@ char *argv[];
#ifndef LIBDES_LIT #ifndef LIBDES_LIT
printf("Doing desx cbc\n"); printf("Doing desx 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); printf("Key error %d\n",j);
err=1; err=1;
...@@ -487,19 +483,15 @@ char *argv[]; ...@@ -487,19 +483,15 @@ char *argv[];
memset(cbc_out,0,40); memset(cbc_out,0,40);
memset(cbc_in,0,40); memset(cbc_in,0,40);
memcpy(iv3,cbc_iv,sizeof(cbc_iv)); memcpy(iv3,cbc_iv,sizeof(cbc_iv));
des_xcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, des_xcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
(long)strlen((char *)cbc_data)+1,ks, iv3,cbc2_key,cbc3_key, DES_ENCRYPT);
(C_Block *)iv3,
(C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_ENCRYPT);
if (memcmp(cbc_out,xcbc_ok,32) != 0) if (memcmp(cbc_out,xcbc_ok,32) != 0)
{ {
printf("des_xcbc_encrypt encrypt error\n"); printf("des_xcbc_encrypt encrypt error\n");
} }
memcpy(iv3,cbc_iv,sizeof(cbc_iv)); memcpy(iv3,cbc_iv,sizeof(cbc_iv));
des_xcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
(long)strlen((char *)cbc_data)+1,ks, iv3,cbc2_key,cbc3_key, DES_DECRYPT);
(C_Block *)iv3,
(C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_DECRYPT);
if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
{ {
printf("des_xcbc_encrypt decrypt error\n"); printf("des_xcbc_encrypt decrypt error\n");
...@@ -508,17 +500,17 @@ char *argv[]; ...@@ -508,17 +500,17 @@ char *argv[];
#endif #endif
printf("Doing ede cbc\n"); 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); printf("Key error %d\n",j);
err=1; 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); printf("Key error %d\n",j);
err=1; 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); printf("Key error %d\n",j);
err=1; err=1;
...@@ -529,11 +521,9 @@ char *argv[]; ...@@ -529,11 +521,9 @@ char *argv[];
/* 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((C_Block *)cbc_data,(C_Block *)cbc_out, des_ede3_cbc_encrypt(cbc_data,cbc_out,16L,ks,ks2,ks3,iv3,DES_ENCRYPT);
16L,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT); des_ede3_cbc_encrypt(&(cbc_data[16]),&(cbc_out[16]),i-16,ks,ks2,ks3,
des_ede3_cbc_encrypt((C_Block *)&(cbc_data[16]), iv3,DES_ENCRYPT);
(C_Block *)&(cbc_out[16]),
(long)i-16,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT);
if (memcmp(cbc_out,cbc3_ok, if (memcmp(cbc_out,cbc3_ok,
(unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0) (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
{ {
...@@ -542,8 +532,7 @@ char *argv[]; ...@@ -542,8 +532,7 @@ char *argv[];
} }
memcpy(iv3,cbc_iv,sizeof(cbc_iv)); memcpy(iv3,cbc_iv,sizeof(cbc_iv));
des_ede3_cbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, des_ede3_cbc_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,iv3,DES_DECRYPT);
(long)i,ks,ks2,ks3,(C_Block *)iv3,DES_DECRYPT);
if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0) if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
{ {
printf("des_ede3_cbc_encrypt decrypt error\n"); printf("des_ede3_cbc_encrypt decrypt error\n");
...@@ -552,22 +541,22 @@ char *argv[]; ...@@ -552,22 +541,22 @@ char *argv[];
#ifndef LIBDES_LIT #ifndef LIBDES_LIT
printf("Doing pcbc\n"); printf("Doing pcbc\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); printf("Key error %d\n",j);
err=1; err=1;
} }
memset(cbc_out,0,40); memset(cbc_out,0,40);
memset(cbc_in,0,40); memset(cbc_in,0,40);
des_pcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, des_pcbc_encrypt(cbc_data,cbc_out,strlen(cbc_data)+1,ks,cbc_iv,
(long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_ENCRYPT); DES_ENCRYPT);
if (memcmp(cbc_out,pcbc_ok,32) != 0) if (memcmp(cbc_out,pcbc_ok,32) != 0)
{ {
printf("pcbc_encrypt encrypt error\n"); printf("pcbc_encrypt encrypt error\n");
err=1; err=1;
} }
des_pcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, des_pcbc_encrypt(cbc_out,cbc_in,strlen(cbc_data)+1,ks,cbc_iv,
(long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_DECRYPT); DES_DECRYPT);
if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0) if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
{ {
printf("pcbc_encrypt decrypt error\n"); printf("pcbc_encrypt decrypt error\n");
...@@ -592,7 +581,7 @@ char *argv[]; ...@@ -592,7 +581,7 @@ char *argv[];
memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
for (i=0; i<sizeof(plain); i++) for (i=0; i<sizeof(plain); i++)
des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]), des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]),
8,(long)1,ks,(C_Block *)cfb_tmp,DES_ENCRYPT); 8,1,ks,cfb_tmp,DES_ENCRYPT);
if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0) if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0)
{ {
printf("cfb_encrypt small encrypt error\n"); printf("cfb_encrypt small encrypt error\n");
...@@ -602,7 +591,7 @@ char *argv[]; ...@@ -602,7 +591,7 @@ char *argv[];
memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
for (i=0; i<sizeof(plain); i++) for (i=0; i<sizeof(plain); i++)
des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]), des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]),
8,(long)1,ks,(C_Block *)cfb_tmp,DES_DECRYPT); 8,1,ks,cfb_tmp,DES_DECRYPT);
if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
{ {
printf("cfb_encrypt small decrypt error\n"); printf("cfb_encrypt small decrypt error\n");
...@@ -615,10 +604,9 @@ char *argv[]; ...@@ -615,10 +604,9 @@ char *argv[];
printf("done\n"); printf("done\n");
printf("Doing ofb\n"); printf("Doing ofb\n");
des_key_sched((C_Block *)ofb_key,ks); des_key_sched(ofb_key,ks);
memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
des_ofb_encrypt(plain,ofb_buf1,64,(long)sizeof(plain)/8,ks, des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,ofb_tmp);
(C_Block *)ofb_tmp);
if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
{ {
printf("ofb_encrypt encrypt error\n"); printf("ofb_encrypt encrypt error\n");
...@@ -631,8 +619,7 @@ ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]); ...@@ -631,8 +619,7 @@ ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]);
err=1; err=1;
} }
memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
des_ofb_encrypt(ofb_buf1,ofb_buf2,64,(long)sizeof(ofb_buf1)/8,ks, des_ofb_encrypt(ofb_buf1,ofb_buf2,64,sizeof(ofb_buf1)/8,ks,ofb_tmp);
(C_Block *)ofb_tmp);
if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
{ {
printf("ofb_encrypt decrypt error\n"); printf("ofb_encrypt decrypt error\n");
...@@ -646,15 +633,15 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); ...@@ -646,15 +633,15 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
} }
printf("Doing ofb64\n"); printf("Doing ofb64\n");
des_key_sched((C_Block *)ofb_key,ks); des_key_sched(ofb_key,ks);
memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
memset(ofb_buf1,0,sizeof(ofb_buf1)); memset(ofb_buf1,0,sizeof(ofb_buf1));
memset(ofb_buf2,0,sizeof(ofb_buf1)); memset(ofb_buf2,0,sizeof(ofb_buf1));
num=0; num=0;
for (i=0; i<sizeof(plain); i++) for (i=0; i<sizeof(plain); i++)
{ {
des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks, des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ofb_tmp,
(C_Block *)ofb_tmp,&num); &num);
} }
if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
{ {
...@@ -663,8 +650,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); ...@@ -663,8 +650,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
} }
memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
num=0; num=0;
des_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks, des_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,ofb_tmp,&num);
(C_Block *)ofb_tmp,&num);
if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
{ {
printf("ofb64_encrypt decrypt error\n"); printf("ofb64_encrypt decrypt error\n");
...@@ -672,7 +658,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); ...@@ -672,7 +658,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
} }
printf("Doing ede_ofb64\n"); printf("Doing ede_ofb64\n");
des_key_sched((C_Block *)ofb_key,ks); des_key_sched(ofb_key,ks);
memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
memset(ofb_buf1,0,sizeof(ofb_buf1)); memset(ofb_buf1,0,sizeof(ofb_buf1));
memset(ofb_buf2,0,sizeof(ofb_buf1)); memset(ofb_buf2,0,sizeof(ofb_buf1));
...@@ -680,7 +666,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); ...@@ -680,7 +666,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
for (i=0; i<sizeof(plain); i++) for (i=0; i<sizeof(plain); i++)
{ {
des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,ks, des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,ks,
(C_Block *)ofb_tmp,&num); ofb_tmp,&num);
} }
if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
{ {
...@@ -689,8 +675,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); ...@@ -689,8 +675,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
} }
memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
num=0; num=0;
des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks, des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,
ks,ks,(C_Block *)ofb_tmp,&num); ks,ks,ofb_tmp,&num);
if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
{ {
printf("ede_ofb64_encrypt decrypt error\n"); printf("ede_ofb64_encrypt decrypt error\n");
...@@ -698,9 +684,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); ...@@ -698,9 +684,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
} }
printf("Doing cbc_cksum\n"); printf("Doing cbc_cksum\n");
des_key_sched((C_Block *)cbc_key,ks); des_key_sched(cbc_key,ks);
cs=des_cbc_cksum((C_Block *)cbc_data,(C_Block *)cret, cs=des_cbc_cksum(cbc_data,cret,strlen(cbc_data),ks,cbc_iv);
(long)strlen(cbc_data),ks,(C_Block *)cbc_iv);
if (cs != cbc_cksum_ret) if (cs != cbc_cksum_ret)
{ {
printf("bad return value (%08lX), should be %08lX\n", printf("bad return value (%08lX), should be %08lX\n",
...@@ -714,8 +699,11 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); ...@@ -714,8 +699,11 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
} }
printf("Doing quad_cksum\n"); printf("Doing quad_cksum\n");
cs=quad_cksum((C_Block *)cbc_data,(C_Block *)qret, /* This is obviously done this way especially to puzzle me. Although
(long)strlen(cbc_data),2,(C_Block *)cbc_iv); quad_cksum returns up to 4 groups of 8 bytes, this test gets it to
produce 2 groupos then treats them as 4 groups of 4 bytes.
Ben 13 Feb 1999 */
cs=quad_cksum(cbc_data,(des_cblocks)qret,strlen(cbc_data),2,cbc_iv);
{ /* Big-endian fix */ { /* Big-endian fix */
static DES_LONG l=1; static DES_LONG l=1;
...@@ -777,17 +765,15 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); ...@@ -777,17 +765,15 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
for (i=0; i<4; i++) for (i=0; i<4; i++)
{ {
printf(" %d",i); printf(" %d",i);
des_ncbc_encrypt((C_Block *)&(cbc_out[i]),(C_Block *)cbc_in, des_ncbc_encrypt(&(cbc_out[i]),cbc_in,strlen(cbc_data)+1,ks,
(long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv, cbc_iv,DES_ENCRYPT);
DES_ENCRYPT);
} }
printf("\noutput word alignment test"); printf("\noutput word alignment test");
for (i=0; i<4; i++) for (i=0; i<4; i++)
{ {
printf(" %d",i); printf(" %d",i);
des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)&(cbc_in[i]), des_ncbc_encrypt(cbc_out,&(cbc_in[i]),strlen(cbc_data)+1,ks,
(long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv, cbc_iv,DES_ENCRYPT);
DES_ENCRYPT);
} }
printf("\n"); printf("\n");
printf("fast crypt test "); printf("fast crypt test ");
...@@ -837,10 +823,10 @@ unsigned char *cfb_cipher; ...@@ -837,10 +823,10 @@ unsigned char *cfb_cipher;
des_key_schedule ks; des_key_schedule ks;
int i,err=0; int i,err=0;
des_key_sched((C_Block *)cfb_key,ks); des_key_sched(cfb_key,ks);
memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
des_cfb_encrypt(plain,cfb_buf1,bits,(long)sizeof(plain),ks, des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,cfb_tmp,
(C_Block *)cfb_tmp,DES_ENCRYPT); DES_ENCRYPT);
if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
{ {
err=1; err=1;
...@@ -849,8 +835,8 @@ unsigned char *cfb_cipher; ...@@ -849,8 +835,8 @@ unsigned char *cfb_cipher;
printf("%s\n",pt(&(cfb_buf1[i]))); printf("%s\n",pt(&(cfb_buf1[i])));
} }
memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,(long)sizeof(plain),ks, des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,cfb_tmp,
(C_Block *)cfb_tmp,DES_DECRYPT); DES_DECRYPT);
if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
{ {
err=1; err=1;
...@@ -867,14 +853,12 @@ unsigned char *cfb_cipher; ...@@ -867,14 +853,12 @@ unsigned char *cfb_cipher;
des_key_schedule ks; des_key_schedule ks;
int err=0,i,n; int err=0,i,n;
des_key_sched((C_Block *)cfb_key,ks); des_key_sched(cfb_key,ks);
memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
n=0; n=0;
des_cfb64_encrypt(plain,cfb_buf1,(long)12,ks, des_cfb64_encrypt(plain,cfb_buf1,12,ks,cfb_tmp,&n,DES_ENCRYPT);
(C_Block *)cfb_tmp,&n,DES_ENCRYPT); des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks,
des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), cfb_tmp,&n,DES_ENCRYPT);
(long)sizeof(plain)-12,ks,
(C_Block *)cfb_tmp,&n,DES_ENCRYPT);
if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
{ {
err=1; err=1;
...@@ -884,11 +868,9 @@ unsigned char *cfb_cipher; ...@@ -884,11 +868,9 @@ unsigned char *cfb_cipher;
} }
memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
n=0; n=0;
des_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks, des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,cfb_tmp,&n,DES_DECRYPT);
(C_Block *)cfb_tmp,&n,DES_DECRYPT);
des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
(long)sizeof(plain)-17,ks, sizeof(plain)-17,ks,cfb_tmp,&n,DES_DECRYPT);
(C_Block *)cfb_tmp,&n,DES_DECRYPT);
if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
{ {
err=1; err=1;
...@@ -905,14 +887,14 @@ unsigned char *cfb_cipher; ...@@ -905,14 +887,14 @@ unsigned char *cfb_cipher;
des_key_schedule ks; des_key_schedule ks;
int err=0,i,n; int err=0,i,n;
des_key_sched((C_Block *)cfb_key,ks); des_key_sched(cfb_key,ks);
memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
n=0; n=0;
des_ede3_cfb64_encrypt(plain,cfb_buf1,(long)12,ks,ks,ks, des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,cfb_tmp,&n,
(C_Block *)cfb_tmp,&n,DES_ENCRYPT); DES_ENCRYPT);
des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
(long)sizeof(plain)-12,ks,ks,ks, sizeof(plain)-12,ks,ks,ks,
(C_Block *)cfb_tmp,&n,DES_ENCRYPT); cfb_tmp,&n,DES_ENCRYPT);
if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
{ {
err=1; err=1;
...@@ -923,10 +905,10 @@ unsigned char *cfb_cipher; ...@@ -923,10 +905,10 @@ unsigned char *cfb_cipher;
memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
n=0; n=0;
des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks, des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks,
(C_Block *)cfb_tmp,&n,DES_DECRYPT); cfb_tmp,&n,DES_DECRYPT);
des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
(long)sizeof(plain)-17,ks,ks,ks, sizeof(plain)-17,ks,ks,ks,
(C_Block *)cfb_tmp,&n,DES_DECRYPT); cfb_tmp,&n,DES_DECRYPT);
if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
{ {
err=1; err=1;
......
...@@ -58,20 +58,17 @@ ...@@ -58,20 +58,17 @@
#include "des_locl.h" #include "des_locl.h"
void des_ecb3_encrypt(input, output, ks1, ks2, ks3, enc) void des_ecb3_encrypt(in, out, ks1, ks2, ks3, enc)
des_cblock (*input); const des_cblock in;
des_cblock (*output); des_cblock out;
des_key_schedule ks1; des_key_schedule ks1;
des_key_schedule ks2; des_key_schedule ks2;
des_key_schedule ks3; des_key_schedule ks3;
int enc; int enc;
{ {
register DES_LONG l0,l1; register DES_LONG l0,l1;
register unsigned char *in,*out;
DES_LONG ll[2]; DES_LONG ll[2];
in=(unsigned char *)input;
out=(unsigned char *)output;
c2l(in,l0); c2l(in,l0);
c2l(in,l1); c2l(in,l1);
ll[0]=l0; ll[0]=l0;
......
...@@ -102,18 +102,15 @@ char *des_options() ...@@ -102,18 +102,15 @@ char *des_options()
} }
void des_ecb_encrypt(input, output, ks, enc) void des_ecb_encrypt(in, out, ks, enc)
des_cblock (*input); const unsigned char *in;
des_cblock (*output); unsigned char *out;
des_key_schedule ks; des_key_schedule ks;
int enc; int enc;
{ {
register DES_LONG l; register DES_LONG l;
register unsigned char *in,*out;
DES_LONG ll[2]; DES_LONG ll[2];
in=(unsigned char *)input;
out=(unsigned char *)output;
c2l(in,l); ll[0]=l; c2l(in,l); ll[0]=l;
c2l(in,l); ll[1]=l; c2l(in,l); ll[1]=l;
des_encrypt(ll,ks,enc); des_encrypt(ll,ks,enc);
......
...@@ -65,7 +65,7 @@ Feedback Masking, by Coppersmith, Johnson and Matyas, (IBM and Certicom). ...@@ -65,7 +65,7 @@ Feedback Masking, by Coppersmith, Johnson and Matyas, (IBM and Certicom).
#include "des_locl.h" #include "des_locl.h"
void des_ede3_cbcm_encrypt(const unsigned char *input,unsigned char *output, void des_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
long length, long length,
des_key_schedule ks1,des_key_schedule ks2, des_key_schedule ks1,des_key_schedule ks2,
des_key_schedule ks3, des_key_schedule ks3,
...@@ -74,15 +74,12 @@ void des_ede3_cbcm_encrypt(const unsigned char *input,unsigned char *output, ...@@ -74,15 +74,12 @@ void des_ede3_cbcm_encrypt(const unsigned char *input,unsigned char *output,
{ {
register DES_LONG tin0,tin1; register DES_LONG tin0,tin1;
register DES_LONG tout0,tout1,xor0,xor1,m0,m1; register DES_LONG tout0,tout1,xor0,xor1,m0,m1;
register unsigned char *in,*out;
register long l=length; register long l=length;
DES_LONG tin[2]; DES_LONG tin[2];
unsigned char *iv1,*iv2; unsigned char *iv1,*iv2;
in=(unsigned char *)input; iv1=ivec1;
out=(unsigned char *)output; iv2=ivec2;
iv1=(unsigned char *)ivec1;
iv2=(unsigned char *)ivec2;
if (enc) if (enc)
{ {
...@@ -125,11 +122,11 @@ void des_ede3_cbcm_encrypt(const unsigned char *input,unsigned char *output, ...@@ -125,11 +122,11 @@ void des_ede3_cbcm_encrypt(const unsigned char *input,unsigned char *output,
l2c(tout0,out); l2c(tout0,out);
l2c(tout1,out); l2c(tout1,out);
} }
iv1=(unsigned char *)ivec1; iv1=ivec1;
l2c(m0,iv1); l2c(m0,iv1);
l2c(m1,iv1); l2c(m1,iv1);
iv2=(unsigned char *)ivec2; iv2=ivec2;
l2c(tout0,iv2); l2c(tout0,iv2);
l2c(tout1,iv2); l2c(tout1,iv2);
} }
...@@ -182,11 +179,11 @@ void des_ede3_cbcm_encrypt(const unsigned char *input,unsigned char *output, ...@@ -182,11 +179,11 @@ void des_ede3_cbcm_encrypt(const unsigned char *input,unsigned char *output,
xor1=t1; xor1=t1;
} }
iv1=(unsigned char *)ivec1; iv1=ivec1;
l2c(m0,iv1); l2c(m0,iv1);
l2c(m1,iv1); l2c(m1,iv1);
iv2=(unsigned char *)ivec2; iv2=ivec2;
l2c(xor0,iv2); l2c(xor0,iv2);
l2c(xor1,iv2); l2c(xor1,iv2);
} }
......
...@@ -69,7 +69,7 @@ int fd; ...@@ -69,7 +69,7 @@ int fd;
char *buf; char *buf;
int len; int len;
des_key_schedule sched; des_key_schedule sched;
des_cblock (*iv); des_cblock iv;
{ {
/* data to be unencrypted */ /* data to be unencrypted */
int net_num=0; int net_num=0;
...@@ -165,11 +165,9 @@ des_cblock (*iv); ...@@ -165,11 +165,9 @@ des_cblock (*iv);
if (len < num) if (len < num)
{ {
if (des_rw_mode & DES_PCBC_MODE) if (des_rw_mode & DES_PCBC_MODE)
des_pcbc_encrypt((des_cblock *)net,(des_cblock *)unnet, des_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
num,sched,iv,DES_DECRYPT);
else else
des_cbc_encrypt((des_cblock *)net,(des_cblock *)unnet, des_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
num,sched,iv,DES_DECRYPT);
memcpy(buf,unnet,(unsigned int)len); memcpy(buf,unnet,(unsigned int)len);
unnet_start=len; unnet_start=len;
unnet_left=(int)num-len; unnet_left=(int)num-len;
...@@ -189,13 +187,11 @@ des_cblock (*iv); ...@@ -189,13 +187,11 @@ des_cblock (*iv);
{ {
if (des_rw_mode & DES_PCBC_MODE) if (des_rw_mode & DES_PCBC_MODE)
des_pcbc_encrypt((des_cblock *)net, des_pcbc_encrypt(net,tmpbuf,num,sched,iv,
(des_cblock *)tmpbuf, DES_DECRYPT);
num,sched,iv,DES_DECRYPT);
else else
des_cbc_encrypt((des_cblock *)net, des_cbc_encrypt(net,tmpbuf,num,sched,iv,
(des_cblock *)tmpbuf, DES_DECRYPT);
num,sched,iv,DES_DECRYPT);
/* eay 26/08/92 fix a bug that returned more /* eay 26/08/92 fix a bug that returned more
* bytes than you asked for (returned len bytes :-( */ * bytes than you asked for (returned len bytes :-( */
...@@ -204,13 +200,11 @@ des_cblock (*iv); ...@@ -204,13 +200,11 @@ des_cblock (*iv);
else else
{ {
if (des_rw_mode & DES_PCBC_MODE) if (des_rw_mode & DES_PCBC_MODE)
des_pcbc_encrypt((des_cblock *)net, des_pcbc_encrypt(net,buf,num,sched,iv,
(des_cblock *)buf,num,sched,iv, DES_DECRYPT);
DES_DECRYPT);
else else
des_cbc_encrypt((des_cblock *)net, des_cbc_encrypt(net,buf,num,sched,iv,
(des_cblock *)buf,num,sched,iv, DES_DECRYPT);
DES_DECRYPT);
} }
} }
return((int)num); return((int)num);
......
...@@ -62,10 +62,10 @@ ...@@ -62,10 +62,10 @@
int des_enc_write(fd, buf, len, sched, iv) int des_enc_write(fd, buf, len, sched, iv)
int fd; int fd;
char *buf; const char *buf;
int len; int len;
des_key_schedule sched; des_key_schedule sched;
des_cblock (*iv); des_cblock iv;
{ {
#ifdef _LIBC #ifdef _LIBC
extern int srandom(); extern int srandom();
...@@ -79,6 +79,7 @@ des_cblock (*iv); ...@@ -79,6 +79,7 @@ des_cblock (*iv);
static char *outbuf=NULL; static char *outbuf=NULL;
char shortbuf[8]; char shortbuf[8];
char *p; char *p;
const char *cp;
static int start=1; static int start=1;
if (outbuf == NULL) if (outbuf == NULL)
...@@ -117,7 +118,7 @@ des_cblock (*iv); ...@@ -117,7 +118,7 @@ des_cblock (*iv);
/* pad short strings */ /* pad short strings */
if (len < 8) if (len < 8)
{ {
p=shortbuf; cp=shortbuf;
memcpy(shortbuf,buf,(unsigned int)len); memcpy(shortbuf,buf,(unsigned int)len);
for (i=len; i<8; i++) for (i=len; i<8; i++)
shortbuf[i]=random(); shortbuf[i]=random();
...@@ -125,18 +126,16 @@ des_cblock (*iv); ...@@ -125,18 +126,16 @@ des_cblock (*iv);
} }
else else
{ {
p=buf; cp=buf;
rnum=((len+7)/8*8); /* round up to nearest eight */ rnum=((len+7)/8*8); /* round up to nearest eight */
} }
if (des_rw_mode & DES_PCBC_MODE) if (des_rw_mode & DES_PCBC_MODE)
des_pcbc_encrypt((des_cblock *)p, des_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
(des_cblock *)&(outbuf[HDRSIZE]), DES_ENCRYPT);
(long)((len<8)?8:len),sched,iv,DES_ENCRYPT);
else else
des_cbc_encrypt((des_cblock *)p, des_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
(des_cblock *)&(outbuf[HDRSIZE]), DES_ENCRYPT);
(long)((len<8)?8:len),sched,iv,DES_ENCRYPT);
/* output */ /* output */
outnum=(int)rnum+HDRSIZE; outnum=(int)rnum+HDRSIZE;
......
...@@ -123,7 +123,7 @@ r=(r+7)/8; ...@@ -123,7 +123,7 @@ r=(r+7)/8;
for (; i<8; i++) for (; i<8; i++)
key[i]=0; key[i]=0;
des_set_key((des_cblock *)(key),ks); des_set_key(key,ks);
fcrypt_body(&(out[0]),ks,Eswap0,Eswap1); fcrypt_body(&(out[0]),ks,Eswap0,Eswap1);
ll=out[0]; l2c(ll,b); ll=out[0]; l2c(ll,b);
......
...@@ -63,11 +63,11 @@ ...@@ -63,11 +63,11 @@
* 64bit block we have used is contained in *num; * 64bit block we have used is contained in *num;
*/ */
void des_ede3_ofb64_encrypt(in, out, length, k1,k2,k3, ivec, num) void des_ede3_ofb64_encrypt(in, out, length, k1,k2,k3, ivec, num)
register unsigned char *in; register const unsigned char *in;
register unsigned char *out; register unsigned char *out;
long length; long length;
des_key_schedule k1,k2,k3; des_key_schedule k1,k2,k3;
des_cblock (*ivec); des_cblock ivec;
int *num; int *num;
{ {
register DES_LONG v0,v1; register DES_LONG v0,v1;
...@@ -79,7 +79,7 @@ int *num; ...@@ -79,7 +79,7 @@ int *num;
unsigned char *iv; unsigned char *iv;
int save=0; int save=0;
iv=(unsigned char *)ivec; iv=ivec;
c2l(iv,v0); c2l(iv,v0);
c2l(iv,v1); c2l(iv,v1);
ti[0]=v0; ti[0]=v0;
...@@ -93,7 +93,7 @@ int *num; ...@@ -93,7 +93,7 @@ int *num;
{ {
/* ti[0]=v0; */ /* ti[0]=v0; */
/* ti[1]=v1; */ /* ti[1]=v1; */
des_encrypt3((DES_LONG *)ti,k1,k2,k3); des_encrypt3(ti,k1,k2,k3);
v0=ti[0]; v0=ti[0];
v1=ti[1]; v1=ti[1];
...@@ -109,7 +109,7 @@ int *num; ...@@ -109,7 +109,7 @@ int *num;
{ {
/* v0=ti[0]; /* v0=ti[0];
v1=ti[1];*/ v1=ti[1];*/
iv=(unsigned char *)ivec; iv=ivec;
l2c(v0,iv); l2c(v0,iv);
l2c(v1,iv); l2c(v1,iv);
} }
......
...@@ -63,36 +63,36 @@ ...@@ -63,36 +63,36 @@
* 64bit block we have used is contained in *num; * 64bit block we have used is contained in *num;
*/ */
void des_ofb64_encrypt(in, out, length, schedule, ivec, num) void des_ofb64_encrypt(in, out, length, schedule, ivec, num)
register unsigned char *in; register const unsigned char *in;
register unsigned char *out; register unsigned char *out;
long length; long length;
des_key_schedule schedule; des_key_schedule schedule;
des_cblock (*ivec); des_cblock ivec;
int *num; int *num;
{ {
register DES_LONG v0,v1,t; register DES_LONG v0,v1,t;
register int n= *num; register int n= *num;
register long l=length; register long l=length;
des_cblock d; des_cblock d;
register char *dp; register unsigned char *dp;
DES_LONG ti[2]; DES_LONG ti[2];
unsigned char *iv; unsigned char *iv;
int save=0; int save=0;
iv=(unsigned char *)ivec; iv=ivec;
c2l(iv,v0); c2l(iv,v0);
c2l(iv,v1); c2l(iv,v1);
ti[0]=v0; ti[0]=v0;
ti[1]=v1; ti[1]=v1;
dp=(char *)d; dp=d;
l2c(v0,dp); l2c(v0,dp);
l2c(v1,dp); l2c(v1,dp);
while (l--) while (l--)
{ {
if (n == 0) if (n == 0)
{ {
des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); des_encrypt(ti,schedule,DES_ENCRYPT);
dp=(char *)d; dp=d;
t=ti[0]; l2c(t,dp); t=ti[0]; l2c(t,dp);
t=ti[1]; l2c(t,dp); t=ti[1]; l2c(t,dp);
save++; save++;
...@@ -104,7 +104,7 @@ int *num; ...@@ -104,7 +104,7 @@ int *num;
{ {
v0=ti[0]; v0=ti[0];
v1=ti[1]; v1=ti[1];
iv=(unsigned char *)ivec; iv=ivec;
l2c(v0,iv); l2c(v0,iv);
l2c(v1,iv); l2c(v1,iv);
} }
......
...@@ -65,12 +65,12 @@ ...@@ -65,12 +65,12 @@
* byte. * byte.
*/ */
void des_ofb_encrypt(in, out, numbits, length, schedule, ivec) void des_ofb_encrypt(in, out, numbits, length, schedule, ivec)
unsigned char *in; const unsigned char *in;
unsigned char *out; unsigned char *out;
int numbits; int numbits;
long length; long length;
des_key_schedule schedule; des_key_schedule schedule;
des_cblock (*ivec); des_cblock ivec;
{ {
register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8; register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8;
register DES_LONG mask0,mask1; register DES_LONG mask0,mask1;
...@@ -97,7 +97,7 @@ des_cblock (*ivec); ...@@ -97,7 +97,7 @@ des_cblock (*ivec);
mask1=0x00000000L; mask1=0x00000000L;
} }
iv=(unsigned char *)ivec; iv=ivec;
c2l(iv,v0); c2l(iv,v0);
c2l(iv,v1); c2l(iv,v1);
ti[0]=v0; ti[0]=v0;
...@@ -131,7 +131,7 @@ des_cblock (*ivec); ...@@ -131,7 +131,7 @@ des_cblock (*ivec);
v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL; v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL;
} }
} }
iv=(unsigned char *)ivec; iv=ivec;
l2c(v0,iv); l2c(v0,iv);
l2c(v1,iv); l2c(v1,iv);
v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0; v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0;
......
...@@ -59,11 +59,11 @@ ...@@ -59,11 +59,11 @@
#include "des_locl.h" #include "des_locl.h"
void des_pcbc_encrypt(input, output, length, schedule, ivec, enc) void des_pcbc_encrypt(input, output, length, schedule, ivec, enc)
des_cblock (*input); const unsigned char *input;
des_cblock (*output); unsigned char *output;
long length; long length;
des_key_schedule schedule; des_key_schedule schedule;
des_cblock (*ivec); des_cblock ivec;
int enc; int enc;
{ {
register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1; register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1;
......
...@@ -74,11 +74,11 @@ ...@@ -74,11 +74,11 @@
#define NOISE ((DES_LONG)83653421L) #define NOISE ((DES_LONG)83653421L)
DES_LONG des_quad_cksum(input, output, length, out_count, seed) DES_LONG des_quad_cksum(input, output, length, out_count, seed)
des_cblock (*input); const unsigned char *input;
des_cblock (*output); des_cblocks output;
long length; long length;
int out_count; int out_count;
des_cblock (*seed); des_cblock seed;
{ {
DES_LONG z0,z1,t0,t1; DES_LONG z0,z1,t0,t1;
int i; int i;
...@@ -87,10 +87,10 @@ des_cblock (*seed); ...@@ -87,10 +87,10 @@ des_cblock (*seed);
unsigned char *lp; unsigned char *lp;
if (out_count < 1) out_count=1; if (out_count < 1) out_count=1;
lp=(unsigned char *)output; lp=output;
z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]); z0=Q_B0(seed[0])|Q_B1(seed[1])|Q_B2(seed[2])|Q_B3(seed[3]);
z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]); z1=Q_B0(seed[4])|Q_B1(seed[5])|Q_B2(seed[6])|Q_B3(seed[7]);
for (i=0; ((i<4)&&(i<out_count)); i++) for (i=0; ((i<4)&&(i<out_count)); i++)
{ {
...@@ -133,7 +133,7 @@ des_cblock (*seed); ...@@ -133,7 +133,7 @@ des_cblock (*seed);
} }
else else
{ {
lp=output[out_count-i-1]; lp=&output[out_count-i-1];
l2n(z1,lp); l2n(z1,lp);
l2n(z0,lp); l2n(z0,lp);
} }
......
...@@ -101,15 +101,13 @@ unsigned char *ret; ...@@ -101,15 +101,13 @@ unsigned char *ret;
t=(DES_LONG)((pid)|((c++)<<16)); t=(DES_LONG)((pid)|((c++)<<16));
l2c(t,p); l2c(t,p);
des_set_odd_parity((des_cblock *)data); des_set_odd_parity(data);
des_set_key((des_cblock *)data,ks); des_set_key(data,ks);
des_cbc_cksum((des_cblock *)key,(des_cblock *)key, des_cbc_cksum(key,key,sizeof(key),ks,data);
(long)sizeof(key),ks,(des_cblock *)data);
des_set_odd_parity((des_cblock *)key); des_set_odd_parity(key);
des_set_key((des_cblock *)key,ks); des_set_key(key,ks);
des_cbc_cksum((des_cblock *)key,(des_cblock *)data, des_cbc_cksum(key,data,sizeof(key),ks,key);
(long)sizeof(key),ks,(des_cblock *)key);
memcpy(ret,data,sizeof(key)); memcpy(ret,data,sizeof(key));
memset(key,0,sizeof(key)); memset(key,0,sizeof(key));
......
...@@ -59,8 +59,8 @@ ...@@ -59,8 +59,8 @@
#include "des_locl.h" #include "des_locl.h"
int des_read_password(key, prompt, verify) int des_read_password(key, prompt, verify)
des_cblock (*key); des_cblock key;
char *prompt; const char *prompt;
int verify; int verify;
{ {
int ok; int ok;
...@@ -74,9 +74,9 @@ int verify; ...@@ -74,9 +74,9 @@ int verify;
} }
int des_read_2passwords(key1, key2, prompt, verify) int des_read_2passwords(key1, key2, prompt, verify)
des_cblock (*key1); des_cblock key1;
des_cblock (*key2); des_cblock key2;
char *prompt; const char *prompt;
int verify; int verify;
{ {
int ok; int ok;
......
...@@ -209,7 +209,7 @@ int des_read_pw(buf, buff, size, prompt, verify) ...@@ -209,7 +209,7 @@ int des_read_pw(buf, buff, size, prompt, verify)
char *buf; char *buf;
char *buff; char *buff;
int size; int size;
char *prompt; const char *prompt;
int verify; int verify;
{ {
#ifdef VMS #ifdef VMS
......
...@@ -74,18 +74,16 @@ struct desparams *desp; ...@@ -74,18 +74,16 @@ struct desparams *desp;
des_key_schedule ks; des_key_schedule ks;
int enc; int enc;
des_set_key((des_cblock *)desp->des_key,ks); des_set_key(desp->des_key,ks);
enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT; enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;
if (desp->des_mode == CBC) if (desp->des_mode == CBC)
des_ecb_encrypt((des_cblock *)desp->UDES.UDES_buf, des_ecb_encrypt(desp->UDES.UDES_buf,desp->UDES.UDES_buf,ks,
(des_cblock *)desp->UDES.UDES_buf,ks,enc); enc);
else else
{ {
des_ncbc_encrypt((des_cblock *)desp->UDES.UDES_buf, des_ncbc_encrypt(desp->UDES.UDES_buf,desp->UDES.UDES_buf,
(des_cblock *)desp->UDES.UDES_buf, len,ks,desp->des_ivec,enc);
(long)len,ks,
(des_cblock *)desp->des_ivec,enc);
#ifdef undef #ifdef undef
/* len will always be %8 if called from common_crypt /* len will always be %8 if called from common_crypt
* in secure_rpc. * in secure_rpc.
......
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
#include "sk.h" #include "sk.h"
#ifndef NOPROTO #ifndef NOPROTO
static int check_parity(des_cblock (*key)); static int check_parity(const des_cblock key);
#else #else
static int check_parity(); static int check_parity();
#endif #endif
...@@ -76,22 +76,22 @@ static int check_parity(); ...@@ -76,22 +76,22 @@ static int check_parity();
int des_check_key=0; int des_check_key=0;
void des_set_odd_parity(key) void des_set_odd_parity(key)
des_cblock (*key); des_cblock key;
{ {
int i; int i;
for (i=0; i<DES_KEY_SZ; i++) for (i=0; i<DES_KEY_SZ; i++)
(*key)[i]=odd_parity[(*key)[i]]; key[i]=odd_parity[key[i]];
} }
static int check_parity(key) static int check_parity(key)
des_cblock (*key); const des_cblock key;
{ {
int i; int i;
for (i=0; i<DES_KEY_SZ; i++) for (i=0; i<DES_KEY_SZ; i++)
{ {
if ((*key)[i] != odd_parity[(*key)[i]]) if (key[i] != odd_parity[key[i]])
return(0); return(0);
} }
return(1); return(1);
...@@ -128,7 +128,7 @@ static des_cblock weak_keys[NUM_WEAK_KEY]={ ...@@ -128,7 +128,7 @@ static des_cblock weak_keys[NUM_WEAK_KEY]={
{0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}}; {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
int des_is_weak_key(key) int des_is_weak_key(key)
des_cblock (*key); const des_cblock key;
{ {
int i; int i;
...@@ -158,7 +158,7 @@ des_cblock (*key); ...@@ -158,7 +158,7 @@ des_cblock (*key);
* return -2 if illegal weak key. * return -2 if illegal weak key.
*/ */
int des_set_key(key, schedule) int des_set_key(key, schedule)
des_cblock (*key); const des_cblock key;
des_key_schedule schedule; des_key_schedule schedule;
{ {
static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0}; static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
...@@ -239,7 +239,7 @@ des_key_schedule schedule; ...@@ -239,7 +239,7 @@ des_key_schedule schedule;
} }
int des_key_sched(key, schedule) int des_key_sched(key, schedule)
des_cblock (*key); const des_cblock key;
des_key_schedule schedule; des_key_schedule schedule;
{ {
return(des_set_key(key,schedule)); return(des_set_key(key,schedule));
......
...@@ -61,8 +61,8 @@ ...@@ -61,8 +61,8 @@
extern int des_check_key; extern int des_check_key;
void des_string_to_key(str, key) void des_string_to_key(str, key)
char *str; const char *str;
des_cblock (*key); des_cblock key;
{ {
des_key_schedule ks; des_key_schedule ks;
int i,length; int i,length;
...@@ -72,38 +72,37 @@ des_cblock (*key); ...@@ -72,38 +72,37 @@ des_cblock (*key);
length=strlen(str); length=strlen(str);
#ifdef OLD_STR_TO_KEY #ifdef OLD_STR_TO_KEY
for (i=0; i<length; i++) for (i=0; i<length; i++)
(*key)[i%8]^=(str[i]<<1); key[i%8]^=(str[i]<<1);
#else /* MIT COMPATIBLE */ #else /* MIT COMPATIBLE */
for (i=0; i<length; i++) for (i=0; i<length; i++)
{ {
j=str[i]; j=str[i];
if ((i%16) < 8) if ((i%16) < 8)
(*key)[i%8]^=(j<<1); key[i%8]^=(j<<1);
else else
{ {
/* Reverse the bit order 05/05/92 eay */ /* Reverse the bit order 05/05/92 eay */
j=((j<<4)&0xf0)|((j>>4)&0x0f); j=((j<<4)&0xf0)|((j>>4)&0x0f);
j=((j<<2)&0xcc)|((j>>2)&0x33); j=((j<<2)&0xcc)|((j>>2)&0x33);
j=((j<<1)&0xaa)|((j>>1)&0x55); j=((j<<1)&0xaa)|((j>>1)&0x55);
(*key)[7-(i%8)]^=j; key[7-(i%8)]^=j;
} }
} }
#endif #endif
des_set_odd_parity((des_cblock *)key); des_set_odd_parity(key);
i=des_check_key; i=des_check_key;
des_check_key=0; des_check_key=0;
des_set_key((des_cblock *)key,ks); des_set_key(key,ks);
des_check_key=i; des_check_key=i;
des_cbc_cksum((des_cblock *)str,(des_cblock *)key,(long)length,ks, des_cbc_cksum(str,key,length,ks,key);
(des_cblock *)key);
memset(ks,0,sizeof(ks)); memset(ks,0,sizeof(ks));
des_set_odd_parity((des_cblock *)key); des_set_odd_parity(key);
} }
void des_string_to_2keys(str, key1, key2) void des_string_to_2keys(str, key1, key2)
char *str; const char *str;
des_cblock (*key1); des_cblock key1;
des_cblock (*key2); des_cblock key2;
{ {
des_key_schedule ks; des_key_schedule ks;
int i,length; int i,length;
...@@ -117,7 +116,7 @@ des_cblock (*key2); ...@@ -117,7 +116,7 @@ des_cblock (*key2);
{ {
for (i=0; i<length; i++) for (i=0; i<length; i++)
{ {
(*key2)[i]=(*key1)[i]=(str[i]<<1); key2[i]=key1[i]=(str[i]<<1);
} }
} }
else else
...@@ -125,9 +124,9 @@ des_cblock (*key2); ...@@ -125,9 +124,9 @@ des_cblock (*key2);
for (i=0; i<length; i++) for (i=0; i<length; i++)
{ {
if ((i/8)&1) if ((i/8)&1)
(*key2)[i%8]^=(str[i]<<1); key2[i%8]^=(str[i]<<1);
else else
(*key1)[i%8]^=(str[i]<<1); key1[i%8]^=(str[i]<<1);
} }
} }
#else /* MIT COMPATIBLE */ #else /* MIT COMPATIBLE */
...@@ -137,9 +136,9 @@ des_cblock (*key2); ...@@ -137,9 +136,9 @@ des_cblock (*key2);
if ((i%32) < 16) if ((i%32) < 16)
{ {
if ((i%16) < 8) if ((i%16) < 8)
(*key1)[i%8]^=(j<<1); key1[i%8]^=(j<<1);
else else
(*key2)[i%8]^=(j<<1); key2[i%8]^=(j<<1);
} }
else else
{ {
...@@ -147,23 +146,21 @@ des_cblock (*key2); ...@@ -147,23 +146,21 @@ des_cblock (*key2);
j=((j<<2)&0xcc)|((j>>2)&0x33); j=((j<<2)&0xcc)|((j>>2)&0x33);
j=((j<<1)&0xaa)|((j>>1)&0x55); j=((j<<1)&0xaa)|((j>>1)&0x55);
if ((i%16) < 8) if ((i%16) < 8)
(*key1)[7-(i%8)]^=j; key1[7-(i%8)]^=j;
else else
(*key2)[7-(i%8)]^=j; key2[7-(i%8)]^=j;
} }
} }
if (length <= 8) memcpy(key2,key1,8); if (length <= 8) memcpy(key2,key1,8);
#endif #endif
des_set_odd_parity((des_cblock *)key1); des_set_odd_parity(key1);
des_set_odd_parity((des_cblock *)key2); des_set_odd_parity(key2);
i=des_check_key; i=des_check_key;
des_check_key=0; des_check_key=0;
des_set_key((des_cblock *)key1,ks); des_set_key(key1,ks);
des_cbc_cksum((des_cblock *)str,(des_cblock *)key1,(long)length,ks, des_cbc_cksum(str,key1,length,ks,key1);
(des_cblock *)key1); des_set_key(key2,ks);
des_set_key((des_cblock *)key2,ks); des_cbc_cksum(str,key2,length,ks,key2);
des_cbc_cksum((des_cblock *)str,(des_cblock *)key2,(long)length,ks,
(des_cblock *)key2);
des_check_key=i; des_check_key=i;
memset(ks,0,sizeof(ks)); memset(ks,0,sizeof(ks));
des_set_odd_parity(key1); des_set_odd_parity(key1);
......
...@@ -87,14 +87,14 @@ ...@@ -87,14 +87,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: supp.c,v 1.1.1.2 1998/12/21 10:55:04 rse Exp $ * $Id: supp.c,v 1.2 1999/02/13 18:52:21 ben Exp $
*/ */
#include <stdio.h> #include <stdio.h>
#include "des_locl.h" #include "des_locl.h"
void des_cblock_print_file(cb, fp) void des_cblock_print_file(cb, fp)
des_cblock *cb; const des_cblock cb;
FILE *fp; FILE *fp;
{ {
int i; int i;
......
...@@ -79,19 +79,14 @@ static unsigned char desx_white_in2out[256]={ ...@@ -79,19 +79,14 @@ static unsigned char desx_white_in2out[256]={
0xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB, 0xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB,
}; };
void des_xwhite_in2out(des_key,in_white,out_white) void des_xwhite_in2out(key,in,out)
des_cblock (*des_key); const des_cblock key;
des_cblock (*in_white); const des_cblock in;
des_cblock (*out_white); des_cblock out;
{ {
unsigned char *key,*in,*out;
int out0,out1; int out0,out1;
int i; int i;
key=(unsigned char *)des_key;
in=(unsigned char *)in_white;
out=(unsigned char *)out_white;
out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0; out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0;
out0=out1=0; out0=out1=0;
for (i=0; i<8; i++) for (i=0; i<8; i++)
...@@ -111,34 +106,32 @@ des_cblock (*out_white); ...@@ -111,34 +106,32 @@ des_cblock (*out_white);
} }
} }
void des_xcbc_encrypt(input, output, length, schedule, ivec, inw,outw,enc) void des_xcbc_encrypt(in, out, length, schedule, ivec, inw,outw,enc)
des_cblock (*input); const unsigned char *in;
des_cblock (*output); unsigned char *out;
long length; long length;
des_key_schedule schedule; des_key_schedule schedule;
des_cblock (*ivec); des_cblock ivec;
des_cblock (*inw); const des_cblock inw;
des_cblock (*outw); const des_cblock outw;
int enc; int enc;
{ {
register DES_LONG tin0,tin1; register DES_LONG tin0,tin1;
register DES_LONG tout0,tout1,xor0,xor1; register DES_LONG tout0,tout1,xor0,xor1;
register DES_LONG inW0,inW1,outW0,outW1; register DES_LONG inW0,inW1,outW0,outW1;
register unsigned char *in,*out; register const unsigned char *in2;
register long l=length; register long l=length;
DES_LONG tin[2]; DES_LONG tin[2];
unsigned char *iv; unsigned char *iv;
in=(unsigned char *)inw; in2=inw;
c2l(in,inW0); c2l(in2,inW0);
c2l(in,inW1); c2l(in2,inW1);
in=(unsigned char *)outw; in2=outw;
c2l(in,outW0); c2l(in2,outW0);
c2l(in,outW1); c2l(in2,outW1);
in=(unsigned char *)input; iv=ivec;
out=(unsigned char *)output;
iv=(unsigned char *)ivec;
if (enc) if (enc)
{ {
...@@ -150,7 +143,7 @@ int enc; ...@@ -150,7 +143,7 @@ int enc;
c2l(in,tin1); c2l(in,tin1);
tin0^=tout0^inW0; tin[0]=tin0; tin0^=tout0^inW0; tin[0]=tin0;
tin1^=tout1^inW1; tin[1]=tin1; tin1^=tout1^inW1; tin[1]=tin1;
des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); des_encrypt(tin,schedule,DES_ENCRYPT);
tout0=tin[0]^outW0; l2c(tout0,out); tout0=tin[0]^outW0; l2c(tout0,out);
tout1=tin[1]^outW1; l2c(tout1,out); tout1=tin[1]^outW1; l2c(tout1,out);
} }
...@@ -159,11 +152,11 @@ int enc; ...@@ -159,11 +152,11 @@ int enc;
c2ln(in,tin0,tin1,l+8); c2ln(in,tin0,tin1,l+8);
tin0^=tout0^inW0; tin[0]=tin0; tin0^=tout0^inW0; tin[0]=tin0;
tin1^=tout1^inW1; tin[1]=tin1; tin1^=tout1^inW1; tin[1]=tin1;
des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); des_encrypt(tin,schedule,DES_ENCRYPT);
tout0=tin[0]^outW0; l2c(tout0,out); tout0=tin[0]^outW0; l2c(tout0,out);
tout1=tin[1]^outW1; l2c(tout1,out); tout1=tin[1]^outW1; l2c(tout1,out);
} }
iv=(unsigned char *)ivec; iv=ivec;
l2c(tout0,iv); l2c(tout0,iv);
l2c(tout1,iv); l2c(tout1,iv);
} }
...@@ -175,7 +168,7 @@ int enc; ...@@ -175,7 +168,7 @@ int enc;
{ {
c2l(in,tin0); tin[0]=tin0^outW0; c2l(in,tin0); tin[0]=tin0^outW0;
c2l(in,tin1); tin[1]=tin1^outW1; c2l(in,tin1); tin[1]=tin1^outW1;
des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); des_encrypt(tin,schedule,DES_DECRYPT);
tout0=tin[0]^xor0^inW0; tout0=tin[0]^xor0^inW0;
tout1=tin[1]^xor1^inW1; tout1=tin[1]^xor1^inW1;
l2c(tout0,out); l2c(tout0,out);
...@@ -187,7 +180,7 @@ int enc; ...@@ -187,7 +180,7 @@ int enc;
{ {
c2l(in,tin0); tin[0]=tin0^outW0; c2l(in,tin0); tin[0]=tin0^outW0;
c2l(in,tin1); tin[1]=tin1^outW1; c2l(in,tin1); tin[1]=tin1^outW1;
des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); des_encrypt(tin,schedule,DES_DECRYPT);
tout0=tin[0]^xor0^inW0; tout0=tin[0]^xor0^inW0;
tout1=tin[1]^xor1^inW1; tout1=tin[1]^xor1^inW1;
l2cn(tout0,tout1,out,l+8); l2cn(tout0,tout1,out,l+8);
...@@ -195,7 +188,7 @@ int enc; ...@@ -195,7 +188,7 @@ int enc;
xor1=tin1; xor1=tin1;
} }
iv=(unsigned char *)ivec; iv=ivec;
l2c(xor0,iv); l2c(xor0,iv);
l2c(xor1,iv); l2c(xor1,iv);
} }
......
...@@ -122,8 +122,8 @@ int enc; ...@@ -122,8 +122,8 @@ int enc;
if (key != NULL) if (key != NULL)
{ {
des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); des_set_key(key,ctx->c.des_ede.ks1);
des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); des_set_key(&(key[8]),ctx->c.des_ede.ks2);
memcpy( (char *)ctx->c.des_ede.ks3, memcpy( (char *)ctx->c.des_ede.ks3,
(char *)ctx->c.des_ede.ks1, (char *)ctx->c.des_ede.ks1,
sizeof(ctx->c.des_ede.ks1)); sizeof(ctx->c.des_ede.ks1));
...@@ -142,9 +142,9 @@ int enc; ...@@ -142,9 +142,9 @@ int enc;
if (key != NULL) if (key != NULL)
{ {
des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); des_set_key(key,ctx->c.des_ede.ks1);
des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); des_set_key(&(key[8]),ctx->c.des_ede.ks2);
des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3); des_set_key(&(key[16]),ctx->c.des_ede.ks3);
} }
} }
...@@ -154,10 +154,8 @@ unsigned char *out; ...@@ -154,10 +154,8 @@ unsigned char *out;
unsigned char *in; unsigned char *in;
unsigned int inl; unsigned int inl;
{ {
des_ede3_cbc_encrypt( des_ede3_cbc_encrypt(in,out,inl, ctx->c.des_ede.ks1,
(des_cblock *)in,(des_cblock *)out,
(long)inl, ctx->c.des_ede.ks1,
ctx->c.des_ede.ks2,ctx->c.des_ede.ks3, ctx->c.des_ede.ks2,ctx->c.des_ede.ks3,
(des_cblock *)&(ctx->iv[0]), &(ctx->iv[0]),
ctx->encrypt); ctx->encrypt);
} }
...@@ -101,7 +101,7 @@ int enc; ...@@ -101,7 +101,7 @@ int enc;
memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->oiv[0]),iv,8);
memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
if (key != NULL) if (key != NULL)
des_set_key((des_cblock *)key,ctx->c.des_ks); des_set_key(key,ctx->c.des_ks);
} }
static void des_cfb_cipher(ctx,out,in,inl) static void des_cfb_cipher(ctx,out,in,inl)
...@@ -113,6 +113,6 @@ unsigned int inl; ...@@ -113,6 +113,6 @@ unsigned int inl;
des_cfb64_encrypt( des_cfb64_encrypt(
in,out, in,out,
(long)inl, ctx->c.des_ks, (long)inl, ctx->c.des_ks,
(des_cblock *)&(ctx->iv[0]), &(ctx->iv[0]),
&ctx->num,ctx->encrypt); &ctx->num,ctx->encrypt);
} }
...@@ -117,8 +117,8 @@ int enc; ...@@ -117,8 +117,8 @@ int enc;
{ {
if (key != NULL) if (key != NULL)
{ {
des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); des_set_key(key,ctx->c.des_ede.ks1);
des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); des_set_key(&(key[8]),ctx->c.des_ede.ks2);
memcpy( (char *)ctx->c.des_ede.ks3, memcpy( (char *)ctx->c.des_ede.ks3,
(char *)ctx->c.des_ede.ks1, (char *)ctx->c.des_ede.ks1,
sizeof(ctx->c.des_ede.ks1)); sizeof(ctx->c.des_ede.ks1));
...@@ -133,9 +133,9 @@ int enc; ...@@ -133,9 +133,9 @@ int enc;
{ {
if (key != NULL) if (key != NULL)
{ {
des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); des_set_key(key,ctx->c.des_ede.ks1);
des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); des_set_key(&(key[8]),ctx->c.des_ede.ks2);
des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3); des_set_key(&(key[16]),ctx->c.des_ede.ks3);
} }
} }
...@@ -151,8 +151,7 @@ unsigned int inl; ...@@ -151,8 +151,7 @@ unsigned int inl;
inl-=8; inl-=8;
for (i=0; i<=inl; i+=8) for (i=0; i<=inl; i+=8)
{ {
des_ecb3_encrypt( des_ecb3_encrypt(&(in[i]),&(out[i]),
(des_cblock *)&(in[i]),(des_cblock *)&(out[i]),
ctx->c.des_ede.ks1, ctx->c.des_ede.ks1,
ctx->c.des_ede.ks2, ctx->c.des_ede.ks2,
ctx->c.des_ede.ks3, ctx->c.des_ede.ks3,
......
...@@ -96,7 +96,7 @@ unsigned char *iv; ...@@ -96,7 +96,7 @@ unsigned char *iv;
int enc; int enc;
{ {
if (key != NULL) if (key != NULL)
des_set_key((des_cblock *)key,ctx->c.des_ks); des_set_key(key,ctx->c.des_ks);
} }
static void des_ecb_cipher(ctx,out,in,inl) static void des_ecb_cipher(ctx,out,in,inl)
...@@ -111,8 +111,6 @@ unsigned int inl; ...@@ -111,8 +111,6 @@ unsigned int inl;
inl-=8; inl-=8;
for (i=0; i<=inl; i+=8) for (i=0; i<=inl; i+=8)
{ {
des_ecb_encrypt( des_ecb_encrypt(&(in[i]),&(out[i]),ctx->c.des_ks,ctx->encrypt);
(des_cblock *)&(in[i]),(des_cblock *)&(out[i]),
ctx->c.des_ks,ctx->encrypt);
} }
} }
...@@ -100,7 +100,7 @@ int enc; ...@@ -100,7 +100,7 @@ int enc;
memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
if (key != NULL) if (key != NULL)
{ {
des_set_key((des_cblock *)key,ctx->c.desx_cbc.ks); des_set_key(key,ctx->c.desx_cbc.ks);
memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8); memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8);
memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8); memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8);
} }
...@@ -112,11 +112,9 @@ unsigned char *out; ...@@ -112,11 +112,9 @@ unsigned char *out;
unsigned char *in; unsigned char *in;
unsigned int inl; unsigned int inl;
{ {
des_xcbc_encrypt( des_xcbc_encrypt(in,out,inl,ctx->c.desx_cbc.ks,
(des_cblock *)in,(des_cblock *)out, &(ctx->iv[0]),
(long)inl, ctx->c.desx_cbc.ks, &(ctx->c.desx_cbc.inw[0]),
(des_cblock *)&(ctx->iv[0]), &(ctx->c.desx_cbc.outw[0]),
(des_cblock *)&(ctx->c.desx_cbc.inw[0]),
(des_cblock *)&(ctx->c.desx_cbc.outw[0]),
ctx->encrypt); ctx->encrypt);
} }
...@@ -135,35 +135,35 @@ unsigned int len; ...@@ -135,35 +135,35 @@ unsigned int len;
register DES_LONG tin0,tin1; register DES_LONG tin0,tin1;
register DES_LONG ttin0,ttin1; register DES_LONG ttin0,ttin1;
DES_LONG d[2],dd[2]; DES_LONG d[2],dd[2];
des_cblock *h,*hh; unsigned char *h,*hh;
des_key_schedule k; des_key_schedule k;
unsigned char *p; unsigned char *p;
unsigned int i; unsigned int i;
h= (des_cblock *)&(c->h[0]); h= c->h;
hh= (des_cblock *)&(c->hh[0]); hh= c->hh;
for (i=0; i<len; i+=8) for (i=0; i<len; i+=8)
{ {
c2l(in,tin0); d[0]=dd[0]=tin0; c2l(in,tin0); d[0]=dd[0]=tin0;
c2l(in,tin1); d[1]=dd[1]=tin1; c2l(in,tin1); d[1]=dd[1]=tin1;
(*h)[0]=((*h)[0]&0x9f)|0x40; h[0]=(h[0]&0x9f)|0x40;
(*hh)[0]=((*hh)[0]&0x9f)|0x20; hh[0]=(hh[0]&0x9f)|0x20;
des_set_odd_parity(h); des_set_odd_parity(h);
des_set_key(h,k); des_set_key(h,k);
des_encrypt((DES_LONG *)d,k,1); des_encrypt(d,k,1);
des_set_odd_parity(hh); des_set_odd_parity(hh);
des_set_key(hh,k); des_set_key(hh,k);
des_encrypt((DES_LONG *)dd,k,1); des_encrypt(dd,k,1);
ttin0=tin0^dd[0]; ttin0=tin0^dd[0];
ttin1=tin1^dd[1]; ttin1=tin1^dd[1];
tin0^=d[0]; tin0^=d[0];
tin1^=d[1]; tin1^=d[1];
p=(unsigned char *)h; p=h;
l2c(tin0,p); l2c(tin0,p);
l2c(ttin1,p); l2c(ttin1,p);
p=(unsigned char *)hh; p=(unsigned char *)hh;
......
...@@ -659,8 +659,8 @@ static ASN1_OBJECT *obj_objs[NUM_OBJ]={ ...@@ -659,8 +659,8 @@ static ASN1_OBJECT *obj_objs[NUM_OBJ]={
&(nid_objs[19]),/* OBJ_rsa 2 5 8 1 1 */ &(nid_objs[19]),/* OBJ_rsa 2 5 8 1 1 */
&(nid_objs[96]),/* OBJ_mdc2WithRSA 2 5 8 3 100 */ &(nid_objs[96]),/* OBJ_mdc2WithRSA 2 5 8 3 100 */
&(nid_objs[95]),/* OBJ_mdc2 2 5 8 3 101 */ &(nid_objs[95]),/* OBJ_mdc2 2 5 8 3 101 */
&(nid_objs[124]),/* OBJ_rle_compression 1 1 1 1 666.1 */
&(nid_objs[125]),/* OBJ_zlib_compression 1 1 1 1 666.2 */ &(nid_objs[125]),/* OBJ_zlib_compression 1 1 1 1 666.2 */
&(nid_objs[124]),/* OBJ_rle_compression 1 1 1 1 666.1 */
&(nid_objs[104]),/* OBJ_md5WithRSA 1 3 14 3 2 3 */ &(nid_objs[104]),/* OBJ_md5WithRSA 1 3 14 3 2 3 */
&(nid_objs[29]),/* OBJ_des_ecb 1 3 14 3 2 6 */ &(nid_objs[29]),/* OBJ_des_ecb 1 3 14 3 2 6 */
&(nid_objs[31]),/* OBJ_des_cbc 1 3 14 3 2 7 */ &(nid_objs[31]),/* OBJ_des_cbc 1 3 14 3 2 7 */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册