applied simple nohang patch from Wayne Davison
[rsync/rsync.git] / lib / mdfour.c
index 48dfc78..0a059dc 100644 (file)
 
 static struct mdfour *m;
 
-static uint32 F(uint32 X, uint32 Y, uint32 Z)
-{
-       return (X&Y) | ((~X)&Z);
-}
-
-static uint32 G(uint32 X, uint32 Y, uint32 Z)
-{
-       return (X&Y) | (X&Z) | (Y&Z); 
-}
-
-static uint32 H(uint32 X, uint32 Y, uint32 Z)
-{
-       return X^Y^Z;
-}
-
-static uint32 lshift(uint32 x, int s)
-{
-       x &= 0xFFFFFFFF;
-       return ((x<<s)&0xFFFFFFFF) | (x>>(32-s));
-}
+#define F(X,Y,Z) (((X)&(Y)) | ((~(X))&(Z)))
+#define G(X,Y,Z) (((X)&(Y)) | ((X)&(Z)) | ((Y)&(Z)))
+#define H(X,Y,Z) ((X)^(Y)^(Z))
+#ifdef LARGE_INT32
+#define lshift(x,s) ((((x)<<(s))&0xFFFFFFFF) | (((x)>>(32-(s)))&0xFFFFFFFF))
+#else
+#define lshift(x,s) (((x)<<(s)) | ((x)>>(32-(s))))
+#endif
 
-#define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s)
-#define ROUND2(a,b,c,d,k,s) a = lshift(a + G(b,c,d) + X[k] + (uint32)0x5A827999,s)
-#define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + (uint32)0x6ED9EBA1,s)
+#define ROUND1(a,b,c,d,k,s) a = lshift((uint32)(a + F(b,c,d) + X[k]), s)
+#define ROUND2(a,b,c,d,k,s) a = lshift((uint32)(a + G(b,c,d) + X[k] + 0x5A827999),s)
+#define ROUND3(a,b,c,d,k,s) a = lshift((uint32)(a + H(b,c,d) + X[k] + 0x6ED9EBA1),s)
 
 /* this applies md4 to 64 byte chunks */
 static void mdfour64(uint32 *M)
@@ -96,8 +84,10 @@ static void mdfour64(uint32 *M)
 
        A += AA; B += BB; C += CC; D += DD;
        
+#ifdef LARGE_INT32
        A &= 0xFFFFFFFF; B &= 0xFFFFFFFF;
        C &= 0xFFFFFFFF; D &= 0xFFFFFFFF;
+#endif
 
        for (j=0;j<16;j++)
                X[j] = 0;
@@ -157,9 +147,6 @@ static void mdfour_tail(unsigned char *in, int n)
                copy64(M, buf+64);
                mdfour64(M);
        }
-
-       memset(buf, 0, 128);
-       copy64(M, buf); 
 }
 
 void mdfour_update(struct mdfour *md, unsigned char *in, int n)
@@ -206,8 +193,8 @@ static void file_checksum1(char *fname)
 {
        int fd, i;
        struct mdfour md;
-       unsigned char buf[64], sum[16];
-
+       unsigned char buf[64*1024], sum[16];
+       
        fd = open(fname,O_RDONLY);
        if (fd == -1) {
                perror("fname");
@@ -231,6 +218,7 @@ static void file_checksum1(char *fname)
        printf("\n");
 }
 
+#if 0
 #include "../md4.h"
 
 static void file_checksum2(char *fname)
@@ -265,11 +253,14 @@ static void file_checksum2(char *fname)
                printf("%02X", sum[i]);
        printf("\n");
 }
+#endif
 
  int main(int argc, char *argv[])
 {
        file_checksum1(argv[1]);
+#if 0
        file_checksum2(argv[1]);
+#endif
        return 0;
 }
 #endif