traceroute: fix help text to not show -6 when traceroute6 is off
[oweals/busybox.git] / libbb / sha1.c
index a07435919e1e78f5e68aa0bfbca7ac6e11ef8c74..5f42532cd7fa793f9354ca28097b5a19beaebf13 100644 (file)
@@ -53,6 +53,12 @@ static inline uint64_t hton64(uint64_t v)
 #endif
 
 
+/* Some arch headers have conflicting defines */
+#undef ch
+#undef parity
+#undef maj
+#undef rnd
+
 static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx)
 {
        unsigned t;
@@ -162,6 +168,13 @@ static const uint64_t sha_K[80] = {
        0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL
 };
 
+#undef Ch
+#undef Maj
+#undef S0
+#undef S1
+#undef R0
+#undef R1
+
 static void FAST_FUNC sha256_process_block64(sha256_ctx_t *ctx)
 {
        unsigned t;
@@ -196,12 +209,11 @@ static void FAST_FUNC sha256_process_block64(sha256_ctx_t *ctx)
 
        /* The actual computation according to FIPS 180-2:6.2.2 step 3.  */
        for (t = 0; t < 64; ++t) {
-               /* Need to fetch upper half of sha_K[t] */
-#if BB_BIG_ENDIAN
-               uint32_t K_t = ((uint32_t*)(sha_K + t))[0];
-#else
-               uint32_t K_t = ((uint32_t*)(sha_K + t))[1];
-#endif
+               /* Need to fetch upper half of sha_K[t]
+                * (I hope compiler is clever enough to just fetch
+                * upper half)
+                */
+               uint32_t K_t = sha_K[t] >> 32;
                uint32_t T1 = h + S1(e) + Ch(e, f, g) + K_t + W[t];
                uint32_t T2 = S0(a) + Maj(a, b, c);
                h = g;
@@ -396,7 +408,7 @@ void FAST_FUNC sha512_hash(const void *buffer, size_t len, sha512_ctx_t *ctx)
 /* Used also for sha256 */
 void FAST_FUNC sha1_end(void *resbuf, sha1_ctx_t *ctx)
 {
-       unsigned i, pad, in_buf;
+       unsigned pad, in_buf;
 
        in_buf = ctx->total64 & 63;
        /* Pad the buffer to the next 64-byte boundary with 0x80,0,0,0... */
@@ -422,16 +434,17 @@ void FAST_FUNC sha1_end(void *resbuf, sha1_ctx_t *ctx)
 
        in_buf = (ctx->process_block == sha1_process_block64) ? 5 : 8;
        /* This way we do not impose alignment constraints on resbuf: */
-#if BB_LITTLE_ENDIAN
-       for (i = 0; i < in_buf; ++i)
-               ctx->hash[i] = htonl(ctx->hash[i]);
-#endif
+       if (BB_LITTLE_ENDIAN) {
+               unsigned i;
+               for (i = 0; i < in_buf; ++i)
+                       ctx->hash[i] = htonl(ctx->hash[i]);
+       }
        memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * in_buf);
 }
 
 void FAST_FUNC sha512_end(void *resbuf, sha512_ctx_t *ctx)
 {
-       unsigned i, pad, in_buf;
+       unsigned pad, in_buf;
 
        in_buf = ctx->total64[0] & 127;
        /* Pad the buffer to the next 128-byte boundary with 0x80,0,0,0...
@@ -458,9 +471,10 @@ void FAST_FUNC sha512_end(void *resbuf, sha512_ctx_t *ctx)
                        break;
        }
 
-#if BB_LITTLE_ENDIAN
-       for (i = 0; i < ARRAY_SIZE(ctx->hash); ++i)
-               ctx->hash[i] = hton64(ctx->hash[i]);
-#endif
+       if (BB_LITTLE_ENDIAN) {
+               unsigned i;
+               for (i = 0; i < ARRAY_SIZE(ctx->hash); ++i)
+                       ctx->hash[i] = hton64(ctx->hash[i]);
+       }
        memcpy(resbuf, ctx->hash, sizeof(ctx->hash));
 }