Hi
I need the MD4 Hash algorithm and since I couldn't find it in .NET,
I looked for libraries in the Web.
The only thing I found was something written in Java.
Now I'm trying to convert the source.
I fixed all the syntax errors but it seems I converted some bitwise operators wrongly.
Javacode:
My VB.NET code:
It throws an "A first chance exception of type 'System.OverflowException' occurred in HashLib.dll" on:
The error most likly results from converting the operator >>> to >>,
since VB.NET doesn't have that one.
How can I get the "Unsigned" right shift to work in VB.NET?
I need the MD4 Hash algorithm and since I couldn't find it in .NET,
I looked for libraries in the Web.
The only thing I found was something written in Java.
Now I'm trying to convert the source.
I fixed all the syntax errors but it seems I converted some bitwise operators wrongly.
Javacode:
Visual Basic:
int X0 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 | in[i++] << 24;
int X1 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 | (in[i++] & 0xFF) << 16 | in[i++] << 24;
...
int aa, bb, cc, dd;
aa = a; bb = b; cc = c; dd = d;
aa += ((bb & cc) | ((~bb) & dd)) + X0;
aa = aa << 3 | aa >>> -3;
dd += ((aa & bb) | ((~aa) & cc)) + X1;
dd = dd << 7 | dd >>> -7;
cc += ((dd & aa) | ((~dd) & bb)) + X2;
cc = cc << 11 | cc >>> -11;
bb += ((cc & dd) | ((~cc) & aa)) + X3;
bb = bb << 19 | bb >>> -19;
...
aa += ((bb & (cc | dd)) | (cc & dd)) + X0 + 0x5a827999;
aa = aa << 3 | aa >>> -3;
dd += ((aa & (bb | cc)) | (bb & cc)) + X4 + 0x5a827999;
dd = dd << 5 | dd >>> -5;
cc += ((dd & (aa | bb)) | (aa & bb)) + X8 + 0x5a827999;
cc = cc << 9 | cc >>> -9;
bb += ((cc & (dd | aa)) | (dd & aa)) + X12 + 0x5a827999;
bb = bb << 13 | bb >>> -13;
...
aa += (bb ^ cc ^ dd) + X0 + 0x6ed9eba1;
aa = aa << 3 | aa >>> -3;
dd += (aa ^ bb ^ cc) + X8 + 0x6ed9eba1;
dd = dd << 9 | dd >>> -9;
cc += (dd ^ aa ^ bb) + X4 + 0x6ed9eba1;
cc = cc << 11 | cc >>> -11;
bb += (cc ^ dd ^ aa) + X12 + 0x6ed9eba1;
bb = bb << 15 | bb >>> -15;
...
a += aa; b += bb; c += cc; d += dd;
My VB.NET code:
Visual Basic:
Dim X0 As Integer = (b(Add(i)) And &HFF) Or (b(Add(i)) And &HFF) << 8 Or (b(Add(i)) And &HFF) << 16 Or b(Add(i)) << 24
Dim X1 As Integer = (b(Add(i)) And &HFF) Or (b(Add(i)) And &HFF) << 8 Or (b(Add(i)) And &HFF) << 16 Or b(Add(i)) << 24
...
Dim aa, bb, cc, dd As Integer
aa = A
bb = Me.B
cc = C
dd = D
aa += ((bb And cc) Or ((Not bb) And dd)) + X0
aa = aa << 3 Or aa >> -3
dd += ((aa And bb) Or ((Not aa) And cc)) + X1
dd = dd << 7 Or dd >> -7
cc += ((dd And aa) Or ((Not dd) And bb)) + X2
cc = cc << 11 Or cc >> -11
bb += ((cc And dd) Or ((Not cc) And aa)) + X3
bb = bb << 19 Or bb >> -19
...
aa += ((bb And (cc Or dd)) Or (cc And dd)) + X0 + &H5A827999
aa = aa << 3 Or aa >> -3
dd += ((aa And (bb Or cc)) Or (bb And cc)) + X4 + &H5A827999
dd = dd << 5 Or dd >> -5
cc += ((dd And (aa Or bb)) Or (aa And bb)) + X8 + &H5A827999
cc = cc << 9 Or cc >> -9
bb += ((cc And (dd Or aa)) Or (dd And aa)) + X12 + &H5A827999
bb = bb << 13 Or bb >> -13
...
aa += (bb Xor cc Xor dd) + X0 + &H6ED9EBA1
aa = aa << 3 Or aa >> -3
dd += (aa Xor bb Xor cc) + X8 + &H6ED9EBA1
dd = dd << 9 Or dd >> -9
cc += (dd Xor aa Xor bb) + X4 + &H6ED9EBA1
cc = cc << 11 Or cc >> -11
bb += (cc Xor dd Xor aa) + X12 + &H6ED9EBA1
bb = bb << 15 Or bb >> -15
...
A += aa
Me.B += bb
C += cc
D += dd
It throws an "A first chance exception of type 'System.OverflowException' occurred in HashLib.dll" on:
Visual Basic:
cc += ((dd And aa) Or ((Not dd) And bb)) + X14
The error most likly results from converting the operator >>> to >>,
since VB.NET doesn't have that one.
How can I get the "Unsigned" right shift to work in VB.NET?