Git fork

Merge branch 'ad/sha1-update-chunked' into maint

Apple's common crypto implementation of SHA1_Update() does not take
more than 4GB at a time, and we now have a compile-time workaround
for it.

* ad/sha1-update-chunked:
sha1: allow limiting the size of the data passed to SHA1_Update()
sha1: provide another level of indirection for the SHA-1 functions

+69 -13
+13
Makefile
··· 144 144 # Define PPC_SHA1 environment variable when running make to make use of 145 145 # a bundled SHA1 routine optimized for PowerPC. 146 146 # 147 + # Define SHA1_MAX_BLOCK_SIZE to limit the amount of data that will be hashed 148 + # in one call to the platform's SHA1_Update(). e.g. APPLE_COMMON_CRYPTO 149 + # wants 'SHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L' defined. 150 + # 147 151 # Define NEEDS_CRYPTO_WITH_SSL if you need -lcrypto when using -lssl (Darwin). 148 152 # 149 153 # Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin). ··· 1340 1344 BASIC_CFLAGS += -DNO_POSIX_GOODIES 1341 1345 endif 1342 1346 1347 + ifdef APPLE_COMMON_CRYPTO 1348 + # Apple CommonCrypto requires chunking 1349 + SHA1_MAX_BLOCK_SIZE = 1024L*1024L*1024L 1350 + endif 1351 + 1343 1352 ifdef BLK_SHA1 1344 1353 SHA1_HEADER = "block-sha1/sha1.h" 1345 1354 LIB_OBJS += block-sha1/sha1.o ··· 1358 1367 endif 1359 1368 endif 1360 1369 1370 + ifdef SHA1_MAX_BLOCK_SIZE 1371 + LIB_OBJS += compat/sha1-chunked.o 1372 + BASIC_CFLAGS += -DSHA1_MAX_BLOCK_SIZE="$(SHA1_MAX_BLOCK_SIZE)" 1373 + endif 1361 1374 ifdef NO_PERL_MAKEMAKER 1362 1375 export NO_PERL_MAKEMAKER 1363 1376 endif
+4 -4
block-sha1/sha1.h
··· 16 16 void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, unsigned long len); 17 17 void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx); 18 18 19 - #define git_SHA_CTX blk_SHA_CTX 20 - #define git_SHA1_Init blk_SHA1_Init 21 - #define git_SHA1_Update blk_SHA1_Update 22 - #define git_SHA1_Final blk_SHA1_Final 19 + #define platform_SHA_CTX blk_SHA_CTX 20 + #define platform_SHA1_Init blk_SHA1_Init 21 + #define platform_SHA1_Update blk_SHA1_Update 22 + #define platform_SHA1_Final blk_SHA1_Final
+23 -5
cache.h
··· 11 11 #include "string-list.h" 12 12 13 13 #include SHA1_HEADER 14 - #ifndef git_SHA_CTX 15 - #define git_SHA_CTX SHA_CTX 16 - #define git_SHA1_Init SHA1_Init 17 - #define git_SHA1_Update SHA1_Update 18 - #define git_SHA1_Final SHA1_Final 14 + #ifndef platform_SHA_CTX 15 + /* 16 + * platform's underlying implementation of SHA-1; could be OpenSSL, 17 + * blk_SHA, Apple CommonCrypto, etc... Note that including 18 + * SHA1_HEADER may have already defined platform_SHA_CTX for our 19 + * own implementations like block-sha1 and ppc-sha1, so we list 20 + * the default for OpenSSL compatible SHA-1 implementations here. 21 + */ 22 + #define platform_SHA_CTX SHA_CTX 23 + #define platform_SHA1_Init SHA1_Init 24 + #define platform_SHA1_Update SHA1_Update 25 + #define platform_SHA1_Final SHA1_Final 26 + #endif 27 + 28 + #define git_SHA_CTX platform_SHA_CTX 29 + #define git_SHA1_Init platform_SHA1_Init 30 + #define git_SHA1_Update platform_SHA1_Update 31 + #define git_SHA1_Final platform_SHA1_Final 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 19 37 #endif 20 38 21 39 #include <zlib.h>
+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);
+4 -4
ppc/sha1.h
··· 19 19 int ppc_SHA1_Update(ppc_SHA_CTX *c, const void *p, unsigned long n); 20 20 int ppc_SHA1_Final(unsigned char *hash, ppc_SHA_CTX *c); 21 21 22 - #define git_SHA_CTX ppc_SHA_CTX 23 - #define git_SHA1_Init ppc_SHA1_Init 24 - #define git_SHA1_Update ppc_SHA1_Update 25 - #define git_SHA1_Final ppc_SHA1_Final 22 + #define platform_SHA_CTX ppc_SHA_CTX 23 + #define platform_SHA1_Init ppc_SHA1_Init 24 + #define platform_SHA1_Update ppc_SHA1_Update 25 + #define platform_SHA1_Final ppc_SHA1_Final