Fix strange formatting by indent
[openssl.git] / crypto / des / xcbc_enc.c
index fa251170fbd46db826ef195f5df5166f46fcc767..058cab6bce0cb95e039f17ebf1097f77b199c2f3 100644 (file)
@@ -1,5 +1,5 @@
 /* crypto/des/xcbc_enc.c */
 /* crypto/des/xcbc_enc.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  * This package is an SSL implementation written
  * All rights reserved.
  *
  * This package is an SSL implementation written
@@ -60,7 +60,8 @@
 
 /* RSA's DESX */
 
 
 /* RSA's DESX */
 
-static unsigned char desx_white_in2out[256]={
+#if 0 /* broken code, preserved just in case anyone specifically looks for this */
+static const unsigned char desx_white_in2out[256]={
 0xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0,
 0x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A,
 0x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36,
 0xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0,
 0x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A,
 0x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36,
@@ -79,18 +80,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)
-des_cblock (*des_key);
-des_cblock (*in_white);
-des_cblock (*out_white);
+void DES_xwhite_in2out(const_DES_cblock *des_key, const_DES_cblock *in_white,
+            DES_cblock *out_white)
        {
        {
-       unsigned char *key,*in,*out;
        int out0,out1;
        int i;
        int out0,out1;
        int i;
-
-       key=(unsigned char *)des_key;
-       in=(unsigned char *)in_white;
-       out=(unsigned char *)out_white;
+       const unsigned char *key = &(*des_key)[0];
+       const unsigned char *in = &(*in_white)[0];
+       unsigned char *out = &(*out_white)[0];
 
        out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0;
        out0=out1=0;
 
        out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0;
        out0=out1=0;
@@ -102,7 +99,7 @@ des_cblock (*out_white);
                }
 
        out0=out[0];
                }
 
        out0=out[0];
-       out1=out[i];
+       out1=out[i]; /* BUG: out-of-bounds read */
        for (i=0; i<8; i++)
                {
                out[i]=in[i]^desx_white_in2out[out0^out1];
        for (i=0; i<8; i++)
                {
                out[i]=in[i]^desx_white_in2out[out0^out1];
@@ -110,35 +107,29 @@ des_cblock (*out_white);
                out1=(int)out[i&0x07];
                }
        }
                out1=(int)out[i&0x07];
                }
        }
