Git fork

sha1: allow limiting the size of the data passed to SHA1_Update()

Using the previous commit's inredirection mechanism for SHA1,
support a chunked implementation of SHA1_Update() that limits the
amount of data in the chunk passed to SHA1_Update().

This is enabled by using the Makefile variable SHA1_MAX_BLOCK_SIZE
to specify chunk size. When using Apple's CommonCrypto library this
is set to 1GiB (the implementation cannot handle more 4GiB).

Signed-off-by: Atousa Pahlevan Duprat <apahlevan@ieee.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Atousa Pahlevan Duprat and committed by
Junio C Hamano
001fd7a9 3bc72fde

+44
+13
Makefile
··· 141 141 # Define PPC_SHA1 environment variable when running make to make use of 142 142 # a bundled SHA1 routine optimized for PowerPC. 143 143 # 144 + # Define SHA1_MAX_BLOCK_SIZE to limit the amount of data that will be hashed 145 + # in one call to the platform's SHA1_Update(). e.g. APPLE_COMMON_CRYPTO 146 + # wants 'SHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L' defined. 147 + # 144 148 # Define NEEDS_CRYPTO_WITH_SSL if you need -lcrypto when using -lssl (Darwin). 145 149 # 146 150 # Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin). ··· 1276 1280 BASIC_CFLAGS += -DNO_POSIX_GOODIES 1277 1281 endif 1278 1282 1283 + ifdef APPLE_COMMON_CRYPTO 1284 + # Apple CommonCrypto requires chunking 1285 + SHA1_MAX_BLOCK_SIZE = 1024L*1024L*1024L 1286 + endif 1287 + 1279 1288 ifdef BLK_SHA1 1280 1289 SHA1_HEADER = "block-sha1/sha1.h" 1281 1290 LIB_OBJS += block-sha1/sha1.o ··· 1294 1303 endif 1295 1304 endif 1296 1305 1306 + ifdef SHA1_MAX_BLOCK_SIZE 1307 + LIB_OBJS += compat/sha1-chunked.o 1308 + BASIC_CFLAGS += -DSHA1_MAX_BLOCK_SIZE="$(SHA1_MAX_BLOCK_SIZE)" 1309 + endif 1297 1310 ifdef NO_PERL_MAKEMAKER 1298 1311 export NO_PERL_MAKEMAKER 1299 1312 endif
+6
cache.h
··· 30 30 #define git_SHA1_Update platform_SHA1_Update 31 31 #define git_SHA1_Final platform_SHA1_Final 32 32 33 + #ifdef SHA1_MAX_BLOCK_SIZE 34 + #include "compat/sha1-chunked.h" 35 + #undef git_SHA1_Update 36 + #define git_SHA1_Update git_SHA1_Update_Chunked 37 + #endif 38 + 33 39 #include <zlib.h> 34 40 typedef struct git_zstream { 35 41 z_stream z;
+4
compat/apple-common-crypto.h
··· 16 16 #undef TYPE_BOOL 17 17 #endif 18 18 19 + #ifndef SHA1_MAX_BLOCK_SIZE 20 + #error Using Apple Common Crypto library requires setting SHA1_MAX_BLOCK_SIZE 21 + #endif 22 + 19 23 #ifdef APPLE_LION_OR_NEWER 20 24 #define git_CC_error_check(pattern, err) \ 21 25 do { \
+19
compat/sha1-chunked.c
··· 1 + #include "cache.h" 2 + 3 + int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len) 4 + { 5 + size_t nr; 6 + size_t total = 0; 7 + const char *cdata = (const char*)data; 8 + 9 + while (len) { 10 + nr = len; 11 + if (nr > SHA1_MAX_BLOCK_SIZE) 12 + nr = SHA1_MAX_BLOCK_SIZE; 13 + platform_SHA1_Update(c, cdata, nr); 14 + total += nr; 15 + cdata += nr; 16 + len -= nr; 17 + } 18 + return total; 19 + }
+2
compat/sha1-chunked.h
··· 1 + 2 + int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len);