hush: move msh/lash config into hush.c, no code changes
[oweals/busybox.git] / libbb / md5.c
index eb15d758d24bab4c4bb728976c9d92f620b27edd..a98631d0cae11e27ddd7722d465623f4d750de1a 100644 (file)
@@ -247,7 +247,7 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
        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
@@ -286,7 +286,7 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
        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
@@ -313,7 +313,7 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
        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
@@ -373,7 +373,8 @@ void FAST_FUNC md5_hash(const void *buffer, size_t len, md5_ctx_t *ctx)
                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;
@@ -391,9 +392,6 @@ void FAST_FUNC md5_hash(const void *buffer, size_t len, md5_ctx_t *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.
  */
 void FAST_FUNC md5_end(void *resbuf, md5_ctx_t *ctx)
 {
@@ -416,15 +414,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);
 }