diff options
Diffstat (limited to 'libbb/md5.c')
-rw-r--r-- | libbb/md5.c | 19 |
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) | |||
416 | md5_hash_block(ctx->buffer, ctx); | 416 | md5_hash_block(ctx->buffer, ctx); |
417 | md5_hash_block(buf, ctx); | 417 | md5_hash_block(buf, ctx); |
418 | 418 | ||
419 | /* Put result from CTX in first 16 bytes following RESBUF. The result is | 419 | /* The MD5 result is in little endian byte order. |
420 | * always in little endian byte order, so that a byte-wise output yields | 420 | * We (ab)use the fact that A-D are consecutive in memory. |
421 | * to the wanted ASCII representation of the message digest. | ||
422 | * | ||
423 | * IMPORTANT: On some systems it is required that RESBUF is correctly | ||
424 | * aligned for a 32 bits value. | ||
425 | */ | 421 | */ |
426 | ((uint32_t *) resbuf)[0] = SWAP_LE32(ctx->A); | 422 | #if BB_BIG_ENDIAN |
427 | ((uint32_t *) resbuf)[1] = SWAP_LE32(ctx->B); | 423 | ctx->A = SWAP_LE32(ctx->A); |
428 | ((uint32_t *) resbuf)[2] = SWAP_LE32(ctx->C); | 424 | ctx->B = SWAP_LE32(ctx->B); |
429 | ((uint32_t *) resbuf)[3] = SWAP_LE32(ctx->D); | 425 | ctx->C = SWAP_LE32(ctx->C); |
426 | ctx->D = SWAP_LE32(ctx->D); | ||
427 | #endif | ||
428 | memcpy(resbuf, &ctx->A, sizeof(ctx->A) * 4); | ||
430 | } | 429 | } |