00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifdef _MSC_VER
00010 #include "des_locl.h"
00011 #include "spr.h"
00012 #include "version.h"
00013 #else
00014 #include "libdes/des_locl.h"
00015 #include "libdes/spr.h"
00016 #include "libdes/version.h"
00017 #endif
00018
00019 int des_ecb_encrypt(input,output,ks,encrypt)
00020 des_cblock *input;
00021 des_cblock *output;
00022 des_key_schedule ks;
00023 int encrypt;
00024 {
00025 register unsigned long l0,l1;
00026 register unsigned char *in,*out;
00027 unsigned long ll[2];
00028
00029 in=(unsigned char *)input;
00030 out=(unsigned char *)output;
00031 c2l(in,l0);
00032 c2l(in,l1);
00033 ll[0]=l0;
00034 ll[1]=l1;
00035 des_encrypt(ll,ll,ks,encrypt);
00036 l0=ll[0];
00037 l1=ll[1];
00038 l2c(l0,out);
00039 l2c(l1,out);
00040 l0=l1=ll[0]=ll[1]=0;
00041 return(0);
00042 }
00043
00044 int des_encrypt(input,output,ks,encrypt)
00045 unsigned long *input;
00046 unsigned long *output;
00047 des_key_schedule ks;
00048 int encrypt;
00049 {
00050 register unsigned long l,r,t,u;
00051 #ifdef ALT_ECB
00052 register unsigned char *des_SP=(unsigned char *)des_SPtrans;
00053 #endif
00054 #ifdef MSDOS
00055 union fudge {
00056 unsigned long l;
00057 unsigned short s[2];
00058 unsigned char c[4];
00059 } U,T;
00060 #endif
00061 register int i;
00062 register unsigned long *s;
00063
00064 l=input[0];
00065 r=input[1];
00066
00067 IP(l,r,t);
00068
00069
00070
00071
00072
00073
00074 t=(r<<1)|(r>>31);
00075 r=(l<<1)|(l>>31);
00076 l=t;
00077
00078
00079 l&=0xffffffffL;
00080 r&=0xffffffffL;
00081
00082 s=(unsigned long *)ks;
00083
00084
00085 if (encrypt)
00086 {
00087 for (i=0; i<32; i+=4)
00088 {
00089 D_ENCRYPT(l,r,i+0);
00090 D_ENCRYPT(r,l,i+2);
00091 }
00092 }
00093 else
00094 {
00095 for (i=30; i>0; i-=4)
00096 {
00097 D_ENCRYPT(l,r,i-0);
00098 D_ENCRYPT(r,l,i-2);
00099 }
00100 }
00101 l=(l>>1)|(l<<31);
00102 r=(r>>1)|(r<<31);
00103
00104 l&=0xffffffffL;
00105 r&=0xffffffffL;
00106
00107 FP(r,l,t);
00108 output[0]=l;
00109 output[1]=r;
00110 l=r=t=u=0;
00111 return(0);
00112 }