mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-12-26 22:41:08 +00:00
In the md4 code, use a 64-bit counter to avoid a manual carry operation.
This commit is contained in:
parent
340b3240cf
commit
910c782b2f
2 changed files with 6 additions and 17 deletions
|
@ -51,7 +51,7 @@ extern digest_algorithm md4_digest;
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t total[2]; /*!< number of bytes processed */
|
uint64_t total; /*!< number of bytes processed */
|
||||||
uint32_t state[4]; /*!< intermediate digest state */
|
uint32_t state[4]; /*!< intermediate digest state */
|
||||||
uint8_t buffer[64]; /*!< data block being processed */
|
uint8_t buffer[64]; /*!< data block being processed */
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,7 @@
|
||||||
*/
|
*/
|
||||||
void md4_init( md4_ctx *ctx )
|
void md4_init( md4_ctx *ctx )
|
||||||
{
|
{
|
||||||
ctx->total[0] = 0;
|
ctx->total = 0;
|
||||||
ctx->total[1] = 0;
|
|
||||||
|
|
||||||
ctx->state[0] = 0x67452301;
|
ctx->state[0] = 0x67452301;
|
||||||
ctx->state[1] = 0xEFCDAB89;
|
ctx->state[1] = 0xEFCDAB89;
|
||||||
|
@ -190,14 +189,10 @@ void md4_update( md4_ctx *ctx, const void *input, int ilen )
|
||||||
if( ilen <= 0 )
|
if( ilen <= 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
left = ctx->total[0] & 0x3F;
|
left = ctx->total & 0x3F;
|
||||||
fill = 64 - left;
|
fill = 64 - left;
|
||||||
|
|
||||||
ctx->total[0] += ilen;
|
ctx->total += ilen;
|
||||||
ctx->total[0] &= 0xFFFFFFFF;
|
|
||||||
|
|
||||||
if( ctx->total[0] < (uint32_t) ilen )
|
|
||||||
ctx->total[1]++;
|
|
||||||
|
|
||||||
if( left && ilen >= fill )
|
if( left && ilen >= fill )
|
||||||
{
|
{
|
||||||
|
@ -235,17 +230,11 @@ static const uint8_t md4_padding[64] =
|
||||||
void md4_final( md4_ctx *ctx, uint8_t *output )
|
void md4_final( md4_ctx *ctx, uint8_t *output )
|
||||||
{
|
{
|
||||||
uint32_t last, padn;
|
uint32_t last, padn;
|
||||||
uint32_t high, low;
|
|
||||||
uint8_t msglen[8];
|
uint8_t msglen[8];
|
||||||
|
|
||||||
high = ( ctx->total[0] >> 29 )
|
le64enc(msglen, ctx->total << 3);
|
||||||
| ( ctx->total[1] << 3 );
|
|
||||||
low = ( ctx->total[0] << 3 );
|
|
||||||
|
|
||||||
PUT_ULONG_LE( low, msglen, 0 );
|
last = ctx->total & 0x3F;
|
||||||
PUT_ULONG_LE( high, msglen, 4 );
|
|
||||||
|
|
||||||
last = ctx->total[0] & 0x3F;
|
|
||||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||||
|
|
||||||
md4_update( ctx, md4_padding, padn );
|
md4_update( ctx, md4_padding, padn );
|
||||||
|
|
Loading…
Reference in a new issue