Formatting.

This commit is contained in:
Jeff Young 2022-02-17 14:04:51 +00:00
parent 3b072ca8b4
commit ff21a16f7d
1 changed files with 154 additions and 143 deletions

View File

@ -27,13 +27,12 @@
a = b + ROTLEFT(a,s); }
MD5_HASH::MD5_HASH()
{
Init();
}
MD5_HASH::MD5_HASH( const MD5_HASH& aOther )
{
m_valid = aOther.m_valid;
@ -41,9 +40,9 @@ MD5_HASH::MD5_HASH( const MD5_HASH& aOther )
memcpy( m_hash, aOther.m_hash, 16 );
}
MD5_HASH::~MD5_HASH()
{
}
MD5_HASH& MD5_HASH::operator=( const MD5_HASH& aOther )
@ -62,28 +61,32 @@ void MD5_HASH::Init()
md5_init(&m_ctx);
}
void MD5_HASH::Hash( uint8_t *data, uint32_t length )
{
md5_update( &m_ctx, data, length );
}
void MD5_HASH::Hash( int value )
{
md5_update( &m_ctx, (uint8_t*) &value, sizeof(int) );
}
void MD5_HASH::Finalize()
{
md5_final( &m_ctx, m_hash );
m_valid = true;
}
bool MD5_HASH::operator==( const MD5_HASH& aOther ) const
{
return ( memcmp( m_hash, aOther.m_hash, 16 ) == 0 );
}
bool MD5_HASH::operator!=( const MD5_HASH& aOther ) const
{
return ( memcmp( m_hash, aOther.m_hash, 16 ) != 0 );
@ -207,6 +210,7 @@ void MD5_HASH::md5_transform(MD5_CTX *ctx, uint8_t data[])
ctx->state[3] += d;
}
void MD5_HASH::md5_init( MD5_CTX* ctx )
{
ctx->datalen = 0;
@ -218,14 +222,16 @@ void MD5_HASH::md5_init(MD5_CTX *ctx)
ctx->state[3] = 0x10325476;
}
void MD5_HASH::md5_update( MD5_CTX* ctx, uint8_t data[], uint32_t len )
{
uint32_t i;
for (i=0; i < len; ++i) {
for( uint32_t i = 0; i < len; ++i )
{
ctx->data[ctx->datalen] = data[i];
ctx->datalen++;
if (ctx->datalen == 64) {
if( ctx->datalen == 64 )
{
md5_transform( ctx,ctx->data );
DBL_INT_ADD( ctx->bitlen[0], ctx->bitlen[1], 512 );
ctx->datalen = 0;
@ -233,22 +239,26 @@ void MD5_HASH::md5_update(MD5_CTX *ctx, uint8_t data[], uint32_t len)
}
}
void MD5_HASH::md5_final( MD5_CTX *ctx, uint8_t hash[] )
{
uint32_t i;
i = ctx->datalen;
uint32_t i = ctx->datalen;
// Pad whatever data is left in the buffer.
if (ctx->datalen < 56) {
if( ctx->datalen < 56 )
{
ctx->data[i++] = 0x80;
while( i < 56 )
ctx->data[i++] = 0x00;
}
else if (ctx->datalen >= 56) {
else if (ctx->datalen >= 56)
{
ctx->data[i++] = 0x80;
while( i < 64 )
ctx->data[i++] = 0x00;
md5_transform( ctx, ctx->data );
memset( ctx->data, 0, 56 );
}
@ -267,7 +277,8 @@ void MD5_HASH::md5_final(MD5_CTX *ctx, uint8_t hash[])
// Since this implementation uses little endian byte ordering and MD uses big endian,
// reverse all the bytes when copying the final state to the output hash.
for (i=0; i < 4; ++i) {
for( i=0; i < 4; ++i )
{
hash[i] = (ctx->state[0] >> (i*8)) & 0x000000ff;
hash[i+4] = (ctx->state[1] >> (i*8)) & 0x000000ff;
hash[i+8] = (ctx->state[2] >> (i*8)) & 0x000000ff;