Skip to content

Commit 3964cbb

Browse files
tiwaigitster
authored andcommitted
sha1dc: allow building with the external sha1dc library
Some distros provide SHA1 collision-detect code as a shared library. It's the same code as we have in git tree (but may be with a different init default for hash), and git can link with it as well; at least, it may make maintenance easier, according to our security guys. This patch allows user to build git linking with the external sha1dc library instead of the built-in code. User needs to define DC_SHA1_EXTERNAL explicitly. As default without it, the built-in sha1dc code is used like before. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 36f048c commit 3964cbb

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

Makefile

Lines changed: 13 additions & 0 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
@@ -1474,6 +1479,13 @@ else
14741479
DC_SHA1 := YesPlease
14751480
BASIC_CFLAGS += -DSHA1_DC
14761481
LIB_OBJS += sha1dc_git.o
1482+
ifdef DC_SHA1_EXTERNAL
1483+
ifdef DC_SHA1_SUBMODULE
1484+
$(error Only set DC_SHA1_EXTERNAL or DC_SHA1_SUBMODULE, not both)
1485+
endif
1486+
BASIC_CFLAGS += -DDC_SHA1_EXTERNAL
1487+
EXTLIBS += -lsha1detectcoll
1488+
else
14771489
ifdef DC_SHA1_SUBMODULE
14781490
LIB_OBJS += sha1collisiondetection/lib/sha1.o
14791491
LIB_OBJS += sha1collisiondetection/lib/ubc_check.o
@@ -1491,6 +1503,7 @@ endif
14911503
endif
14921504
endif
14931505
endif
1506+
endif
14941507

14951508
ifdef SHA1_MAX_BLOCK_SIZE
14961509
LIB_OBJS += compat/sha1-chunked.o

sha1dc_git.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
#include "cache.h"
22

3+
#ifdef DC_SHA1_EXTERNAL
4+
/*
5+
* Same as SHA1DCInit, but with default save_hash=0
6+
*/
7+
void git_SHA1DCInit(SHA1_CTX *ctx)
8+
{
9+
SHA1DCInit(ctx);
10+
SHA1DCSetSafeHash(ctx, 0);
11+
}
12+
#endif
13+
314
/*
415
* Same as SHA1DCFinal, but convert collision attack case into a verbose die().
516
*/

sha1dc_git.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@
22

33
#ifdef DC_SHA1_SUBMODULE
44
#include "sha1collisiondetection/lib/sha1.h"
5+
#elif defined(DC_SHA1_EXTERNAL)
6+
#include <sha1dc/sha1.h>
57
#else
68
#include "sha1dc/sha1.h"
79
#endif
810

11+
#ifdef DC_SHA1_EXTERNAL
12+
void git_SHA1DCInit(SHA1_CTX *);
13+
#else
14+
#define git_SHA1DCInit SHA1DCInit
15+
#endif
16+
917
void git_SHA1DCFinal(unsigned char [20], SHA1_CTX *);
1018
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, unsigned long len);
1119

1220
#define platform_SHA_CTX SHA1_CTX
13-
#define platform_SHA1_Init SHA1DCInit
21+
#define platform_SHA1_Init git_SHA1DCInit
1422
#define platform_SHA1_Update git_SHA1DCUpdate
1523
#define platform_SHA1_Final git_SHA1DCFinal

0 commit comments

Comments
 (0)