X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=block-sha1%2Fsha1.c;h=d8934757a5e5e259f26c4a09f7ea5d10615df0c1;hb=af24059fa299f1656692f5807eddd3b30b5f3cfb;hp=464cb258aaa11786d3615a55c0ae8dff95150667;hpb=dad1a454d5411a50dc8a51837cf859f40804b776;p=git.git diff --git a/block-sha1/sha1.c b/block-sha1/sha1.c index 464cb258a..c0054a0b0 100644 --- a/block-sha1/sha1.c +++ b/block-sha1/sha1.c @@ -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 -#include +/* 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)) @@ -68,6 +70,7 @@ */ #if defined(__i386__) || defined(__x86_64__) || \ + defined(_M_IX86) || defined(_M_X64) || \ defined(__ppc__) || defined(__ppc64__) || \ defined(__powerpc__) || defined(__powerpc64__) || \ defined(__s390__) || defined(__s390x__) @@ -234,13 +237,13 @@ void blk_SHA1_Init(blk_SHA_CTX *ctx) void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len) { - int lenW = ctx->size & 63; + unsigned int lenW = ctx->size & 63; ctx->size += len; /* Read the data into W and process blocks as they get full */ if (lenW) { - int left = 64 - lenW; + unsigned int left = 64 - lenW; if (len < left) left = len; memcpy(lenW + (char *)ctx->W, data, left); @@ -267,8 +270,8 @@ void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx) int i; /* Pad with a binary 1 (ie 0x80), then zeroes, then length */ - padlen[0] = htonl(ctx->size >> 29); - padlen[1] = htonl(ctx->size << 3); + padlen[0] = htonl((uint32_t)(ctx->size >> 29)); + padlen[1] = htonl((uint32_t)(ctx->size << 3)); i = ctx->size & 63; blk_SHA1_Update(ctx, pad, 1+ (63 & (55 - i)));