+#endif
 
 
-void des_xcbc_encrypt(input, output, length, schedule, ivec, inw,outw,enc)
-des_cblock (*input);
-des_cblock (*output);
-long length;
-des_key_schedule schedule;
-des_cblock (*ivec);
-des_cblock (*inw);
-des_cblock (*outw);
-int enc;
+void DES_xcbc_encrypt(const unsigned char *in, unsigned char *out,
+                     long length, DES_key_schedule *schedule,
+                     DES_cblock *ivec, const_DES_cblock *inw,
+                     const_DES_cblock *outw, int enc)
        {
        register DES_LONG tin0,tin1;
        register DES_LONG tout0,tout1,xor0,xor1;
        register DES_LONG inW0,inW1,outW0,outW1;
        {
        register DES_LONG tin0,tin1;
        register DES_LONG tout0,tout1,xor0,xor1;
        register DES_LONG inW0,inW1,outW0,outW1;
-       register unsigned char *in,*out;
+       register const unsigned char *in2;
        register long l=length;
        DES_LONG tin[2];
        unsigned char *iv;
 
        register long l=length;
        DES_LONG tin[2];
        unsigned char *iv;
 
-       in=(unsigned char *)inw;
-       c2l(in,inW0);
-       c2l(in,inW1);
-       in=(unsigned char *)outw;
-       c2l(in,outW0);
-       c2l(in,outW1);
+       in2 = &(*inw)[0];
+       c2l(in2,inW0);
+       c2l(in2,inW1);
+       in2 = &(*outw)[0];
+       c2l(in2,outW0);
+       c2l(in2,outW1);
 
 
-       in=(unsigned char *)input;
-       out=(unsigned char *)output;
-       iv=(unsigned char *)ivec;
+       iv = &(*ivec)[0];
 
        if (enc)
                {
 
        if (enc)
                {
@@ -150,7 +141,7 @@ int enc;
                        c2l(in,tin1);
                        tin0^=tout0^inW0; tin[0]=tin0;
                        tin1^=tout1^inW1; tin[1]=tin1;
                        c2l(in,tin1);
                        tin0^=tout0^inW0; tin[0]=tin0;
                        tin1^=tout1^inW1; tin[1]=tin1;
-                       des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
+                       DES_encrypt1(tin,schedule,DES_ENCRYPT);
                        tout0=tin[0]^outW0; l2c(tout0,out);
                        tout1=tin[1]^outW1; l2c(tout1,out);
                        }
                        tout0=tin[0]^outW0; l2c(tout0,out);
                        tout1=tin[1]^outW1; l2c(tout1,out);
                        }
@@ -159,11 +150,11 @@ int enc;
                        c2ln(in,tin0,tin1,l+8);
                        tin0^=tout0^inW0; tin[0]=tin0;
                        tin1^=tout1^inW1; tin[1]=tin1;
                        c2ln(in,tin0,tin1,l+8);
                        tin0^=tout0^inW0; tin[0]=tin0;
                        tin1^=tout1^inW1; tin[1]=tin1;
-                       des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
+                       DES_encrypt1(tin,schedule,DES_ENCRYPT);
                        tout0=tin[0]^outW0; l2c(tout0,out);
                        tout1=tin[1]^outW1; l2c(tout1,out);
                        }
                        tout0=tin[0]^outW0; l2c(tout0,out);
                        tout1=tin[1]^outW1; l2c(tout1,out);
                        }
-               iv=(unsigned char *)ivec;
+               iv = &(*ivec)[0];
                l2c(tout0,iv);
                l2c(tout1,iv);
                }
                l2c(tout0,iv);
                l2c(tout1,iv);
                }
@@ -175,7 +166,7 @@ int enc;
                        {
                        c2l(in,tin0); tin[0]=tin0^outW0;
                        c2l(in,tin1); tin[1]=tin1^outW1;
                        {
                        c2l(in,tin0); tin[0]=tin0^outW0;
                        c2l(in,tin1); tin[1]=tin1^outW1;
-                       des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
+                       DES_encrypt1(tin,schedule,DES_DECRYPT);
                        tout0=tin[0]^xor0^inW0;
                        tout1=tin[1]^xor1^inW1;
                        l2c(tout0,out);
                        tout0=tin[0]^xor0^inW0;
                        tout1=tin[1]^xor1^inW1;
                        l2c(tout0,out);
@@ -187,7 +178,7 @@ int enc;
                        {
                        c2l(in,tin0); tin[0]=tin0^outW0;
                        c2l(in,tin1); tin[1]=tin1^outW1;
                        {
                        c2l(in,tin0); tin[0]=tin0^outW0;
                        c2l(in,tin1); tin[1]=tin1^outW1;
-                       des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
+                       DES_encrypt1(tin,schedule,DES_DECRYPT);
                        tout0=tin[0]^xor0^inW0;
                        tout1=tin[1]^xor1^inW1;
                        l2cn(tout0,tout1,out,l+8);
                        tout0=tin[0]^xor0^inW0;
                        tout1=tin[1]^xor1^inW1;
                        l2cn(tout0,tout1,out,l+8);
@@ -195,7 +186,7 @@ int enc;
                        xor1=tin1;
                        }
 
                        xor1=tin1;
                        }
 
-               iv=(unsigned char *)ivec;
+               iv = &(*ivec)[0];
                l2c(xor0,iv);
                l2c(xor1,iv);
                }
                l2c(xor0,iv);
                l2c(xor1,iv);
                }