Click here to Skip to main content
15,890,282 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Compiling 64bit Pin
Richard MacCutchan16-Jul-10 23:00
mveRichard MacCutchan16-Jul-10 23:00 
Questionproper conversion of unsigned char [16] -> unsigned long [4] [modified] Pin
saiyuk6=716-Jul-10 8:45
saiyuk6=716-Jul-10 8:45 
AnswerRe: proper conversion of unsigned char [16] -> unsigned long [4] Pin
Chris Losinger16-Jul-10 9:14
professionalChris Losinger16-Jul-10 9:14 
GeneralRe: proper conversion of unsigned char [16] -> unsigned long [4] Pin
saiyuk6=716-Jul-10 9:28
saiyuk6=716-Jul-10 9:28 
GeneralRe: proper conversion of unsigned char [16] -> unsigned long [4] Pin
Chris Losinger16-Jul-10 9:40
professionalChris Losinger16-Jul-10 9:40 
GeneralRe: proper conversion of unsigned char [16] -> unsigned long [4] Pin
saiyuk6=716-Jul-10 9:53
saiyuk6=716-Jul-10 9:53 
GeneralRe: proper conversion of unsigned char [16] -> unsigned long [4] Pin
Chris Losinger16-Jul-10 10:27
professionalChris Losinger16-Jul-10 10:27 
GeneralRe: proper conversion of unsigned char [16] -> unsigned long [4] Pin
saiyuk6=716-Jul-10 10:40
saiyuk6=716-Jul-10 10:40 
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;
}

void main(void)
{
   unsigned char bszBuffer[2] = {'A', 'B'};
   unsigned long ulSig[4];
   SignBuffer((unsigned char*)"key", bszBuffer, 2, ulSig);
   printf("\n");
   if (VerifyBuffer((unsigned char*)"key", bszBuffer, 2, ulSig))
      printf("\nok");
   else printf("\nerr");
}


I had made _ustrlen because i got tired of using casting for (unsigned char*), unless there is a different way?
AnswerRe: proper conversion of unsigned char [16] -> unsigned long [4] Pin
Code-o-mat16-Jul-10 9:18
Code-o-mat16-Jul-10 9:18 
GeneralRe: proper conversion of unsigned char [16] -> unsigned long [4] Pin
saiyuk6=716-Jul-10 9:39
saiyuk6=716-Jul-10 9:39 
QuestionFIX protocol: Logon using QuickFix engine Pin
arupsarkar16-Jul-10 7:01
arupsarkar16-Jul-10 7:01 
AnswerRe: FIX protocol: Logon using QuickFix engine Pin
Garth J Lancaster18-Jul-10 1:07
professionalGarth J Lancaster18-Jul-10 1:07 
Questioncurl to return server response Pin
Eli Nurman16-Jul-10 4:40
Eli Nurman16-Jul-10 4:40 
AnswerRe: curl to return server response Pin
Aescleal16-Jul-10 20:18
Aescleal16-Jul-10 20:18 
QuestionMagic Packet Pin
Fareed Rizkalla16-Jul-10 4:04
Fareed Rizkalla16-Jul-10 4:04 
AnswerRe: Magic Packet Pin
Richard MacCutchan16-Jul-10 7:07
mveRichard MacCutchan16-Jul-10 7:07 
QuestionHow to send data to a C# App which has WPF control (text box) from VC++ application. Pin
Joseph8216-Jul-10 3:38
Joseph8216-Jul-10 3:38 
AnswerRe: How to send data to a C# App which has WPF control (text box) from VC++ application. Pin
Hristo-Bojilov16-Jul-10 7:24
Hristo-Bojilov16-Jul-10 7:24 
QuestionActive Directory/LDAP. Pin
Mike Doner16-Jul-10 2:47
Mike Doner16-Jul-10 2:47 
AnswerRe: Active Directory/LDAP. Pin
Emilio Garavaglia16-Jul-10 7:05
Emilio Garavaglia16-Jul-10 7:05 
GeneralRe: Active Directory/LDAP. Pin
Mike Doner29-Jul-10 7:59
Mike Doner29-Jul-10 7:59 
GeneralRe: Active Directory/LDAP. Pin
Emilio Garavaglia31-Jul-10 9:33
Emilio Garavaglia31-Jul-10 9:33 
QuestionINT_PTR in VC++ 2010 Pin
rp_suman16-Jul-10 1:43
rp_suman16-Jul-10 1:43 
AnswerRe: INT_PTR in VC++ 2010 Pin
Sauro Viti16-Jul-10 2:16
professionalSauro Viti16-Jul-10 2:16 
AnswerRe: INT_PTR in VC++ 2010 Pin
ThatsAlok18-Jul-10 20:49
ThatsAlok18-Jul-10 20:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.