Before being flamed, I aquired this source from a website were it was publicly released. Knowing that it's publicly released, and there is no extra information provided by the author of the source; i'm going to post it here.
void _stdcall calchashbuf(unsigned long *hash, void *inbuf, int len) {
char *buf = (char*)inbuf;
int pos;
int sublen;
unsigned long hashbuf[0x10 + 5];
hashbuf[0] = 0x67452301;
hashbuf[1] = 0xEFCDAB89;
hashbuf[2] = 0x98BADCFE;
hashbuf[3] = 0x10325476;
hashbuf[4] = 0xC3D2E1F0;
for(pos=0; pos<len; pos+=0x40) {
sublen = len - pos;
if(sublen > 0x40)
sublen = 0x40;
memcpy(hashbuf+5, buf+pos, sublen);
if(sublen<0x40)
ZeroMemory((char*)(hashbuf+5)+sublen, 0x40-sublen);
datahash(hashbuf);
}
memcpy(hash, hashbuf, 5*4);
}
void _stdcall datahash(unsigned long*param) {
unsigned long buf[0x50];
unsigned long dw, a, b, c, d, e, *p;
int i;
memcpy(buf, param+5, 0x40);
for(i=0x10; i<0x50; i++) {
dw = buf[i-0x10]^buf[i-0x8]^buf[i-0xe]^buf[i-0x3];
buf[i] = (1>>(0x20-(unsigned char)dw)) | (1<<(unsigned char)dw);
}
a = param[0];
b = param[1];
c = param[2];
d = param[3];
e = param[4];
p = buf;
i = 0x14;
do {
dw = ((a<<5) | (a>>0x1b)) + ((~b & d) | (c & b)) + e + *p++ + 0x5A827999;
e = d;
d = c;
c = (b>>2) | (b<<0x1e);
b = a;
a = dw;
} while(--i);
i = 0x14;
do {
dw = (d ^ c ^ b) + e + ((a<<5) | (a>>0x1b)) + *p++ + 0x6ED9EBA1;
e = d;
d = c;
c = (b>>2) | (b<<0x1e);
b = a;
a = dw;
} while(--i);
i = 0x14;
do {
dw = ((c & b) | (d & c) | (d & b)) + e + ((a<<5) | (a>>0x1b)) + *p++ - 0x70E44324;
e = d;
d = c;
c = (b>>2) | (b<<0x1e);
b = a;
a = dw;
} while(--i);
i = 0x14;
do {
dw = ((a<<5) | (a>>0x1b)) + e + (d ^ c ^ b) + *p++ - 0x359D3E2A;
e = d;
d = c;
c = (b>>2) | (b<<0x1e);
b = a;
a = dw;
} while(--i);
param[0] += a;
param[1] += b;
param[2] += c;
param[3] += d;
param[4] += e;
}
Now... all you visual basic user's have fun converting it from c++ :D It shouldn't be too hard. The first thing you want to do is implement some of the unsupported bitwise operators (examples being the L/R shift operators)
[edit] I didn't look @ the source too long. If there is any other function(s) called by any of the above that aren't provided tell me. I will post them also.
Quote from: TheMinistered on May 01, 2003, 08:08 PM
If there is any other function(s) called by any of the above that aren't provided tell me. I will post them also.
memcpy and ZeroMemory ;)
heck, i may as well give people a head start on the vb version ;)
Public Function CalcHashBuf(ByVal buf As String) As String
Dim pos As Long, sublen As Long
Dim hashbuf(&H10 + 5) As Long
hashbuf(0) = &H67452301
hashbuf(1) = &HEFCDAB89
hashbuf(2) = &H98BADCFE
hashbuf(3) = &H10325476
hashbuf(4) = &HC3D2E1F0
For pos = 0 To Len(buf) Step &H40
sublen = Len(buf) - pos
If sublen > &H40 Then sublen = &H40
Dim t As String
t = Mid(buf, pos + 1, sublen) & String(&H40 - sublen, Chr(0))
Dim i As Long
For i = 0 To 15
hashbuf(5 + i) = CVL(Mid(t, i * 4 + 1, 4))
Next
datahash hashbuf
Next
CalcHashBuf = MKL(hashbuf(0)) & MKL(hashbuf(1)) & MKL(hashbuf(2)) & MKL(hashbuf(3)) & MKL(hashbuf(4))
End Function
you can port hashdata yourself ;)
Quote from: Maddox on May 02, 2003, 12:44 AM
Or...
void HashData(void* lpSource, int nLength, void* lpResult)
{
...
}
isn't that totally defunct by now?
Aww... camel you take all the fun out of it :) well not really the newbies will never port it because they don't have enough math skills to implement the missing bitwise functions, gg :)
if(sublen<0x40)
ZeroMemory((char*)(hashbuf+5)+sublen, 0x40-sublen);
where did you implement that in your version? you might have... i just scanned your code a little bit.
[edit] I missed the very end of the code line where you move data into variable t
Quote from: TheMinistered on May 03, 2003, 08:52 PM
Aww... camel you take all the fun out of it :) well not really the newbies will never port it because they don't have enough math skills to implement the missing bitwise functions, gg :)
it requires writing an lshift(), rshift(), and add() function (need add because vb
refuses to stop checking for overflows unless you compile, and then it'll just crash if you overflow)
G = buf(i)
G = Add(G, Rol(A, 5))
G = Add(G, E)
G = Add(G, ((B And C) Or ((Not B) And D)))
G = Add(G, &H5A827999)
Rol(A, 5)
You forgot to mention you need bitwise rotations too?
Quote from: TheMinistered on May 03, 2003, 09:26 PM
Rol(A, 5)
You forgot to mention you need bitwise rotations too?
_asm shl [TheMinistered], SizeOf(forum)*8
[edit] forgot it shifts bits not bytes >.<
shl isn't a bitwise rotation, it's a bitwise shift left.
rol is a bitwise rotate left, and ror is a bitwise rotate right.
Also, rcl and rcr extend the operand by 1 bit by using CF (the Carry Flag) as the 33rd bit (assuming the operand is 32 bits), and perform the bitwise rotation.
The above sentences assume x86.
Yoni, where are you getting that? I don't see anyone here saying that shl is a bitwise rotation..
Quote from: Arta[vL] on May 05, 2003, 01:42 PM
TheMinistered:
Quote from: Camel on May 03, 2003, 09:43 PM
Quote from: TheMinistered on May 03, 2003, 09:26 PM
Rol(A, 5)
...
_asm shl [TheMinistered], SizeOf(forum)*8
that doesn't answer the question
nobody said or even implied that shl rotates; the whole idea was that i was pushing the data at [TheMinistered] left by the number of bits in the forum. he wasn't supposed to pop back up on the other end.
call createbird
push storm
push shit
call birdexcrete