Skip to content

Commit dc1cf35

Browse files
avarttaylorr
authored andcommitted
Makefile & test-tool: replace "DC_SHA1" variable with a "define"
Address the root cause of technical debt we've been carrying since sha1collisiondetection was made the default in [1]. In a preceding commit we narrowly fixed a bug where the "DC_SHA1" variable would be unset (in combination with "NO_APPLE_COMMON_CRYPTO=" on OSX), even though we had the sha1collisiondetection library enabled. But the only reason we needed to have such a user-exposed knob went away with [1], and it's been doing nothing useful since then. We don't care if you define DC_SHA1=*, we only care that you don't ask for any other SHA-1 implementation. If it turns out that you didn't, we'll use sha1collisiondetection, whether you had "DC_SHA1" set or not. As a result of this being confusing we had e.g. [2] for cmake and the recent [3] for ci/lib.sh setting "DC_SHA1" explicitly, even though this was always a NOOP. A much simpler way to do this is to stop having the Makefile and CMakeLists.txt set "DC_SHA1" to be picked up by the test-lib.sh, let's instead add a trivial "test-tool sha1-is-sha1dc". It returns zero if we're using sha1collisiondetection, non-zero otherwise. 1. e6b07da (Makefile: make DC_SHA1 the default, 2017-03-17) 2. c4b2f41 (cmake: support for testing git with ctest, 2020-06-26) 3. 1ad5c3d (ci: use DC_SHA1=YesPlease on osx-clang job for CI, 2022-10-20) Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent ed605fa commit dc1cf35

File tree

8 files changed

+20
-9
lines changed

8 files changed

+20
-9
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,10 @@ include shared.mak
500500
# Define BLK_SHA1 to make use of optimized C SHA-1 routines bundled
501501
# with git (in the block-sha1/ directory).
502502
#
503-
# Define DC_SHA1 to enable the collision-detecting sha1
504-
# algorithm. This is slower, but may detect attempted collision attacks.
503+
# If don't enable any of the *_SHA1 settings in this section, Git will
504+
# default to its built-in sha1collisiondetection library, which is a
505+
# collision-detecting sha1 This is slower, but may detect attempted
506+
# collision attacks.
505507
#
506508
# ==== Options for the sha1collisiondetection library ====
507509
#
@@ -1867,7 +1869,6 @@ ifdef APPLE_COMMON_CRYPTO
18671869
COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL
18681870
BASIC_CFLAGS += -DSHA1_APPLE
18691871
else
1870-
override DC_SHA1 = YesPlease
18711872
BASIC_CFLAGS += -DSHA1_DC
18721873
LIB_OBJS += sha1dc_git.o
18731874
ifdef DC_SHA1_EXTERNAL
@@ -3030,7 +3031,6 @@ GIT-BUILD-OPTIONS: FORCE
30303031
@echo NO_REGEX=\''$(subst ','\'',$(subst ','\'',$(NO_REGEX)))'\' >>$@+
30313032
@echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@+
30323033
@echo PAGER_ENV=\''$(subst ','\'',$(subst ','\'',$(PAGER_ENV)))'\' >>$@+
3033-
@echo DC_SHA1=\''$(subst ','\'',$(subst ','\'',$(DC_SHA1)))'\' >>$@+
30343034
@echo SANITIZE_LEAK=\''$(subst ','\'',$(subst ','\'',$(SANITIZE_LEAK)))'\' >>$@+
30353035
@echo SANITIZE_ADDRESS=\''$(subst ','\'',$(subst ','\'',$(SANITIZE_ADDRESS)))'\' >>$@+
30363036
@echo X=\'$(X)\' >>$@+

ci/lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ macos-latest)
260260
else
261261
MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=$(which python2)"
262262
MAKEFLAGS="$MAKEFLAGS NO_APPLE_COMMON_CRYPTO=NoThanks"
263-
MAKEFLAGS="$MAKEFLAGS DC_SHA1=YesPlease NO_OPENSSL=NoThanks"
263+
MAKEFLAGS="$MAKEFLAGS NO_OPENSSL=NoThanks"
264264
fi
265265
;;
266266
esac

contrib/buildsystems/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,6 @@ set(NO_PERL )
10251025
set(NO_PTHREADS )
10261026
set(NO_PYTHON )
10271027
set(PAGER_ENV "LESS=FRX LV=-c")
1028-
set(DC_SHA1 YesPlease)
10291028
set(RUNTIME_PREFIX true)
10301029
set(NO_GETTEXT )
10311030

@@ -1061,7 +1060,6 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PERL='${NO_PERL}'\n")
10611060
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PTHREADS='${NO_PTHREADS}'\n")
10621061
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\n")
10631062
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PAGER_ENV='${PAGER_ENV}'\n")
1064-
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DC_SHA1='${DC_SHA1}'\n")
10651063
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n")
10661064
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n")
10671065
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")

sha1dc_git.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ void git_SHA1DCInit(SHA1_CTX *);
1717
void git_SHA1DCFinal(unsigned char [20], SHA1_CTX *);
1818
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, unsigned long len);
1919

20+
#define platform_SHA_IS_SHA1DC /* used by "test-tool sha1-is-sha1dc" */
2021
#define platform_SHA_CTX SHA1_CTX
2122
#define platform_SHA1_Init git_SHA1DCInit
2223
#define platform_SHA1_Update git_SHA1DCUpdate

t/helper/test-sha1.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ int cmd__sha1(int ac, const char **av)
55
{
66
return cmd_hash_impl(ac, av, GIT_HASH_SHA1);
77
}
8+
9+
int cmd__sha1_is_sha1dc(int argc UNUSED, const char **argv UNUSED)
10+
{
11+
#ifdef platform_SHA_IS_SHA1DC
12+
return 0;
13+
#endif
14+
return 1;
15+
}

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static struct test_cmd cmds[] = {
7373
{ "scrap-cache-tree", cmd__scrap_cache_tree },
7474
{ "serve-v2", cmd__serve_v2 },
7575
{ "sha1", cmd__sha1 },
76+
{ "sha1-is-sha1dc", cmd__sha1_is_sha1dc },
7677
{ "sha256", cmd__sha256 },
7778
{ "sigchain", cmd__sigchain },
7879
{ "simple-ipc", cmd__simple_ipc },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ int cmd__run_command(int argc, const char **argv);
6666
int cmd__scrap_cache_tree(int argc, const char **argv);
6767
int cmd__serve_v2(int argc, const char **argv);
6868
int cmd__sha1(int argc, const char **argv);
69+
int cmd__sha1_is_sha1dc(int argc, const char **argv);
6970
int cmd__oid_array(int argc, const char **argv);
7071
int cmd__sha256(int argc, const char **argv);
7172
int cmd__sigchain(int argc, const char **argv);

t/t0013-sha1dc.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ TEST_PASSES_SANITIZE_LEAK=true
66
. ./test-lib.sh
77
TEST_DATA="$TEST_DIRECTORY/t0013"
88

9-
if test -z "$DC_SHA1"
9+
test_lazy_prereq SHA1_IS_SHA1DC 'test-tool sha1-is-sha1dc'
10+
11+
if ! test_have_prereq SHA1_IS_SHA1DC
1012
then
11-
skip_all='skipping sha1 collision tests, DC_SHA1 not set'
13+
skip_all='skipping sha1 collision tests, not using sha1collisiondetection'
1214
test_done
1315
fi
1416

0 commit comments

Comments
 (0)