On Mon, 21 Dec 2009, T T wrote:
> 2009/12/21 Hans Hagen <[email protected]>:
> >> Something seems to be wrong with the library:
> >>
> >> For example
> >>
> >> $echo -n "test" | md5sum 098f6bcd4621d373cade4e832627b4f6  -
> >>
> >> but
> >>
> >> print(md5.sumhexa("test")) gives
> >>
> >> 0944483cd90a293923c8244520132de1
> >
> > strange, as on my machine (vista) it gives
> >
> > 098f6bcd4621d373cade4e832627b4f6
> >
>
> Same here on WinXP with luatex beta-0.40.6-2009110118 &
> beta-0.46.0-2009112716.
>
> I don't know what gives. I did test Reinhard's installer on the same
> machine and with the same binaries and it failed on checksums back
> then.

seems to be a 32/64 bit issue. After sprinkling the md5.c code with 32
bit MASKs (see diff) luatex indeed gives the correct
098f6bcd4621d373cade4e832627b4f6 on an x86_64 AMD debian Linux PC.
Unclear which MASK made it, but i guess it's in the rotate().

Regards, Hartmut
Index: source/texk/web2c/luatexdir/luamd5/md5.c
===================================================================
--- source/texk/web2c/luatexdir/luamd5/md5.c	(Revision 3282)
+++ source/texk/web2c/luatexdir/luamd5/md5.c	(Arbeitskopie)
@@ -30,7 +30,7 @@
 ** Realiza a rotacao no sentido horario dos bits da variavel 'D' do tipo WORD32.
 ** Os bits sao deslocados de 'num' posicoes
 */
-#define rotate(D, num)  (D<<num) | (D>>(WORD-num))
+#define rotate(D, num)  ((D<<num) & MASK) | (((D & MASK)>>(WORD-num)) & MASK)
 
 /*Macros que definem operacoes relizadas pelo algoritmo  md5 */
 #define F(x, y, z) (((x) & (y)) | ((~(x)) & (z)))
@@ -64,9 +64,10 @@
   int j = 0;
   while (j<4*4) {
     WORD32 v = *input++;
-    output[j++] = (char)(v & 0xff); v >>= 8;
-    output[j++] = (char)(v & 0xff); v >>= 8;
-    output[j++] = (char)(v & 0xff); v >>= 8;
+v=v&MASK;
+    output[j++] = (char)(v & 0xff); v = (v >> 8) & MASK;
+    output[j++] = (char)(v & 0xff); v = (v >> 8) & MASK;
+    output[j++] = (char)(v & 0xff); v = (v >> 8) & MASK;
     output[j++] = (char)(v & 0xff);
   }
 }
@@ -150,6 +151,7 @@
            (WORD32)(unsigned char)pt[j+2]) << 8 |
            (WORD32)(unsigned char)pt[j+1]) << 8 |
            (WORD32)(unsigned char)pt[j];
+x[i] = x[i] & MASK;
   }
 
 }
Index: source/texk/web2c/luatexdir/luamd5/md5lib.c
===================================================================
--- source/texk/web2c/luatexdir/luamd5/md5lib.c	(Revision 3282)
+++ source/texk/web2c/luatexdir/luamd5/md5lib.c	(Arbeitskopie)
@@ -25,7 +25,9 @@
   char buff[16];
   size_t l;
   const char *message = luaL_checklstring(L, 1, &l);
+printf("\n=============== <%s> l=%d\n",message,l);
   md5(message, l, buff);
+printf("\n=============== <%s>\n",buff);
   lua_pushlstring(L, buff, 16L);
   return 1;
 }
_______________________________________________
dev-luatex mailing list
[email protected]
http://www.ntg.nl/mailman/listinfo/dev-luatex

Reply via email to