Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/md5.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-01-06 16:02:52 -0600
committerDan McGee <dan@archlinux.org>2012-01-07 11:27:41 -0600
commitd59324c8fff0a91930bf226d013273691f0580e6 (patch)
treea357aae15d3e0e9d4a9f710edce18d6b3ed27c70 /lib/libalpm/md5.c
parent6513b0ba591e44b4da75aa924046a34b8a269e9d (diff)
Use 32-bit wide integer type in PolarSSL code
A look at what this does on 64 bit systems since we were using the unnecessarily large 'unsigned long' type before even though it was 64 bits wide: $ ~/bin/bloat-o-meter libalpm.so.old lib/libalpm/.libs/libalpm.so add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-10412 (-10412) function old new delta md5_finish 370 356 -14 sha2_finish 547 531 -16 md5_process 3762 2643 -1119 sha2_process 20356 11093 -9263 The code size is nearly halved in the sha2 case (44% smaller code size), and md5 gets a nice size reduction (27% smaller) as well. We also move base64 code to <stdint.h> types as well; we can use 'uint32_t' rather than 'unsigned long' for at least two variables in the decode function. This doesn't net the same size benefit as the hash code case, but it is more proper. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/md5.c')
-rw-r--r--lib/libalpm/md5.c81
1 files changed, 41 insertions, 40 deletions
diff --git a/lib/libalpm/md5.c b/lib/libalpm/md5.c
index b4391a61..0d5ed9e0 100644
--- a/lib/libalpm/md5.c
+++ b/lib/libalpm/md5.c
@@ -33,33 +33,34 @@
* GPL. This is from version 1.0.0 of the library, and has been modified
* as following, which may be helpful for future updates:
* * remove "polarssl/config.h" include
- * * change include from "polarssl/sha2.h" to "sha2.h"
+ * * change include from "polarssl/md5.h" to "md5.h"
* * removal of HMAC code
* * removal of SELF_TEST code
- * * removal of ipad and opad from the md5_context struct in sha2.h
+ * * removal of ipad and opad from the md5_context struct in md5.h
* * increase the size of buffer for performance reasons
- * * various static changes
+ * * change 'unsigned long' to uint32_t
*/
#include <stdio.h>
+#include <stdint.h>
#include "md5.h"
/*
* 32-bit integer manipulation macros (little endian)
*/
-#ifndef GET_ULONG_LE
-#define GET_ULONG_LE(n,b,i) \
+#ifndef GET_U32_LE
+#define GET_U32_LE(n,b,i) \
{ \
- (n) = ( (unsigned long) (b)[(i) ] ) \
- | ( (unsigned long) (b)[(i) + 1] << 8 ) \
- | ( (unsigned long) (b)[(i) + 2] << 16 ) \
- | ( (unsigned long) (b)[(i) + 3] << 24 ); \
+ (n) = ( (uint32_t) (b)[(i) ] ) \
+ | ( (uint32_t) (b)[(i) + 1] << 8 ) \
+ | ( (uint32_t) (b)[(i) + 2] << 16 ) \
+ | ( (uint32_t) (b)[(i) + 3] << 24 ); \
}
#endif
-#ifndef PUT_ULONG_LE
-#define PUT_ULONG_LE(n,b,i) \
+#ifndef PUT_U32_LE
+#define PUT_U32_LE(n,b,i) \
{ \
(b)[(i) ] = (unsigned char) ( (n) ); \
(b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
@@ -84,24 +85,24 @@ static void md5_starts( md5_context *ctx )
static void md5_process( md5_context *ctx, const unsigned char data[64] )
{
- unsigned long X[16], A, B, C, D;
-
- GET_ULONG_LE( X[ 0], data, 0 );
- GET_ULONG_LE( X[ 1], data, 4 );
- GET_ULONG_LE( X[ 2], data, 8 );
- GET_ULONG_LE( X[ 3], data, 12 );
- GET_ULONG_LE( X[ 4], data, 16 );
- GET_ULONG_LE( X[ 5], data, 20 );
- GET_ULONG_LE( X[ 6], data, 24 );
- GET_ULONG_LE( X[ 7], data, 28 );
- GET_ULONG_LE( X[ 8], data, 32 );
- GET_ULONG_LE( X[ 9], data, 36 );
- GET_ULONG_LE( X[10], data, 40 );
- GET_ULONG_LE( X[11], data, 44 );
- GET_ULONG_LE( X[12], data, 48 );
- GET_ULONG_LE( X[13], data, 52 );
- GET_ULONG_LE( X[14], data, 56 );
- GET_ULONG_LE( X[15], data, 60 );
+ uint32_t X[16], A, B, C, D;
+
+ GET_U32_LE( X[ 0], data, 0 );
+ GET_U32_LE( X[ 1], data, 4 );
+ GET_U32_LE( X[ 2], data, 8 );
+ GET_U32_LE( X[ 3], data, 12 );
+ GET_U32_LE( X[ 4], data, 16 );
+ GET_U32_LE( X[ 5], data, 20 );
+ GET_U32_LE( X[ 6], data, 24 );
+ GET_U32_LE( X[ 7], data, 28 );
+ GET_U32_LE( X[ 8], data, 32 );
+ GET_U32_LE( X[ 9], data, 36 );
+ GET_U32_LE( X[10], data, 40 );
+ GET_U32_LE( X[11], data, 44 );
+ GET_U32_LE( X[12], data, 48 );
+ GET_U32_LE( X[13], data, 52 );
+ GET_U32_LE( X[14], data, 56 );
+ GET_U32_LE( X[15], data, 60 );
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
@@ -211,7 +212,7 @@ static void md5_process( md5_context *ctx, const unsigned char data[64] )
static void md5_update( md5_context *ctx, const unsigned char *input, size_t ilen )
{
size_t fill;
- unsigned long left;
+ uint32_t left;
if( ilen <= 0 )
return;
@@ -219,10 +220,10 @@ static void md5_update( md5_context *ctx, const unsigned char *input, size_t ile
left = ctx->total[0] & 0x3F;
fill = 64 - left;
- ctx->total[0] += (unsigned long) ilen;
+ ctx->total[0] += (uint32_t) ilen;
ctx->total[0] &= 0xFFFFFFFF;
- if( ctx->total[0] < (unsigned long) ilen )
+ if( ctx->total[0] < (uint32_t) ilen )
ctx->total[1]++;
if( left && ilen >= fill )
@@ -262,16 +263,16 @@ static const unsigned char md5_padding[64] =
*/
static void md5_finish( md5_context *ctx, unsigned char output[16] )
{
- unsigned long last, padn;
- unsigned long high, low;
+ uint32_t last, padn;
+ uint32_t high, low;
unsigned char msglen[8];
high = ( ctx->total[0] >> 29 )
| ( ctx->total[1] << 3 );
low = ( ctx->total[0] << 3 );
- PUT_ULONG_LE( low, msglen, 0 );
- PUT_ULONG_LE( high, msglen, 4 );
+ PUT_U32_LE( low, msglen, 0 );
+ PUT_U32_LE( high, msglen, 4 );
last = ctx->total[0] & 0x3F;
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
@@ -279,10 +280,10 @@ static void md5_finish( md5_context *ctx, unsigned char output[16] )
md5_update( ctx, (unsigned char *) md5_padding, padn );
md5_update( ctx, msglen, 8 );
- PUT_ULONG_LE( ctx->state[0], output, 0 );
- PUT_ULONG_LE( ctx->state[1], output, 4 );
- PUT_ULONG_LE( ctx->state[2], output, 8 );
- PUT_ULONG_LE( ctx->state[3], output, 12 );
+ PUT_U32_LE( ctx->state[0], output, 0 );
+ PUT_U32_LE( ctx->state[1], output, 4 );
+ PUT_U32_LE( ctx->state[2], output, 8 );
+ PUT_U32_LE( ctx->state[3], output, 12 );
}
/*