Skip to content

Commit cb6ec86

Browse files
committed
Merge branch 'ti/external-sha1dc'
Platforms that ship with a separate sha1 with collision detection library can link to it instead of using the copy we ship as part of our source tree. * ti/external-sha1dc: sha1dc: allow building with the external sha1dc library sha1dc: build git plumbing code more explicitly
2 parents 6867272 + 3964cbb commit cb6ec86

4 files changed

Lines changed: 48 additions & 22 deletions

File tree

Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ all::
162162
# algorithm. This is slower, but may detect attempted collision attacks.
163163
# Takes priority over other *_SHA1 knobs.
164164
#
165+
# Define DC_SHA1_EXTERNAL in addition to DC_SHA1 if you want to build / link
166+
# git with the external SHA1 collision-detect library.
167+
# Without this option, i.e. the default behavior is to build git with its
168+
# own built-in code (or submodule).
169+
#
165170
# Define DC_SHA1_SUBMODULE in addition to DC_SHA1 to use the
166171
# sha1collisiondetection shipped as a submodule instead of the
167172
# non-submodule copy in sha1dc/. This is an experimental option used
@@ -1475,6 +1480,15 @@ ifdef APPLE_COMMON_CRYPTO
14751480
BASIC_CFLAGS += -DSHA1_APPLE
14761481
else
14771482
DC_SHA1 := YesPlease
1483+
BASIC_CFLAGS += -DSHA1_DC
1484+
LIB_OBJS += sha1dc_git.o
1485+
ifdef DC_SHA1_EXTERNAL
1486+
ifdef DC_SHA1_SUBMODULE
1487+
$(error Only set DC_SHA1_EXTERNAL or DC_SHA1_SUBMODULE, not both)
1488+
endif
1489+
BASIC_CFLAGS += -DDC_SHA1_EXTERNAL
1490+
EXTLIBS += -lsha1detectcoll
1491+
else
14781492
ifdef DC_SHA1_SUBMODULE
14791493
LIB_OBJS += sha1collisiondetection/lib/sha1.o
14801494
LIB_OBJS += sha1collisiondetection/lib/ubc_check.o
@@ -1484,17 +1498,15 @@ else
14841498
LIB_OBJS += sha1dc/ubc_check.o
14851499
endif
14861500
BASIC_CFLAGS += \
1487-
-DSHA1_DC \
14881501
-DSHA1DC_NO_STANDARD_INCLUDES \
14891502
-DSHA1DC_INIT_SAFE_HASH_DEFAULT=0 \
14901503
-DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"cache.h\"" \
1491-
-DSHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C="\"sha1dc_git.c\"" \
1492-
-DSHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_H="\"sha1dc_git.h\"" \
14931504
-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="\"git-compat-util.h\""
14941505
endif
14951506
endif
14961507
endif
14971508
endif
1509+
endif
14981510

14991511
ifdef SHA1_MAX_BLOCK_SIZE
15001512
LIB_OBJS += compat/sha1-chunked.o

hash.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
#elif defined(SHA1_OPENSSL)
99
#include <openssl/sha.h>
1010
#elif defined(SHA1_DC)
11-
#ifdef DC_SHA1_SUBMODULE
12-
#include "sha1collisiondetection/lib/sha1.h"
13-
#else
14-
#include "sha1dc/sha1.h"
15-
#endif
11+
#include "sha1dc_git.h"
1612
#else /* SHA1_BLK */
1713
#include "block-sha1/sha1.h"
1814
#endif

sha1dc_git.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
#include "cache.h"
2+
3+
#ifdef DC_SHA1_EXTERNAL
14
/*
2-
* This code is included at the end of sha1dc/sha1.c with the
3-
* SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C macro.
5+
* Same as SHA1DCInit, but with default save_hash=0
46
*/
7+
void git_SHA1DCInit(SHA1_CTX *ctx)
8+
{
9+
SHA1DCInit(ctx);
10+
SHA1DCSetSafeHash(ctx, 0);
11+
}
12+
#endif
513

14+
/*
15+
* Same as SHA1DCFinal, but convert collision attack case into a verbose die().
16+
*/
617
void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
718
{
819
if (!SHA1DCFinal(hash, ctx))
@@ -11,6 +22,9 @@ void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
1122
sha1_to_hex(hash));
1223
}
1324

25+
/*
26+
* Same as SHA1DCUpdate, but adjust types to match git's usual interface.
27+
*/
1428
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, unsigned long len)
1529
{
1630
const char *data = vdata;

sha1dc_git.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
/*
2-
* This code is included at the end of sha1dc/sha1.h with the
3-
* SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_H macro.
4-
*/
1+
/* Plumbing with collition-detecting SHA1 code */
52

6-
/*
7-
* Same as SHA1DCFinal, but convert collision attack case into a verbose die().
8-
*/
9-
void git_SHA1DCFinal(unsigned char [20], SHA1_CTX *);
3+
#ifdef DC_SHA1_SUBMODULE
4+
#include "sha1collisiondetection/lib/sha1.h"
5+
#elif defined(DC_SHA1_EXTERNAL)
6+
#include <sha1dc/sha1.h>
7+
#else
8+
#include "sha1dc/sha1.h"
9+
#endif
10+
11+
#ifdef DC_SHA1_EXTERNAL
12+
void git_SHA1DCInit(SHA1_CTX *);
13+
#else
14+
#define git_SHA1DCInit SHA1DCInit
15+
#endif
1016

11-
/*
12-
* Same as SHA1DCUpdate, but adjust types to match git's usual interface.
13-
*/
17+
void git_SHA1DCFinal(unsigned char [20], SHA1_CTX *);
1418
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, unsigned long len);
1519

1620
#define platform_SHA_CTX SHA1_CTX
17-
#define platform_SHA1_Init SHA1DCInit
21+
#define platform_SHA1_Init git_SHA1DCInit
1822
#define platform_SHA1_Update git_SHA1DCUpdate
1923
#define platform_SHA1_Final git_SHA1DCFinal

0 commit comments

Comments
 (0)