Padding output is reversed.
Brought to you by:
dreichl
The padding of the hex output is reversed. The padding is added on the wrong side of the number. It should be prepended and instead it is appended.
Current implementation example:
CRC16 = 8959 (hex - nopad, little endian)
CRC16 = 89590000 (hex - with incorrect padding, little endian)
CRC16 = 13789 (decimal)
If you were to convert that padded hex value to decimal you would get "2304311296", way over 2^16.
It should be.
CRC16 = 00008959 (hex with correct padding, little endian)
Unless it's in big endian, then it should be
CRC16 = 59890000 (hex with correct padding in big endian)
Logged In: YES
user_id=1201482
Originator: YES
Here's a fix for the padding.
hashmgr.cpp
void CHashOutput::_OutputHashBytes(UWORD8 *pHash, UINTPREF uLen)
{
UINTPREF i;
INTPREF j = 0;
RH_ASSERT(pHash != NULL);
RH_ASSERT(uLen >= 1);
if(m_bBase64 == true)
{
CBase64Codec baseCoder;
UWORD32 i32;
m_szHashBuffer[0] = 0;
i32 = RH_MAX_HASH_STRING;
baseCoder.Encode(pHash, uLen, (UWORD8 *)m_szHashBuffer, &i32);
printf(m_szHashBuffer);
return;
}
m_szBuffer[0] = 0;
#ifdef RH_LITTLE_ENDIAN
if ( m_bPadToFullWord == true )
{
UWORD32 padding = uLen % m_nCombineWords;
while ( padding )
{
strcat( m_szBuffer, "00" );
--padding;
}
}
#endif
for(i = 0; i < uLen; i++)
{
sprintf(m_szByteBuffer, m_szCharCode, pHash[i]);
strcat(m_szBuffer, m_szByteBuffer);
j++;
if(j == m_nCombineWords)
{
j = 0;
if(i != (uLen - 1)) strcat(m_szBuffer, " ");
}
}
#ifdef RH_BIG_ENDIAN
if ( m_bPadToFullWord == true )
{
UWORD32 padding = uLen % m_nCombineWords;
while ( padding )
{
strcat( m_szBuffer, "00" );
--padding;
}
}
#endif
printf(m_szBuffer);
}