]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - mdfour.c
Add more CHECKGLERROR calls, and clean up a few obsolete code scraps.
[xonotic/darkplaces.git] / mdfour.c
index c550651ec37b8eba38d1f747631e2ba425baef5f..36180c6e74b957392a69391c938f20924da9599c 100644 (file)
--- a/mdfour.c
+++ b/mdfour.c
@@ -37,8 +37,6 @@
    It assumes that a int is at least 32 bits long
 */
 
-static struct mdfour *m;
-
 #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))
@@ -53,7 +51,7 @@ static struct mdfour *m;
 #define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + 0x6ED9EBA1,s)
 
 /* this applies md4 to 64 byte chunks */
-static void mdfour64(uint32 *M)
+static void mdfour64(struct mdfour *md, uint32 *M)
 {
        int j;
        uint32 AA, BB, CC, DD;
@@ -63,7 +61,7 @@ static void mdfour64(uint32 *M)
        for (j=0;j<16;j++)
                X[j] = M[j];
 
-       A = m->A; B = m->B; C = m->C; D = m->D;
+       A = md->A; B = md->B; C = md->C; D = md->D;
        AA = A; BB = B; CC = C; DD = D;
 
         ROUND1(A,B,C,D,  0,  3);  ROUND1(D,A,B,C,  1,  7);
@@ -103,10 +101,10 @@ static void mdfour64(uint32 *M)
        for (j=0;j<16;j++)
                X[j] = 0;
 
-       m->A = A; m->B = B; m->C = C; m->D = D;
+       md->A = A; md->B = B; md->C = C; md->D = D;
 }
 
-static void copy64(uint32 *M, unsigned char *in)
+static void copy64(uint32 *M, const unsigned char *in)
 {
        int i;
 
@@ -133,15 +131,15 @@ void mdfour_begin(struct mdfour *md)
 }
 
 
-static void mdfour_tail(unsigned char *in, int n)
+static void mdfour_tail(struct mdfour *md, const unsigned char *in, int n)
 {
        unsigned char buf[128];
        uint32 M[16];
        uint32 b;
 
-       m->totalN += n;
+       md->totalN += n;
 
-       b = m->totalN * 8;
+       b = md->totalN * 8;
 
        memset(buf, 0, 128);
        if (n) memcpy(buf, in, n);
@@ -150,17 +148,17 @@ static void mdfour_tail(unsigned char *in, int n)
        if (n <= 55) {
                copy4(buf+56, b);
                copy64(M, buf);
-               mdfour64(M);
+               mdfour64(md, M);
        } else {
                copy4(buf+120, b);
                copy64(M, buf);
-               mdfour64(M);
+               mdfour64(md, M);
                copy64(M, buf+64);
-               mdfour64(M);
+               mdfour64(md, M);
        }
 }
 
-void mdfour_update(struct mdfour *md, unsigned char *in, int n)
+void mdfour_update(struct mdfour *md, const unsigned char *in, int n)
 {
        uint32 M[16];
 
@@ -169,32 +167,28 @@ void mdfour_update(struct mdfour *md, unsigned char *in, int n)
 //     if (n == 0) mdfour_tail(in, n);
 // end of edit by Forest 'LordHavoc' Hale
 
-       m = md;
-
        while (n >= 64) {
                copy64(M, in);
-               mdfour64(M);
+               mdfour64(md, M);
                in += 64;
                n -= 64;
-               m->totalN += 64;
+               md->totalN += 64;
        }
 
-       mdfour_tail(in, n);
+       mdfour_tail(md, in, n);
 }
 
 
 void mdfour_result(struct mdfour *md, unsigned char *out)
 {
-       m = md;
-
-       copy4(out, m->A);
-       copy4(out+4, m->B);
-       copy4(out+8, m->C);
-       copy4(out+12, m->D);
+       copy4(out, md->A);
+       copy4(out+4, md->B);
+       copy4(out+8, md->C);
+       copy4(out+12, md->D);
 }
 
 
-void mdfour(unsigned char *out, unsigned char *in, int n)
+void mdfour(unsigned char *out, const unsigned char *in, int n)
 {
        struct mdfour md;
        mdfour_begin(&md);