mirror of
https://github.com/git/git
synced 2024-08-28 20:20:07 +00:00
![Jeff King](/assets/img/avatar_default.png)
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>
23 lines
705 B
C
23 lines
705 B
C
/*
|
|
* 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.
|
|
*/
|
|
|
|
typedef struct {
|
|
unsigned long long size;
|
|
unsigned int H[5];
|
|
unsigned int W[16];
|
|
} blk_SHA_CTX;
|
|
|
|
void blk_SHA1_Init(blk_SHA_CTX *ctx);
|
|
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
|
|
#define platform_SHA1_Init blk_SHA1_Init
|
|
#define platform_SHA1_Update blk_SHA1_Update
|
|
#define platform_SHA1_Final blk_SHA1_Final
|