OP(D, A, B, C, 12, 0xfd987193);
OP(C, D, A, B, 17, 0xa679438e);
OP(B, C, D, A, 22, 0x49b40821);
-# endif/* MD5_SIZE_VS_SPEED == 1 */
+# endif /* MD5_SIZE_VS_SPEED == 1 */
/* For the second to fourth round we have the possibly swapped words
in CORRECT_WORDS. Redefine the macro to take an additional first
OP(FG, D, A, B, C, 2, 9, 0xfcefa3f8);
OP(FG, C, D, A, B, 7, 14, 0x676f02d9);
OP(FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
-# endif/* MD5_SIZE_VS_SPEED == 1 */
+# endif /* MD5_SIZE_VS_SPEED == 1 */
/* Round 3. */
# if MD5_SIZE_VS_SPEED == 1
OP(FH, D, A, B, C, 12, 11, 0xe6db99e5);
OP(FH, C, D, A, B, 15, 16, 0x1fa27cf8);
OP(FH, B, C, D, A, 2, 23, 0xc4ac5665);
-# endif/* MD5_SIZE_VS_SPEED == 1 */
+# endif /* MD5_SIZE_VS_SPEED == 1 */
/* Round 4. */
# if MD5_SIZE_VS_SPEED == 1
unsigned i = 64 - ctx->buflen;
/* Copy data into aligned buffer. */
- if (i > len) i = len;
+ if (i > len)
+ i = len;
memcpy(ctx->buffer + ctx->buflen, buf, i);
len -= i;
ctx->buflen += i;
* 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.
*/
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);
}