In the md4 code, use a 64-bit counter to avoid a manual carry operation.

This commit is contained in:
Dag-Erling Smørgrav 2014-07-12 22:10:57 +00:00 committed by des
parent 340b3240cf
commit 910c782b2f
2 changed files with 6 additions and 17 deletions

View file

@ -51,7 +51,7 @@ extern digest_algorithm md4_digest;
*/
typedef struct
{
uint32_t total[2]; /*!< number of bytes processed */
uint64_t total; /*!< number of bytes processed */
uint32_t state[4]; /*!< intermediate digest state */
uint8_t buffer[64]; /*!< data block being processed */
}

View file

@ -67,8 +67,7 @@
*/
void md4_init( md4_ctx *ctx )
{
ctx->total[0] = 0;
ctx->total[1] = 0;
ctx->total = 0;
ctx->state[0] = 0x67452301;
ctx->state[1] = 0xEFCDAB89;
@ -190,14 +189,10 @@ void md4_update( md4_ctx *ctx, const void *input, int ilen )
if( ilen <= 0 )
return;
left = ctx->total[0] & 0x3F;
left = ctx->total & 0x3F;
fill = 64 - left;
ctx->total[0] += ilen;
ctx->total[0] &= 0xFFFFFFFF;
if( ctx->total[0] < (uint32_t) ilen )
ctx->total[1]++;
ctx->total += ilen;
if( left && ilen >= fill )
{
@ -235,17 +230,11 @@ static const uint8_t md4_padding[64] =
void md4_final( md4_ctx *ctx, uint8_t *output )
{
uint32_t last, padn;
uint32_t high, low;
uint8_t msglen[8];
high = ( ctx->total[0] >> 29 )
| ( ctx->total[1] << 3 );
low = ( ctx->total[0] << 3 );
le64enc(msglen, ctx->total << 3);
PUT_ULONG_LE( low, msglen, 0 );
PUT_ULONG_LE( high, msglen, 4 );
last = ctx->total[0] & 0x3F;
last = ctx->total & 0x3F;
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
md4_update( ctx, md4_padding, padn );