00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifdef _MSC_VER
00010 #include "des_locl.h"
00011 #else
00012 #include "libdes/des_locl.h"
00013 #endif
00014
00015 int des_pcbc_encrypt(input,output,length,schedule,ivec,encrypt)
00016 des_cblock *input;
00017 des_cblock *output;
00018 long length;
00019 des_key_schedule schedule;
00020 des_cblock *ivec;
00021 int encrypt;
00022 {
00023 register unsigned long sin0,sin1,xor0,xor1,tout0,tout1;
00024 unsigned long tin[2],tout[2];
00025 unsigned char *in,*out,*iv;
00026
00027 in=(unsigned char *)input;
00028 out=(unsigned char *)output;
00029 iv=(unsigned char *)ivec;
00030
00031 if (encrypt)
00032 {
00033 c2l(iv,xor0);
00034 c2l(iv,xor1);
00035 for (; length>0; length-=8)
00036 {
00037 if (length >= 8)
00038 {
00039 c2l(in,sin0);
00040 c2l(in,sin1);
00041 }
00042 else
00043 c2ln(in,sin0,sin1,length);
00044 tin[0]=sin0^xor0;
00045 tin[1]=sin1^xor1;
00046 des_encrypt((unsigned long *)tin,(unsigned long *)tout,
00047 schedule,encrypt);
00048 tout0=tout[0];
00049 tout1=tout[1];
00050 xor0=sin0^tout[0];
00051 xor1=sin1^tout[1];
00052 l2c(tout0,out);
00053 l2c(tout1,out);
00054 }
00055 }
00056 else
00057 {
00058 c2l(iv,xor0); c2l(iv,xor1);
00059 for (; length>0; length-=8)
00060 {
00061 c2l(in,sin0);
00062 c2l(in,sin1);
00063 tin[0]=sin0;
00064 tin[1]=sin1;
00065 des_encrypt((unsigned long *)tin,(unsigned long *)tout,
00066 schedule,encrypt);
00067 tout0=tout[0]^xor0;
00068 tout1=tout[1]^xor1;
00069 if (length >= 8)
00070 {
00071 l2c(tout0,out);
00072 l2c(tout1,out);
00073 }
00074 else
00075 l2cn(tout0,tout1,out,length);
00076 xor0=tout0^sin0;
00077 xor1=tout1^sin1;
00078 }
00079 }
00080 tin[0]=tin[1]=tout[0]=tout[1]=0;
00081 sin0=sin1=xor0=xor1=tout0=tout1=0;
00082 return(0);
00083 }