Skip to content

Commit 9bb4542

Browse files
peffgitster
authored andcommitted
block-sha1: take a size_t length parameter
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 33bbc59 commit 9bb4542

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

block-sha1/sha1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void blk_SHA1_Init(blk_SHA_CTX *ctx)
203203
ctx->H[4] = 0xc3d2e1f0;
204204
}
205205

206-
void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)
206+
void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, size_t len)
207207
{
208208
unsigned int lenW = ctx->size & 63;
209209

block-sha1/sha1.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ typedef struct {
1313
} blk_SHA_CTX;
1414

1515
void blk_SHA1_Init(blk_SHA_CTX *ctx);
16-
void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, unsigned long len);
16+
void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, size_t len);
1717
void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx);
1818

1919
#define platform_SHA_CTX blk_SHA_CTX

0 commit comments

Comments
 (0)