Commit bdb54214 by Edward Thomson

hash: commoncrypto hash should support large files

Teach the CommonCrypto hash mechanisms to support large files.  The hash
primitives take a `CC_LONG` (aka `uint32_t`) at a time.  So loop to give
the hash function at most an unsigned 32 bit's worth of bytes until we
have hashed the entire file.
parent a89560d5
...@@ -16,6 +16,8 @@ struct git_hash_ctx { ...@@ -16,6 +16,8 @@ struct git_hash_ctx {
CC_SHA1_CTX c; CC_SHA1_CTX c;
}; };
#define CC_LONG_MAX ((CC_LONG)-1)
#define git_hash_global_init() 0 #define git_hash_global_init() 0
#define git_hash_ctx_init(ctx) git_hash_init(ctx) #define git_hash_ctx_init(ctx) git_hash_init(ctx)
#define git_hash_ctx_cleanup(ctx) #define git_hash_ctx_cleanup(ctx)
...@@ -27,10 +29,21 @@ GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx) ...@@ -27,10 +29,21 @@ GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx)
return 0; return 0;
} }
GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *data, size_t len) GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *_data, size_t len)
{ {
const unsigned char *data = _data;
assert(ctx); assert(ctx);
CC_SHA1_Update(&ctx->c, data, len);
while (len > 0) {
CC_LONG chunk = (len > CC_LONG_MAX) ? CC_LONG_MAX : (CC_LONG)len;
CC_SHA1_Update(&ctx->c, data, chunk);
data += chunk;
len -= chunk;
}
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment