I just use MD5 algorithm, the code is from Internet. In wvMD5StoreDigest() and wvMD5Update(), there are totally three memcpy() calls. I have another function (has the large iteration) to call these MD5 function. Here is the function code:
Code:
int KeySearch(unsigned char salt[],
unsigned char hashedsalt[], // 16
unsigned char begin[], // 5
unsigned long step,
unsigned char validkey[] //5
)
{
wvMD5_CTX mdContext,mdContext2;
U8 pwarray[64];
rc4_key key;
unsigned long *pKey = (unsigned long *)pwarray;
unsigned long i;
memset (pwarray, 0, 64);
memcpy (pwarray, begin, 5);
pwarray[9] = 0x80;
pwarray[56] = 0x48;
salt[16] = 0x80;
memset (salt + 17, 0, 47);
salt[56] = 0x80;
for (i=0; i < step; ++i) {
wvMD5Init (&mdContext);
wvMD5Update (&mdContext, pwarray, 64);
wvMD5StoreDigest (&mdContext);
(*pKey)++;
prepare_key (mdContext.digest, 16, &key);
rc4 (salt, 16, &key);
rc4 (hashedsalt, 16, &key);
wvMD5Init (&mdContext2);
wvMD5Update (&mdContext2, salt, 64);
wvMD5StoreDigest (&mdContext2);
if ((memcmp (mdContext2.digest, hashedsalt, 16)) == 0) {
memcpy(validkey, mdContext.digest, 5);
return 1;
}
}
return 0;
}