[PATCH v1] git rev-list doesn't complain when repo is empty
From: Atousa Pahlevan DupratSigned-off-by: Atousa Pahlevan Duprat --- builtin/rev-list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/rev-list.c b/builtin/rev-list.c index d80d1ed..f71b87f 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -348,7 +348,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) && !revs.pending.nr)) || revs.diff) - usage(rev_list_usage); + return 0; // empty repo if (revs.show_notes) die(_("rev-list does not support display of notes")); -- 2.4.9 (Apple Git-60) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v4 3/3] Move all the SHA1 implementations into one directory
From: Atousa Pahlevan DupratThe various SHA1 implementations were spread around in 3 directories. This makes it easier to understand what implementations are available at a glance. Signed-off-by: Atousa Pahlevan Duprat --- Makefile | 10 +- block-sha1/sha1.c | 251 -- block-sha1/sha1.h | 22 - cache.h | 2 +- compat/sha1-chunked.c | 19 compat/sha1-chunked.h | 2 - ppc/sha1.c| 72 --- ppc/sha1.h| 25 - ppc/sha1ppc.S | 224 sha1/blk-sha1.c | 251 ++ sha1/blk-sha1.h | 22 + sha1/chk-sha1.c | 19 sha1/chk-sha1.h | 2 + sha1/ppc-sha1.c | 72 +++ sha1/ppc-sha1.h | 25 + sha1/ppc-sha1asm.S| 224 16 files changed, 621 insertions(+), 621 deletions(-) delete mode 100644 block-sha1/sha1.c delete mode 100644 block-sha1/sha1.h delete mode 100644 compat/sha1-chunked.c delete mode 100644 compat/sha1-chunked.h delete mode 100644 ppc/sha1.c delete mode 100644 ppc/sha1.h delete mode 100644 ppc/sha1ppc.S create mode 100644 sha1/blk-sha1.c create mode 100644 sha1/blk-sha1.h create mode 100644 sha1/chk-sha1.c create mode 100644 sha1/chk-sha1.h create mode 100644 sha1/ppc-sha1.c create mode 100644 sha1/ppc-sha1.h create mode 100644 sha1/ppc-sha1asm.S diff --git a/Makefile b/Makefile index 6a4ca59..94f74d7 100644 --- a/Makefile +++ b/Makefile @@ -1345,12 +1345,12 @@ ifdef APPLE_COMMON_CRYPTO endif ifdef BLK_SHA1 - SHA1_HEADER = "block-sha1/sha1.h" - LIB_OBJS += block-sha1/sha1.o + SHA1_HEADER = "sha1/blk-sha1.h" + LIB_OBJS += sha1/blk-sha1.o else ifdef PPC_SHA1 - SHA1_HEADER = "ppc/sha1.h" - LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o + SHA1_HEADER = "sha1/ppc-sha1.h" + LIB_OBJS += sha1/ppc-sha1.o sha1/ppc-sha1asm.o else ifdef APPLE_COMMON_CRYPTO COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL @@ -1363,7 +1363,7 @@ endif endif ifdef SHA1_MAX_BLOCK_SIZE - LIB_OBJS += compat/sha1-chunked.o + LIB_OBJS += sha1/chk-sha1.o BASIC_CFLAGS += -DSHA1_MAX_BLOCK_SIZE="$(SHA1_MAX_BLOCK_SIZE)" endif ifdef NO_PERL_MAKEMAKER diff --git a/block-sha1/sha1.c b/block-sha1/sha1.c deleted file mode 100644 index 22b125c..000 --- a/block-sha1/sha1.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * 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. - */ - -/* this is only to get definitions for memcpy(), ntohl() and htonl() */ -#include "../git-compat-util.h" - -#include "sha1.h" - -#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) - -/* - * Force usage of rol or ror by selecting the one with the smaller constant. - * It _can_ generate slightly smaller code (a constant of 1 is special), but - * perhaps more importantly it's possibly faster on any uarch that does a - * rotate with a loop. - */ - -#define SHA_ASM(op, x, n) ({ unsigned int __res; __asm__(op " %1,%0":"=r" (__res):"i" (n), "0" (x)); __res; }) -#define SHA_ROL(x,n) SHA_ASM("rol", x, n) -#define SHA_ROR(x,n) SHA_ASM("ror", x, n) - -#else - -#define SHA_ROT(X,l,r) (((X) << (l)) | ((X) >> (r))) -#define SHA_ROL(X,n) SHA_ROT(X,n,32-(n)) -#define SHA_ROR(X,n) SHA_ROT(X,32-(n),n) - -#endif - -/* - * If you have 32 registers or more, the compiler can (and should) - * try to change the array[] accesses into registers. However, on - * machines with less than ~25 registers, that won't really work, - * and at least gcc will make an unholy mess of it. - * - * So to avoid that mess which just slows things down, we force - * the stores to memory to actually happen (we might be better off - * with a 'W(t)=(val);asm("":"+m" (W(t))' there instead, as - * suggested by Artur Skawina - that will also make gcc unable to - * try to do the silly "optimize away loads" part because it won't - * see what the value will be). - * - * Ben Herrenschmidt reports that on PPC, the C version comes close - * to the optimized asm with this (ie on PPC you don't want that - * 'volatile', since there are lots of registers). - * - * On ARM we get the best code generation by forcing a full memory barrier - * between each SHA_ROUND, otherwise gcc happily get wild with spilling and - * the stack frame size simply explode and performance goes down the drain. - */ - -#if defined(__i386__) || defined(__x86_64__) - #define setW(x, val) (*(volatile unsigned int *)(x) = (val)) -#elif defined(__GNUC__) && defined(__arm__) - #define setW(x, val) do { W(x) = (val); __asm__("":::"memory"); } while (0) -#else - #define setW(x,
[PATCH v4 1/3] Provide another level of abstraction for the SHA1 utilities.
From: Atousa Pahlevan DupratThe git source uses git_SHA1_Update() and friends to call into the code that computes the hashes. This is can then be mapped directly to an implementation that computes the hash, such as platform_SHA1_Update(); or as we will do in a subsequent patch, it can be mapped to something more complex that will in turn call into the platform's SHA implementation. Signed-off-by: Atousa Pahlevan Duprat --- cache.h | 19 +++ 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cache.h b/cache.h index a9aaa03..a934a2e 100644 --- a/cache.h +++ b/cache.h @@ -12,10 +12,21 @@ #include SHA1_HEADER #ifndef git_SHA_CTX -#define git_SHA_CTXSHA_CTX -#define git_SHA1_Init SHA1_Init -#define git_SHA1_UpdateSHA1_Update -#define git_SHA1_Final SHA1_Final + +/* platform's underlying implementation of SHA1, could be OpenSSL, + blk_SHA, Apple CommonCrypto, etc... */ +#define platform_SHA_CTX SHA_CTX +#define platform_SHA1_Init SHA1_Init +#define platform_SHA1_Update SHA1_Update +#define platform_SHA1_FinalSHA1_Final + +/* git may call platform's underlying implementation of SHA1 directly, + or may call it through a wrapper */ +#define git_SHA_CTXplatform_SHA_CTX +#define git_SHA1_Init platform_SHA1_Init +#define git_SHA1_Updateplatform_SHA1_Update +#define git_SHA1_Final platform_SHA1_Final + #endif #include -- 2.4.9 (Apple Git-60) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v4 2/3] Limit the size of the data block passed to SHA1_Update()
From: Atousa Pahlevan DupratUse the previous commit's abstraction mechanism for SHA1 to support a chunked implementation of SHA1_Update() which limits the amount of data in the chunk passed to SHA1_Update(). This is enabled by using the SHA1_MAX_BLOCK_SIZE envvar to specify chunk size. When using Apple's CommonCrypto library this is enable and set to 1GiB. Signed-off-by: Atousa Pahlevan Duprat --- Makefile | 13 + cache.h | 17 +++-- compat/apple-common-crypto.h | 4 compat/sha1-chunked.c| 19 +++ compat/sha1-chunked.h| 2 ++ 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 compat/sha1-chunked.c create mode 100644 compat/sha1-chunked.h diff --git a/Makefile b/Makefile index 04c2231..6a4ca59 100644 --- a/Makefile +++ b/Makefile @@ -141,6 +141,10 @@ all:: # Define PPC_SHA1 environment variable when running make to make use of # a bundled SHA1 routine optimized for PowerPC. # +# Define SHA1_MAX_BLOCK_SIZE to limit the amount of data that will be hashed +# in one call to the platform's SHA1_Update(). e.g. APPLE_COMMON_CRYPTO +# wants 'SHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L' defined. +# # Define NEEDS_CRYPTO_WITH_SSL if you need -lcrypto when using -lssl (Darwin). # # Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin). @@ -1335,6 +1339,11 @@ ifdef NO_POSIX_GOODIES BASIC_CFLAGS += -DNO_POSIX_GOODIES endif +ifdef APPLE_COMMON_CRYPTO + # Apple CommonCrypto requires chunking + SHA1_MAX_BLOCK_SIZE = 1024L*1024L*1024L +endif + ifdef BLK_SHA1 SHA1_HEADER = "block-sha1/sha1.h" LIB_OBJS += block-sha1/sha1.o @@ -1353,6 +1362,10 @@ endif endif endif +ifdef SHA1_MAX_BLOCK_SIZE + LIB_OBJS += compat/sha1-chunked.o + BASIC_CFLAGS += -DSHA1_MAX_BLOCK_SIZE="$(SHA1_MAX_BLOCK_SIZE)" +endif ifdef NO_PERL_MAKEMAKER export NO_PERL_MAKEMAKER endif diff --git a/cache.h b/cache.h index a934a2e..182ac62 100644 --- a/cache.h +++ b/cache.h @@ -11,7 +11,7 @@ #include "string-list.h" #include SHA1_HEADER -#ifndef git_SHA_CTX +#ifndef platform_SHA_CTX /* platform's underlying implementation of SHA1, could be OpenSSL, blk_SHA, Apple CommonCrypto, etc... */ @@ -20,15 +20,28 @@ #define platform_SHA1_Update SHA1_Update #define platform_SHA1_FinalSHA1_Final +#endif + /* git may call platform's underlying implementation of SHA1 directly, or may call it through a wrapper */ + +#ifndef git_SHA_CTX + +#ifdef SHA1_MAX_BLOCK_SIZE +#include "compat/sha1-chunked.h" +#define git_SHA_CTXplatform_SHA_CTX +#define git_SHA1_Init platform_SHA1_Init +#define git_SHA1_Updategit_SHA1_Update_Chunked +#define git_SHA1_Final platform_SHA1_Final +#else #define git_SHA_CTXplatform_SHA_CTX #define git_SHA1_Init platform_SHA1_Init #define git_SHA1_Updateplatform_SHA1_Update #define git_SHA1_Final platform_SHA1_Final - #endif +#endif + #include typedef struct git_zstream { z_stream z; diff --git a/compat/apple-common-crypto.h b/compat/apple-common-crypto.h index c8b9b0e..d3fb264 100644 --- a/compat/apple-common-crypto.h +++ b/compat/apple-common-crypto.h @@ -16,6 +16,10 @@ #undef TYPE_BOOL #endif +#ifndef SHA1_MAX_BLOCK_SIZE +#error Using Apple Common Crypto library requires setting SHA1_MAX_BLOCK_SIZE +#endif + #ifdef APPLE_LION_OR_NEWER #define git_CC_error_check(pattern, err) \ do { \ diff --git a/compat/sha1-chunked.c b/compat/sha1-chunked.c new file mode 100644 index 000..6adfcfd --- /dev/null +++ b/compat/sha1-chunked.c @@ -0,0 +1,19 @@ +#include "cache.h" + +int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len) +{ + size_t nr; + size_t total = 0; + const char *cdata = (const char*)data; + + while (len) { + nr = len; + if (nr > SHA1_MAX_BLOCK_SIZE) + nr = SHA1_MAX_BLOCK_SIZE; + platform_SHA1_Update(c, cdata, nr); + total += nr; + cdata += nr; + len -= nr; + } + return total; +} diff --git a/compat/sha1-chunked.h b/compat/sha1-chunked.h new file mode 100644 index 000..7b2df28 --- /dev/null +++ b/compat/sha1-chunked.h @@ -0,0 +1,2 @@ + +int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len); -- 2.4.9 (Apple Git-60) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] Limit the size of the data block passed to SHA1_Update()
From: Atousa Pahlevan DupratSome implementations of SHA_Updates have inherent limits on the max chunk size. SHA1_MAX_BLOCK_SIZE can be defined to set the max chunk size supported, if required. This is enabled for OSX CommonCrypto library and set to 1GiB. Signed-off-by: Atousa Pahlevan Duprat --- Makefile | 16 +++- block-sha1/sha1.h| 2 +- cache.h | 17 + compat/apple-common-crypto.h | 4 compat/sha1_chunked.c| 19 +++ 5 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 compat/sha1_chunked.c diff --git a/Makefile b/Makefile index 04c2231..1b098cc 100644 --- a/Makefile +++ b/Makefile @@ -136,11 +136,15 @@ all:: # to provide your own OpenSSL library, for example from MacPorts. # # Define BLK_SHA1 environment variable to make use of the bundled -# optimized C SHA1 routine. +# optimized C SHA1 routine. This implies NO_APPLE_COMMON_CRYPTO. # # Define PPC_SHA1 environment variable when running make to make use of # a bundled SHA1 routine optimized for PowerPC. # +# Define SHA1_MAX_BLOCK_SIZE if your SSH1_Update() implementation can +# hash only a limited amount of data in one call (e.g. APPLE_COMMON_CRYPTO +# may want 'SHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L' defined). +# # Define NEEDS_CRYPTO_WITH_SSL if you need -lcrypto when using -lssl (Darwin). # # Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin). @@ -986,6 +990,10 @@ ifeq (no,$(USE_PARENS_AROUND_GETTEXT_N)) endif endif +ifdef BLK_SHA1 + NO_APPLE_COMMON_CRYPTO=1 +endif + ifeq ($(uname_S),Darwin) ifndef NO_FINK ifeq ($(shell test -d /sw/lib && echo y),y) @@ -1346,6 +1354,8 @@ else ifdef APPLE_COMMON_CRYPTO COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL SHA1_HEADER = + # Apple CommonCrypto requires chunking + SHA1_MAX_BLOCK_SIZE = 1024L*1024L*1024L else SHA1_HEADER = EXTLIBS += $(LIB_4_CRYPTO) @@ -1353,6 +1363,10 @@ endif endif endif +ifdef SHA1_MAX_BLOCK_SIZE + LIB_OBJS += compat/sha1_chunked.o + BASIC_CFLAGS += -DSHA1_MAX_BLOCK_SIZE="$(SHA1_MAX_BLOCK_SIZE)" +endif ifdef NO_PERL_MAKEMAKER export NO_PERL_MAKEMAKER endif diff --git a/block-sha1/sha1.h b/block-sha1/sha1.h index b864df6..d085412 100644 --- a/block-sha1/sha1.h +++ b/block-sha1/sha1.h @@ -18,5 +18,5 @@ void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx); #define git_SHA_CTXblk_SHA_CTX #define git_SHA1_Init blk_SHA1_Init -#define git_SHA1_Updateblk_SHA1_Update +#define platform_SHA1_Update blk_SHA1_Update #define git_SHA1_Final blk_SHA1_Final diff --git a/cache.h b/cache.h index 79066e5..e345e38 100644 --- a/cache.h +++ b/cache.h @@ -10,12 +10,21 @@ #include "trace.h" #include "string-list.h" +/* platform's underlying implementation of SHA1 */ #include SHA1_HEADER #ifndef git_SHA_CTX -#define git_SHA_CTXSHA_CTX -#define git_SHA1_Init SHA1_Init -#define git_SHA1_UpdateSHA1_Update -#define git_SHA1_Final SHA1_Final +#define git_SHA_CTXSHA_CTX +#define git_SHA1_Init SHA1_Init +#define platform_SHA1_Update SHA1_Update +#define git_SHA1_Final SHA1_Final +#endif + +/* choose chunked implementation or not */ +#ifdef SHA1_MAX_BLOCK_SIZE +int git_SHA1_Update_Chunked(SHA_CTX *c, const void *data, size_t len); +#define git_SHA1_Update git_SHA1_Update_Chunked +#else +#define git_SHA1_Update platform_SHA1_Update #endif #include diff --git a/compat/apple-common-crypto.h b/compat/apple-common-crypto.h index c8b9b0e..d3fb264 100644 --- a/compat/apple-common-crypto.h +++ b/compat/apple-common-crypto.h @@ -16,6 +16,10 @@ #undef TYPE_BOOL #endif +#ifndef SHA1_MAX_BLOCK_SIZE +#error Using Apple Common Crypto library requires setting SHA1_MAX_BLOCK_SIZE +#endif + #ifdef APPLE_LION_OR_NEWER #define git_CC_error_check(pattern, err) \ do { \ diff --git a/compat/sha1_chunked.c b/compat/sha1_chunked.c new file mode 100644 index 000..6d0062b --- /dev/null +++ b/compat/sha1_chunked.c @@ -0,0 +1,19 @@ +#include "cache.h" + +int git_SHA1_Update_Chunked(SHA_CTX *c, const void *data, size_t len) +{ + size_t nr; + size_t total = 0; + const char *cdata = (const char*)data; + + while (len) { + nr = len; + if (nr > SHA1_MAX_BLOCK_SIZE) + nr = SHA1_MAX_BLOCK_SIZE; + platform_SHA1_Update(c, cdata, nr); + total += nr; + cdata += nr; + len -= nr; + } + return total; +} -- 2.4.9 (Apple Git-60) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/2] Limit the size of the data block passed to SHA1_Update()
From: Atousa Pahlevan DupratSome implementations of SHA_Updates have inherent limits on the max chunk size. SHA1_MAX_BLOCK_SIZE can be defined to set the max chunk size supported, if required. This is enabled for OSX CommonCrypto library and set to 1GiB. Signed-off-by: Atousa Pahlevan Duprat --- Makefile | 16 +++- block-sha1/sha1.h| 2 +- cache.h | 17 + compat/apple-common-crypto.h | 4 compat/sha1_chunked.c| 19 +++ 5 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 compat/sha1_chunked.c diff --git a/Makefile b/Makefile index 04c2231..1b098cc 100644 --- a/Makefile +++ b/Makefile @@ -136,11 +136,15 @@ all:: # to provide your own OpenSSL library, for example from MacPorts. # # Define BLK_SHA1 environment variable to make use of the bundled -# optimized C SHA1 routine. +# optimized C SHA1 routine. This implies NO_APPLE_COMMON_CRYPTO. # # Define PPC_SHA1 environment variable when running make to make use of # a bundled SHA1 routine optimized for PowerPC. # +# Define SHA1_MAX_BLOCK_SIZE if your SSH1_Update() implementation can +# hash only a limited amount of data in one call (e.g. APPLE_COMMON_CRYPTO +# may want 'SHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L' defined). +# # Define NEEDS_CRYPTO_WITH_SSL if you need -lcrypto when using -lssl (Darwin). # # Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin). @@ -986,6 +990,10 @@ ifeq (no,$(USE_PARENS_AROUND_GETTEXT_N)) endif endif +ifdef BLK_SHA1 + NO_APPLE_COMMON_CRYPTO=1 +endif + ifeq ($(uname_S),Darwin) ifndef NO_FINK ifeq ($(shell test -d /sw/lib && echo y),y) @@ -1346,6 +1354,8 @@ else ifdef APPLE_COMMON_CRYPTO COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL SHA1_HEADER = + # Apple CommonCrypto requires chunking + SHA1_MAX_BLOCK_SIZE = 1024L*1024L*1024L else SHA1_HEADER = EXTLIBS += $(LIB_4_CRYPTO) @@ -1353,6 +1363,10 @@ endif endif endif +ifdef SHA1_MAX_BLOCK_SIZE + LIB_OBJS += compat/sha1_chunked.o + BASIC_CFLAGS += -DSHA1_MAX_BLOCK_SIZE="$(SHA1_MAX_BLOCK_SIZE)" +endif ifdef NO_PERL_MAKEMAKER export NO_PERL_MAKEMAKER endif diff --git a/block-sha1/sha1.h b/block-sha1/sha1.h index b864df6..d085412 100644 --- a/block-sha1/sha1.h +++ b/block-sha1/sha1.h @@ -18,5 +18,5 @@ void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx); #define git_SHA_CTXblk_SHA_CTX #define git_SHA1_Init blk_SHA1_Init -#define git_SHA1_Updateblk_SHA1_Update +#define platform_SHA1_Update blk_SHA1_Update #define git_SHA1_Final blk_SHA1_Final diff --git a/cache.h b/cache.h index 79066e5..a501652 100644 --- a/cache.h +++ b/cache.h @@ -10,12 +10,21 @@ #include "trace.h" #include "string-list.h" +// platform's underlying implementation of SHA1 #include SHA1_HEADER #ifndef git_SHA_CTX -#define git_SHA_CTXSHA_CTX -#define git_SHA1_Init SHA1_Init -#define git_SHA1_UpdateSHA1_Update -#define git_SHA1_Final SHA1_Final +#define git_SHA_CTXSHA_CTX +#define git_SHA1_Init SHA1_Init +#define platform_SHA1_Update SHA1_Update +#define git_SHA1_Final SHA1_Final +#endif + +// choose whether chunked implementation or not +#ifdef SHA1_MAX_BLOCK_SIZE +int git_SHA1_Update_Chunked(SHA_CTX *c, const void *data, size_t len); +#define git_SHA1_Update git_SHA1_Update_Chunked +#else +#define git_SHA1_Update platform_SHA1_Update #endif #include diff --git a/compat/apple-common-crypto.h b/compat/apple-common-crypto.h index c8b9b0e..d3fb264 100644 --- a/compat/apple-common-crypto.h +++ b/compat/apple-common-crypto.h @@ -16,6 +16,10 @@ #undef TYPE_BOOL #endif +#ifndef SHA1_MAX_BLOCK_SIZE +#error Using Apple Common Crypto library requires setting SHA1_MAX_BLOCK_SIZE +#endif + #ifdef APPLE_LION_OR_NEWER #define git_CC_error_check(pattern, err) \ do { \ diff --git a/compat/sha1_chunked.c b/compat/sha1_chunked.c new file mode 100644 index 000..61f67de --- /dev/null +++ b/compat/sha1_chunked.c @@ -0,0 +1,19 @@ +#include "cache.h" + +int git_SHA1_Update_Chunked(SHA_CTX *c, const void *data, size_t len) +{ + size_t nr; + size_t total = 0; + const char *cdata = (const char*)data; + + while (len > 0) { + nr = len; + if (nr > SHA1_MAX_BLOCK_SIZE) + nr = SHA1_MAX_BLOCK_SIZE; + platform_SHA1_Update(c, cdata, nr); + total += nr; + cdata += nr; + len -= nr; + } + return total; +} -- 2.4.9 (Apple Git-60) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] Limit the size of the data block passed to SHA1_Update()
From: Atousa Pahlevan DupratSome implementations of SHA_Updates have inherent limits on the max chunk size. SHA1_MAX_BLOCK_SIZE can be defined to set the max chunk size supported, if required. This is enabled for OSX CommonCrypto library and set to 1GiB. Signed-off-by: Atousa Pahlevan Duprat --- Makefile | 9 + cache.h | 7 ++- compat/apple-common-crypto.h | 4 compat/sha1_chunked.c| 21 + 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 compat/sha1_chunked.c diff --git a/Makefile b/Makefile index 04c2231..5955542 100644 --- a/Makefile +++ b/Makefile @@ -141,6 +141,10 @@ all:: # Define PPC_SHA1 environment variable when running make to make use of # a bundled SHA1 routine optimized for PowerPC. # +# Define SHA1_MAX_BLOCK_SIZE if your SSH1_Update() implementation can +# hash only a limited amount of data in one call (e.g. APPLE_COMMON_CRYPTO +# may want 'SHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L' defined). +# # Define NEEDS_CRYPTO_WITH_SSL if you need -lcrypto when using -lssl (Darwin). # # Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin). @@ -1346,6 +1350,7 @@ else ifdef APPLE_COMMON_CRYPTO COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL SHA1_HEADER = + SHA1_MAX_BLOCK_SIZE = 1024L*1024L*1024L else SHA1_HEADER = EXTLIBS += $(LIB_4_CRYPTO) @@ -1353,6 +1358,10 @@ endif endif endif +ifdef SHA1_MAX_BLOCK_SIZE + LIB_OBJS += compat/sha1_chunked.o + BASIC_CFLAGS += -DSHA1_MAX_BLOCK_SIZE="$(SHA1_MAX_BLOCK_SIZE)" +endif ifdef NO_PERL_MAKEMAKER export NO_PERL_MAKEMAKER endif diff --git a/cache.h b/cache.h index 79066e5..ec84b16 100644 --- a/cache.h +++ b/cache.h @@ -14,7 +14,12 @@ #ifndef git_SHA_CTX #define git_SHA_CTXSHA_CTX #define git_SHA1_Init SHA1_Init -#define git_SHA1_UpdateSHA1_Update +#ifdef SHA1_MAX_BLOCK_SIZE +extern int SHA1_Update_Chunked(SHA_CTX *, const void *, size_t); +#define git_SHA1_Update SHA1_Update_Chunked +#else +#define git_SHA1_Update SHA1_Update +#endif #define git_SHA1_Final SHA1_Final #endif diff --git a/compat/apple-common-crypto.h b/compat/apple-common-crypto.h index c8b9b0e..d3fb264 100644 --- a/compat/apple-common-crypto.h +++ b/compat/apple-common-crypto.h @@ -16,6 +16,10 @@ #undef TYPE_BOOL #endif +#ifndef SHA1_MAX_BLOCK_SIZE +#error Using Apple Common Crypto library requires setting SHA1_MAX_BLOCK_SIZE +#endif + #ifdef APPLE_LION_OR_NEWER #define git_CC_error_check(pattern, err) \ do { \ diff --git a/compat/sha1_chunked.c b/compat/sha1_chunked.c new file mode 100644 index 000..bf62b1b --- /dev/null +++ b/compat/sha1_chunked.c @@ -0,0 +1,21 @@ +#include "cache.h" + +#ifdef SHA1_MAX_BLOCK_SIZE +int git_SHA1_Update(SHA_CTX *c, const void *data, size_t len) +{ + size_t nr; + size_t total = 0; + char *cdata = (char*)data; + + while (len > 0) { + nr = len; + if (nr > SHA1_MAX_BLOCK_SIZE) + nr = SHA1_MAX_BLOCK_SIZE; + SHA1_Update(c, cdata, nr); + total += nr; + cdata += nr; + len -= nr; + } + return total; +} +#endif -- 2.4.9 (Apple Git-60) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html