From 905a3ff4a5d70a00d9ba7819b9f43ad9ce0654e6 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 14 Oct 2014 17:22:51 +0200 Subject: Small code size optimization for RIPEMD-160 when compiled for boot encryption. --- src/Crypto/Rmd160.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/Crypto/Rmd160.c') diff --git a/src/Crypto/Rmd160.c b/src/Crypto/Rmd160.c index 7441dd7d..05285c0a 100644 --- a/src/Crypto/Rmd160.c +++ b/src/Crypto/Rmd160.c @@ -68,17 +68,18 @@ void RMD160Init (RMD160_CTX *ctx) void RMD160Update (RMD160_CTX *ctx, const unsigned char *input, unsigned __int32 lenArg) { #ifndef TC_WINDOWS_BOOT - uint64 len = lenArg, have, need; + uint64 len = lenArg; #else - uint32 len = lenArg, have, need; + uint32 len = lenArg; #endif + unsigned int have, need; /* Check how many bytes we already have and how many more we need. */ - have = ((ctx->count >> 3) & (RIPEMD160_BLOCK_LENGTH - 1)); + have = (unsigned int) ((ctx->count) & (RIPEMD160_BLOCK_LENGTH - 1)); need = RIPEMD160_BLOCK_LENGTH - have; /* Update bitcount */ - ctx->count += len << 3; + ctx->count += len; if (len >= need) { if (have != 0) { @@ -114,15 +115,16 @@ static void RMD160Pad(RMD160_CTX *ctx) /* Convert count to 8 bytes in little endian order. */ #ifndef TC_WINDOWS_BOOT - PUT_64BIT_LE(count, ctx->count); + uint64 bitcount = ctx->count << 3; + PUT_64BIT_LE(count, bitcount); #else *(uint32 *) (count + 4) = 0; - *(uint32 *) (count + 0) = ctx->count; + *(uint32 *) (count + 0) = ctx->count << 3; #endif /* Pad out to 56 mod 64. */ padlen = RIPEMD160_BLOCK_LENGTH - - (uint32)((ctx->count >> 3) & (RIPEMD160_BLOCK_LENGTH - 1)); + (uint32)((ctx->count) & (RIPEMD160_BLOCK_LENGTH - 1)); if (padlen < 1 + 8) padlen += RIPEMD160_BLOCK_LENGTH; RMD160Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */ -- cgit v1.2.3