Skip to content

Commit 36f048c

Browse files
tiwaigitster
authored andcommitted
sha1dc: build git plumbing code more explicitly
The plumbing code between sha1dc and git is defined in sha1dc_git.[ch], but these aren't compiled / included directly but only via the indirect inclusion from sha1dc code. This is slightly confusing when you try to trace the build flow. This patch brings the following changes for simplification: - Make sha1dc_git.c stand-alone and build from Makefile - sha1dc_git.h is the common header to include further sha1.h depending on the build condition - Move comments for plumbing codes from the header to definitions This is also meant as a preliminary work for further plumbing with external sha1dc shlib. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5800c63 commit 36f048c

4 files changed

Lines changed: 16 additions & 22 deletions

File tree

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,8 @@ ifdef APPLE_COMMON_CRYPTO
14721472
BASIC_CFLAGS += -DSHA1_APPLE
14731473
else
14741474
DC_SHA1 := YesPlease
1475+
BASIC_CFLAGS += -DSHA1_DC
1476+
LIB_OBJS += sha1dc_git.o
14751477
ifdef DC_SHA1_SUBMODULE
14761478
LIB_OBJS += sha1collisiondetection/lib/sha1.o
14771479
LIB_OBJS += sha1collisiondetection/lib/ubc_check.o
@@ -1481,12 +1483,9 @@ else
14811483
LIB_OBJS += sha1dc/ubc_check.o
14821484
endif
14831485
BASIC_CFLAGS += \
1484-
-DSHA1_DC \
14851486
-DSHA1DC_NO_STANDARD_INCLUDES \
14861487
-DSHA1DC_INIT_SAFE_HASH_DEFAULT=0 \
14871488
-DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"cache.h\"" \
1488-
-DSHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C="\"sha1dc_git.c\"" \
1489-
-DSHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_H="\"sha1dc_git.h\"" \
14901489
-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="\"git-compat-util.h\""
14911490
endif
14921491
endif

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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
#include "cache.h"
2+
13
/*
2-
* This code is included at the end of sha1dc/sha1.c with the
3-
* SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C macro.
4+
* Same as SHA1DCFinal, but convert collision attack case into a verbose die().
45
*/
5-
66
void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
77
{
88
if (!SHA1DCFinal(hash, ctx))
@@ -11,6 +11,9 @@ void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
1111
sha1_to_hex(hash));
1212
}
1313

14+
/*
15+
* Same as SHA1DCUpdate, but adjust types to match git's usual interface.
16+
*/
1417
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, unsigned long len)
1518
{
1619
const char *data = vdata;

sha1dc_git.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
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+
#else
6+
#include "sha1dc/sha1.h"
7+
#endif
108

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

1612
#define platform_SHA_CTX SHA1_CTX

0 commit comments

Comments
 (0)