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>
Atousa Pahlevan Duprat committed
Nov 4, 2015 at 22:38 UTC
001fd7a90b5851f62e700510729a5e09706f9b63
5 files changed
+44
Makefile
+13
@@ -141,6 +141,10 @@ all::
141
# Define PPC_SHA1 environment variable when running make to make use of
142
# a bundled SHA1 routine optimized for PowerPC.
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
+#
148
# Define NEEDS_CRYPTO_WITH_SSL if you need -lcrypto when using -lssl (Darwin).
149
#
150
# Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin).
@@ -1276,6 +1280,11 @@ ifdef NO_POSIX_GOODIES
1280
BASIC_CFLAGS += -DNO_POSIX_GOODIES
1281
endif
1282
1283
+ifdef APPLE_COMMON_CRYPTO
1284
+ # Apple CommonCrypto requires chunking
1285
+ SHA1_MAX_BLOCK_SIZE = 1024L*1024L*1024L
1286
+endif
1287
+
1288
ifdef BLK_SHA1
1289
SHA1_HEADER = "block-sha1/sha1.h"
1290
LIB_OBJS += block-sha1/sha1.o
@@ -1294,6 +1303,10 @@ endif
1303
endif
1304
endif
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
1310
ifdef NO_PERL_MAKEMAKER
1311
export NO_PERL_MAKEMAKER
1312
endif
cache.h
+6
@@ -30,6 +30,12 @@
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
37
+#endif
38
+
39
#include <zlib.h>
40
typedef struct git_zstream {
41
z_stream z;
compat/apple-common-crypto.h
+4
@@ -16,6 +16,10 @@
16
#undef TYPE_BOOL
17
#endif
18
19
+#ifndef SHA1_MAX_BLOCK_SIZE
20
+#error Using Apple Common Crypto library requires setting SHA1_MAX_BLOCK_SIZE
21
+#endif
22
+
23
#ifdef APPLE_LION_OR_NEWER
24
#define git_CC_error_check(pattern, err) \
25
do { \
compat/sha1-chunked.c
new
+19
@@ -0,0 +1,19 @@
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
+}
compat/sha1-chunked.h
new
+2
@@ -0,0 +1,2 @@
1
+
2
+int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len);