]> asedeno.scripts.mit.edu Git - git.git/blobdiff - block-sha1/sha1.c
Merge branch 'jh/maint-config-file-prefix' into maint
[git.git] / block-sha1 / sha1.c
index d3121f7a021b878e8232795d661c2907b045b6bc..d8934757a5e5e259f26c4a09f7ea5d10615df0c1 100644 (file)
@@ -1,15 +1,17 @@
 /*
- * Based on the Mozilla SHA1 (see mozilla-sha1/sha1.c),
- * optimized to do word accesses rather than byte accesses,
+ * SHA1 routine optimized to do word accesses rather than byte accesses,
  * and to avoid unnecessary copies into the context array.
+ *
+ * This was initially based on the Mozilla SHA1 implementation, although
+ * none of the original Mozilla code remains.
  */
 
-#include <string.h>
-#include <arpa/inet.h>
+/* this is only to get definitions for memcpy(), ntohl() and htonl() */
+#include "../git-compat-util.h"
 
 #include "sha1.h"
 
-#if defined(__i386__) || defined(__x86_64__)
+#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
 
 /*
  * Force usage of rol or ror by selecting the one with the smaller constant.
@@ -54,7 +56,7 @@
 
 #if defined(__i386__) || defined(__x86_64__)
   #define setW(x, val) (*(volatile unsigned int *)&W(x) = (val))
-#elif defined(__arm__)
+#elif defined(__GNUC__) && defined(__arm__)
   #define setW(x, val) do { W(x) = (val); __asm__("":::"memory"); } while (0)
 #else
   #define setW(x, val) (W(x) = (val))
  * and is faster on architectures with memory alignment issues.
  */
 
-#if defined(__i386__) || defined(__x86_64__)
+#if defined(__i386__) || defined(__x86_64__) || \
+    defined(__ppc__) || defined(__ppc64__) || \
+    defined(__powerpc__) || defined(__powerpc64__) || \
+    defined(__s390__) || defined(__s390x__)
 
 #define get_be32(p)    ntohl(*(unsigned int *)(p))
 #define put_be32(p, v) do { *(unsigned int *)(p) = htonl(v); } while (0)
@@ -243,14 +248,14 @@ void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)
                memcpy(lenW + (char *)ctx->W, data, left);
                lenW = (lenW + left) & 63;
                len -= left;
-               data += left;
+               data = ((const char *)data + left);
                if (lenW)
                        return;
                blk_SHA1_Block(ctx, ctx->W);
        }
        while (len >= 64) {
                blk_SHA1_Block(ctx, data);
-               data += 64;
+               data = ((const char *)data + 64);
                len -= 64;
        }
        if (len)