]> git.ipfire.org Git - thirdparty/git.git/commitdiff
block-sha1: take a size_t length parameter
authorJeff King <peff@peff.net>
Fri, 13 Nov 2020 05:07:17 +0000 (00:07 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Nov 2020 21:41:35 +0000 (13:41 -0800)
The block-sha1 implementation takes an "unsigned long" for the length of
a buffer to hash, but our hash algorithm wrappers take a size_t, as do
other implementations we support like openssl or sha1dc. On many
systems, including Linux, these two are equivalent, but they are not on
Windows (where only a "long long" is 64 bits). As a result, passing
large chunks to a single the_hash_algo->update_fn() would produce wrong
answers there.

Note that we don't need to update any other sizes outside of the
function interface. We store the cumulative size in a "long long" (which
we must do since we hash things bigger than 4GB, like packfiles, even on
32-bit platforms). And internally, we break that size_t len down into
64-byte blocks to feed into the guts of the algorithm.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
block-sha1/sha1.c
block-sha1/sha1.h

index 22b125cf8c122e3a1716f34778fa5595454fe76a..8681031402fb93c0e1d5a865041f6f9a924363c6 100644 (file)
@@ -203,7 +203,7 @@ void blk_SHA1_Init(blk_SHA_CTX *ctx)
        ctx->H[4] = 0xc3d2e1f0;
 }
 
-void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)
+void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, size_t len)
 {
        unsigned int lenW = ctx->size & 63;
 
index 4df67477526a2891f7dcdac71ea7bffa75120a67..9fb0441b98849e14e589d7a1b436e3338ae4688d 100644 (file)
@@ -13,7 +13,7 @@ typedef struct {
 } blk_SHA_CTX;
 
 void blk_SHA1_Init(blk_SHA_CTX *ctx);
-void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, unsigned long len);
+void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, size_t len);
 void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx);
 
 #define platform_SHA_CTX       blk_SHA_CTX