aboutsummaryrefslogtreecommitdiff
path: root/libbb/md5.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-03-12 15:40:27 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-03-12 15:40:27 +0000
commitcd2cd312b70e53b2095827d84c675b85cef4d2f6 (patch)
treea005300276c4c0943319c70a957474108ac89ef2 /libbb/md5.c
parent6a5d9faa29e5ccf9467d25388dfaabaf0794e7bd (diff)
downloadbusybox-cd2cd312b70e53b2095827d84c675b85cef4d2f6.tar.gz
shrink sha hashing a bit more (remove wbuflen field from ctx),
remove the requirement for aligned buffer function old new delta sha512_hash 262 297 +35 sha1_end 136 143 +7 passwd_main 1019 1023 +4 sha256_end 135 137 +2 count_lines 72 74 +2 sha256_hash 259 260 +1 popstring 164 158 -6 sha512_begin 88 81 -7 sha256_begin 44 37 -7 parse_expr 832 824 -8 bbunpack 446 438 -8 sha256_process_block64 529 520 -9 md5_end 166 151 -15 evaltreenr 817 802 -15 evaltree 817 802 -15 sha512_end 204 182 -22 sha512_process_block128 1444 1405 -39 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 6/11 up/down: 51/-151) Total: -100 bytes
Diffstat (limited to 'libbb/md5.c')
-rw-r--r--libbb/md5.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/libbb/md5.c b/libbb/md5.c
index eb15d758d..768dfbcb7 100644
--- a/libbb/md5.c
+++ b/libbb/md5.c
@@ -416,15 +416,14 @@ void FAST_FUNC md5_end(void *resbuf, md5_ctx_t *ctx)
md5_hash_block(ctx->buffer, ctx);
md5_hash_block(buf, ctx);
- /* Put result from CTX in first 16 bytes following RESBUF. The result is
- * always in little endian byte order, so that a byte-wise output yields
- * to the wanted ASCII representation of the message digest.
- *
- * IMPORTANT: On some systems it is required that RESBUF is correctly
- * aligned for a 32 bits value.
+ /* The MD5 result is in little endian byte order.
+ * We (ab)use the fact that A-D are consecutive in memory.
*/
- ((uint32_t *) resbuf)[0] = SWAP_LE32(ctx->A);
- ((uint32_t *) resbuf)[1] = SWAP_LE32(ctx->B);
- ((uint32_t *) resbuf)[2] = SWAP_LE32(ctx->C);
- ((uint32_t *) resbuf)[3] = SWAP_LE32(ctx->D);
+#if BB_BIG_ENDIAN
+ ctx->A = SWAP_LE32(ctx->A);
+ ctx->B = SWAP_LE32(ctx->B);
+ ctx->C = SWAP_LE32(ctx->C);
+ ctx->D = SWAP_LE32(ctx->D);
+#endif
+ memcpy(resbuf, &ctx->A, sizeof(ctx->A) * 4);
}