Skip to content

Commit e53598a

Browse files
committed
Merge branch 'ab/sha-makefile-doc'
Makefile comments updates and reordering to clarify knobs used to choose SHA implementations. * ab/sha-makefile-doc: Makefile: discuss SHAttered in *_SHA{1,256} discussion Makefile: document default SHA-1 backend on OSX Makefile & test-tool: replace "DC_SHA1" variable with a "define" Makefile: document SHA-1 and SHA-256 default and selection order Makefile: document default SHA-256 backend Makefile: rephrase the discussion of *_SHA1 knobs Makefile: create and use sections for "define" flag listing Makefile: correct DC_SHA1 documentation INSTALL: remove discussion of SHA-1 backends Makefile: always (re)set DC_SHA1 on fallback
2 parents 69c1d60 + d00fa55 commit e53598a

File tree

9 files changed

+173
-104
lines changed

9 files changed

+173
-104
lines changed

INSTALL

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ Issues of note:
133133
you are using libcurl older than 7.34.0. Otherwise you can use
134134
NO_OPENSSL without losing git-imap-send.
135135

136-
By default, git uses OpenSSL for SHA1 but it will use its own
137-
library (inspired by Mozilla's) with either NO_OPENSSL or
138-
BLK_SHA1.
139-
140136
- "libcurl" library is used for fetching and pushing
141137
repositories over http:// or https://, as well as by
142138
git-imap-send if the curl version is >= 7.34.0. If you do

Makefile

Lines changed: 157 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ all::
44
# Import tree-wide shared Makefile behavior and libraries
55
include shared.mak
66

7+
# == Makefile defines ==
8+
#
9+
# These defines change the behavior of the Makefile itself, but have
10+
# no impact on what it builds:
11+
#
712
# Define V=1 to have a more verbose compile.
813
#
14+
# == Portability and optional library defines ==
15+
#
16+
# These defines indicate what Git can expect from the OS, what
17+
# libraries are available etc. Much of this is auto-detected in
18+
# config.mak.uname, or in configure.ac when using the optional "make
19+
# configure && ./configure" (see INSTALL).
20+
#
921
# Define SHELL_PATH to a POSIX shell if your /bin/sh is broken.
1022
#
1123
# Define SANE_TOOL_PATH to a colon-separated list of paths to prepend
@@ -30,68 +42,8 @@ include shared.mak
3042
#
3143
# Define NO_OPENSSL environment variable if you do not have OpenSSL.
3244
#
33-
# Define USE_LIBPCRE if you have and want to use libpcre. Various
34-
# commands such as log and grep offer runtime options to use
35-
# Perl-compatible regular expressions instead of standard or extended
36-
# POSIX regular expressions.
37-
#
38-
# Only libpcre version 2 is supported. USE_LIBPCRE2 is a synonym for
39-
# USE_LIBPCRE, support for the old USE_LIBPCRE1 has been removed.
40-
#
41-
# Define LIBPCREDIR=/foo/bar if your PCRE header and library files are
42-
# in /foo/bar/include and /foo/bar/lib directories.
43-
#
4445
# Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header.
4546
#
46-
# Define NO_CURL if you do not have libcurl installed. git-http-fetch and
47-
# git-http-push are not built, and you cannot use http:// and https://
48-
# transports (neither smart nor dumb).
49-
#
50-
# Define CURLDIR=/foo/bar if your curl header and library files are in
51-
# /foo/bar/include and /foo/bar/lib directories.
52-
#
53-
# Define CURL_CONFIG to curl's configuration program that prints information
54-
# about the library (e.g., its version number). The default is 'curl-config'.
55-
#
56-
# Define CURL_LDFLAGS to specify flags that you need to link when using libcurl,
57-
# if you do not want to rely on the libraries provided by CURL_CONFIG. The
58-
# default value is a result of `curl-config --libs`. An example value for
59-
# CURL_LDFLAGS is as follows:
60-
#
61-
# CURL_LDFLAGS=-lcurl
62-
#
63-
# Define NO_EXPAT if you do not have expat installed. git-http-push is
64-
# not built, and you cannot push using http:// and https:// transports (dumb).
65-
#
66-
# Define EXPATDIR=/foo/bar if your expat header and library files are in
67-
# /foo/bar/include and /foo/bar/lib directories.
68-
#
69-
# Define EXPAT_NEEDS_XMLPARSE_H if you have an old version of expat (e.g.,
70-
# 1.1 or 1.2) that provides xmlparse.h instead of expat.h.
71-
#
72-
# Define NO_GETTEXT if you don't want Git output to be translated.
73-
# A translated Git requires GNU libintl or another gettext implementation,
74-
# plus libintl-perl at runtime.
75-
#
76-
# Define USE_GETTEXT_SCHEME and set it to 'fallthrough', if you don't trust
77-
# the installed gettext translation of the shell scripts output.
78-
#
79-
# Define HAVE_LIBCHARSET_H if you haven't set NO_GETTEXT and you can't
80-
# trust the langinfo.h's nl_langinfo(CODESET) function to return the
81-
# current character set. GNU and Solaris have a nl_langinfo(CODESET),
82-
# FreeBSD can use either, but MinGW and some others need to use
83-
# libcharset.h's locale_charset() instead.
84-
#
85-
# Define CHARSET_LIB to the library you need to link with in order to
86-
# use locale_charset() function. On some platforms this needs to set to
87-
# -lcharset, on others to -liconv .
88-
#
89-
# Define LIBC_CONTAINS_LIBINTL if your gettext implementation doesn't
90-
# need -lintl when linking.
91-
#
92-
# Define NO_MSGFMT_EXTENDED_OPTIONS if your implementation of msgfmt
93-
# doesn't support GNU extensions like --check and --statistics
94-
#
9547
# Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
9648
# it specifies.
9749
#
@@ -152,39 +104,6 @@ include shared.mak
152104
# and do not want to use Apple's CommonCrypto library. This allows you
153105
# to provide your own OpenSSL library, for example from MacPorts.
154106
#
155-
# Define BLK_SHA1 environment variable to make use of the bundled
156-
# optimized C SHA1 routine.
157-
#
158-
# Define DC_SHA1 to unconditionally enable the collision-detecting sha1
159-
# algorithm. This is slower, but may detect attempted collision attacks.
160-
# Takes priority over other *_SHA1 knobs.
161-
#
162-
# Define DC_SHA1_EXTERNAL in addition to DC_SHA1 if you want to build / link
163-
# git with the external SHA1 collision-detect library.
164-
# Without this option, i.e. the default behavior is to build git with its
165-
# own built-in code (or submodule).
166-
#
167-
# Define DC_SHA1_SUBMODULE in addition to DC_SHA1 to use the
168-
# sha1collisiondetection shipped as a submodule instead of the
169-
# non-submodule copy in sha1dc/. This is an experimental option used
170-
# by the git project to migrate to using sha1collisiondetection as a
171-
# submodule.
172-
#
173-
# Define OPENSSL_SHA1 environment variable when running make to link
174-
# with the SHA1 routine from openssl library.
175-
#
176-
# Define SHA1_MAX_BLOCK_SIZE to limit the amount of data that will be hashed
177-
# in one call to the platform's SHA1_Update(). e.g. APPLE_COMMON_CRYPTO
178-
# wants 'SHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L' defined.
179-
#
180-
# Define BLK_SHA256 to use the built-in SHA-256 routines.
181-
#
182-
# Define NETTLE_SHA256 to use the SHA-256 routines in libnettle.
183-
#
184-
# Define GCRYPT_SHA256 to use the SHA-256 routines in libgcrypt.
185-
#
186-
# Define OPENSSL_SHA256 to use the SHA-256 routines in OpenSSL.
187-
#
188107
# Define NEEDS_CRYPTO_WITH_SSL if you need -lcrypto when using -lssl (Darwin).
189108
#
190109
# Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin).
@@ -490,6 +409,151 @@ include shared.mak
490409
# to the "<name>" of the corresponding `compat/fsmonitor/fsm-settings-<name>.c`
491410
# that implements the `fsm_os_settings__*()` routines.
492411
#
412+
# === Optional library: libintl ===
413+
#
414+
# Define NO_GETTEXT if you don't want Git output to be translated.
415+
# A translated Git requires GNU libintl or another gettext implementation,
416+
# plus libintl-perl at runtime.
417+
#
418+
# Define USE_GETTEXT_SCHEME and set it to 'fallthrough', if you don't trust
419+
# the installed gettext translation of the shell scripts output.
420+
#
421+
# Define HAVE_LIBCHARSET_H if you haven't set NO_GETTEXT and you can't
422+
# trust the langinfo.h's nl_langinfo(CODESET) function to return the
423+
# current character set. GNU and Solaris have a nl_langinfo(CODESET),
424+
# FreeBSD can use either, but MinGW and some others need to use
425+
# libcharset.h's locale_charset() instead.
426+
#
427+
# Define CHARSET_LIB to the library you need to link with in order to
428+
# use locale_charset() function. On some platforms this needs to set to
429+
# -lcharset, on others to -liconv .
430+
#
431+
# Define LIBC_CONTAINS_LIBINTL if your gettext implementation doesn't
432+
# need -lintl when linking.
433+
#
434+
# Define NO_MSGFMT_EXTENDED_OPTIONS if your implementation of msgfmt
435+
# doesn't support GNU extensions like --check and --statistics
436+
#
437+
# === Optional library: libexpat ===
438+
#
439+
# Define NO_EXPAT if you do not have expat installed. git-http-push is
440+
# not built, and you cannot push using http:// and https:// transports (dumb).
441+
#
442+
# Define EXPATDIR=/foo/bar if your expat header and library files are in
443+
# /foo/bar/include and /foo/bar/lib directories.
444+
#
445+
# Define EXPAT_NEEDS_XMLPARSE_H if you have an old version of expat (e.g.,
446+
# 1.1 or 1.2) that provides xmlparse.h instead of expat.h.
447+
448+
# === Optional library: libcurl ===
449+
#
450+
# Define NO_CURL if you do not have libcurl installed. git-http-fetch and
451+
# git-http-push are not built, and you cannot use http:// and https://
452+
# transports (neither smart nor dumb).
453+
#
454+
# Define CURLDIR=/foo/bar if your curl header and library files are in
455+
# /foo/bar/include and /foo/bar/lib directories.
456+
#
457+
# Define CURL_CONFIG to curl's configuration program that prints information
458+
# about the library (e.g., its version number). The default is 'curl-config'.
459+
#
460+
# Define CURL_LDFLAGS to specify flags that you need to link when using libcurl,
461+
# if you do not want to rely on the libraries provided by CURL_CONFIG. The
462+
# default value is a result of `curl-config --libs`. An example value for
463+
# CURL_LDFLAGS is as follows:
464+
#
465+
# CURL_LDFLAGS=-lcurl
466+
#
467+
# === Optional library: libpcre2 ===
468+
#
469+
# Define USE_LIBPCRE if you have and want to use libpcre. Various
470+
# commands such as log and grep offer runtime options to use
471+
# Perl-compatible regular expressions instead of standard or extended
472+
# POSIX regular expressions.
473+
#
474+
# Only libpcre version 2 is supported. USE_LIBPCRE2 is a synonym for
475+
# USE_LIBPCRE, support for the old USE_LIBPCRE1 has been removed.
476+
#
477+
# Define LIBPCREDIR=/foo/bar if your PCRE header and library files are
478+
# in /foo/bar/include and /foo/bar/lib directories.
479+
#
480+
# == SHA-1 and SHA-256 defines ==
481+
#
482+
# === SHA-1 backend ===
483+
#
484+
# ==== Security ====
485+
#
486+
# Due to the SHAttered (https://shattered.io) attack vector on SHA-1
487+
# it's strongly recommended to use the sha1collisiondetection
488+
# counter-cryptanalysis library for SHA-1 hashing.
489+
#
490+
# If you know that you can trust the repository contents, or where
491+
# potential SHA-1 attacks are otherwise mitigated the other backends
492+
# listed in "SHA-1 implementations" are faster than
493+
# sha1collisiondetection.
494+
#
495+
# ==== Default SHA-1 backend ====
496+
#
497+
# If no *_SHA1 backend is picked, the first supported one listed in
498+
# "SHA-1 implementations" will be picked.
499+
#
500+
# ==== Options common to all SHA-1 implementations ====
501+
#
502+
# Define SHA1_MAX_BLOCK_SIZE to limit the amount of data that will be hashed
503+
# in one call to the platform's SHA1_Update(). e.g. APPLE_COMMON_CRYPTO
504+
# wants 'SHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L' defined.
505+
#
506+
# ==== SHA-1 implementations ====
507+
#
508+
# Define OPENSSL_SHA1 to link to the SHA-1 routines from the OpenSSL
509+
# library.
510+
#
511+
# Define BLK_SHA1 to make use of optimized C SHA-1 routines bundled
512+
# with git (in the block-sha1/ directory).
513+
#
514+
# Define NO_APPLE_COMMON_CRYPTO on OSX to opt-out of using the
515+
# "APPLE_COMMON_CRYPTO" backend for SHA-1, which is currently the
516+
# default on that OS. On macOS 01.4 (Tiger) or older,
517+
# NO_APPLE_COMMON_CRYPTO is defined by default.
518+
#
519+
# If don't enable any of the *_SHA1 settings in this section, Git will
520+
# default to its built-in sha1collisiondetection library, which is a
521+
# collision-detecting sha1 This is slower, but may detect attempted
522+
# collision attacks.
523+
#
524+
# ==== Options for the sha1collisiondetection library ====
525+
#
526+
# Define DC_SHA1_EXTERNAL if you want to build / link
527+
# git with the external SHA1 collision-detect library.
528+
# Without this option, i.e. the default behavior is to build git with its
529+
# own built-in code (or submodule).
530+
#
531+
# Define DC_SHA1_SUBMODULE to use the
532+
# sha1collisiondetection shipped as a submodule instead of the
533+
# non-submodule copy in sha1dc/. This is an experimental option used
534+
# by the git project to migrate to using sha1collisiondetection as a
535+
# submodule.
536+
#
537+
# === SHA-256 backend ===
538+
#
539+
# ==== Security ====
540+
#
541+
# Unlike SHA-1 the SHA-256 algorithm does not suffer from any known
542+
# vulnerabilities, so any implementation will do.
543+
#
544+
# ==== SHA-256 implementations ====
545+
#
546+
# Define OPENSSL_SHA256 to use the SHA-256 routines in OpenSSL.
547+
#
548+
# Define NETTLE_SHA256 to use the SHA-256 routines in libnettle.
549+
#
550+
# Define GCRYPT_SHA256 to use the SHA-256 routines in libgcrypt.
551+
#
552+
# If don't enable any of the *_SHA256 settings in this section, Git
553+
# will default to its built-in sha256 implementation.
554+
#
555+
# == DEVELOPER defines ==
556+
#
493557
# Define DEVELOPER to enable more compiler warnings. Compiler version
494558
# and family are auto detected, but could be overridden by defining
495559
# COMPILER_FEATURES (see config.mak.dev). You can still set
@@ -1826,7 +1890,6 @@ ifdef APPLE_COMMON_CRYPTO
18261890
COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL
18271891
BASIC_CFLAGS += -DSHA1_APPLE
18281892
else
1829-
DC_SHA1 := YesPlease
18301893
BASIC_CFLAGS += -DSHA1_DC
18311894
LIB_OBJS += sha1dc_git.o
18321895
ifdef DC_SHA1_EXTERNAL
@@ -2989,7 +3052,6 @@ GIT-BUILD-OPTIONS: FORCE
29893052
@echo NO_REGEX=\''$(subst ','\'',$(subst ','\'',$(NO_REGEX)))'\' >>$@+
29903053
@echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@+
29913054
@echo PAGER_ENV=\''$(subst ','\'',$(subst ','\'',$(PAGER_ENV)))'\' >>$@+
2992-
@echo DC_SHA1=\''$(subst ','\'',$(subst ','\'',$(DC_SHA1)))'\' >>$@+
29933055
@echo SANITIZE_LEAK=\''$(subst ','\'',$(subst ','\'',$(SANITIZE_LEAK)))'\' >>$@+
29943056
@echo SANITIZE_ADDRESS=\''$(subst ','\'',$(subst ','\'',$(SANITIZE_ADDRESS)))'\' >>$@+
29953057
@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)