i fixed it, thank you very much for your help, i noticed
if (tl->_1 == pBuffer[0] && tl->_2 == pBuffer[1] &&
tl->_3 == pBuffer[2] && tl->_4 == pBuffer[4])
bResult = true;
pBuffer[4] should of been pBuffer[3] i was going out of range of the array which didnt exist here is the updated code
int _ustrlen(unsigned char *pbz)
{
const unsigned char *ptr;
for (ptr = pbz; *ptr; ++ptr);
return (ptr - pbz);
}
void SignBuffer(unsigned char *pbzKey, unsigned char *pbzBuffer,
unsigned int iSize, unsigned long *pSignature)
{
MD5_CTX md5, md5key;
BLOWFISH_CTX bf;
MD5Init(&md5);
MD5Update(&md5, pbzBuffer, iSize);
MD5Final(&md5);
_2LONG *tl = (_2LONG*) md5.digest;
printf("BLE 1\t\t %x %x %x %x\n", tl->_1, tl->_2, tl->_3, tl->_4);
MD5Init(&md5key);
MD5Update(&md5key, pbzKey, _ustrlen(pbzKey));
MD5Final(&md5key);
Blowfish_Init(&bf, md5key.digest, 16);
Blowfish_Encrypt(&bf, &tl->_1, &tl->_2);
Blowfish_Encrypt(&bf, &tl->_3, &tl->_4);
pSignature[0] = tl->_1;
pSignature[1] = tl->_2;
pSignature[2] = tl->_3;
pSignature[3] = tl->_4;
printf("BLE 2\t\t %x %x %x %x\n", pSignature[0], pSignature[1],
pSignature[2], pSignature[3]);
}
bool VerifyBuffer(unsigned char *pbzKey, unsigned char *pSignature,
unsigned int iSize, unsigned long *pBuffer)
{
BLOWFISH_CTX bf;
MD5_CTX md5, md5key;
bool bResult = false;
printf("BLD 1\t\t %x %x %x %x\n", pBuffer[0], pBuffer[1],
pBuffer[2], pBuffer[3]);
MD5Init(&md5key);
MD5Update(&md5key, pbzKey, _ustrlen(pbzKey));
MD5Final(&md5key);
Blowfish_Init(&bf, md5key.digest, 16);
Blowfish_Decrypt(&bf, &pBuffer[0], &pBuffer[1]);
Blowfish_Decrypt(&bf, &pBuffer[2], &pBuffer[3]);
printf("BLD 2\t\t %x %x %x %x\n", pBuffer[0], pBuffer[1],
pBuffer[2], pBuffer[3]);
MD5Init(&md5);
MD5Update(&md5, pSignature, iSize);
MD5Final(&md5);
_2LONG *tl = (_2LONG*) md5.digest;
printf("BLD 3\t\t %x %x %x %x\n", tl->_1, tl->_2, tl->_3, tl->_4);
if (tl->_1 == pBuffer[0] && tl->_2 == pBuffer[1] &&
tl->_3 == pBuffer[2] && tl->_4 == pBuffer[3])
bResult = true;
return bResult;