help: include SHA implementation in version info

When the `--build-options` flag is used with git-version(1), additional information about the built version of Git is printed. During build time, different SHA implementations may be configured, but this information is not included in the version info. Add the SHA implementations Git is built with to the version info by requiring each backend to define a SHA1_BACKEND or SHA256_BACKEND symbol as appropriate and use the value in the printed build options. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Apr 3, 2025 at 09:05 UTC 16fd6c85e4d036e789916e4d802b47a792fe496e
3 files changed +17
Documentation/git-version.adoc
+6
@@ -22,6 +22,12 @@ OPTIONS
22 --build-options::
23 Include additional information about how git was built for diagnostic
24 purposes.
25 ++
26 +The libraries used to implement the SHA-1 and SHA-256 algorithms are displayed
27 +in the form `SHA-1: <option>` and `SHA-256: <option>`. Note that the SHA-1
28 +options `SHA1_APPLE`, `SHA1_OPENSSL`, and `SHA1_BLK` do not use a collision
29 +detection algorithm and thus may be vulnerable to known SHA-1 collision
30 +attacks.
31
32 GIT
33 ---
hash.h
+8
@@ -2,16 +2,20 @@
2 #define HASH_H
3
4 #if defined(SHA1_APPLE)
5 +#define SHA1_BACKEND "SHA1_APPLE (No collision detection)"
6 #include <CommonCrypto/CommonDigest.h>
7 #elif defined(SHA1_OPENSSL)
8 +# define SHA1_BACKEND "SHA1_OPENSSL (No collision detection)"
9 # include <openssl/sha.h>
10 # if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
11 # define SHA1_NEEDS_CLONE_HELPER
12 # include "sha1/openssl.h"
13 # endif
14 #elif defined(SHA1_DC)
15 +#define SHA1_BACKEND "SHA1_DC"
16 #include "sha1dc_git.h"
17 #else /* SHA1_BLK */
18 +#define SHA1_BACKEND "SHA1_BLK (No collision detection)"
19 #include "block-sha1/sha1.h"
20 #endif
21
@@ -46,17 +50,21 @@
50 #endif
51
52 #if defined(SHA256_NETTLE)
53 +#define SHA256_BACKEND "SHA256_NETTLE"
54 #include "sha256/nettle.h"
55 #elif defined(SHA256_GCRYPT)
56 +#define SHA256_BACKEND "SHA256_GCRYPT"
57 #define SHA256_NEEDS_CLONE_HELPER
58 #include "sha256/gcrypt.h"
59 #elif defined(SHA256_OPENSSL)
60 +# define SHA256_BACKEND "SHA256_OPENSSL"
61 # include <openssl/sha.h>
62 # if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
63 # define SHA256_NEEDS_CLONE_HELPER
64 # include "sha256/openssl.h"
65 # endif
66 #else
67 +#define SHA256_BACKEND "SHA256_BLK"
68 #include "sha256/block/sha256.h"
69 #endif
70
help.c
+3
@@ -9,6 +9,7 @@
9 #include "run-command.h"
10 #include "levenshtein.h"
11 #include "gettext.h"
12 +#include "hash.h"
13 #include "help.h"
14 #include "command-list.h"
15 #include "string-list.h"
@@ -803,6 +804,8 @@ void get_version_info(struct strbuf *buf, int show_build_options)
804 #elif defined ZLIB_VERSION
805 strbuf_addf(buf, "zlib: %s\n", ZLIB_VERSION);
806 #endif
807 + strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
808 + strbuf_addf(buf, "SHA-256: %s\n", SHA256_BACKEND);
809 }
810 }
811