git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 1/2] help: include SHA implementation in version info

From
Justin Tobler <jltobler@gmail.com>
Date
Apr 3, 2025, 14:05 UTC
Message-ID
<20250403140529.497876-2-jltobler@gmail.com>
In-Reply-To
<20250403140529.497876-1-jltobler@gmail.com>

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>
---
 Documentation/git-version.adoc | 6 ++++++
 hash.h                         | 8 ++++++++
 help.c                         | 3 +++
 3 files changed, 17 insertions(+)
diff --git a/Documentation/git-version.adoc b/Documentation/git-version.adoc
index 80fa7754a6..913ebf147d 100644
--- a/Documentation/git-version.adoc
+++ b/Documentation/git-version.adoc
@@ -22,6 +22,12 @@ OPTIONS
 --build-options::
 	Include additional information about how git was built for diagnostic
 	purposes.
++
+The libraries used to implement the SHA-1 and SHA-256 algorithms are displayed
+in the form `SHA-1: <option>` and `SHA-256: <option>`. Note that the SHA-1
+options `SHA1_APPLE`, `SHA1_OPENSSL`, and `SHA1_BLK` do not use a collision
+detection algorithm and thus may be vulnerable to known SHA-1 collision
+attacks.
 
 GIT
 ---
diff --git a/hash.h b/hash.h
index 4367acfec5..51cd0ec7b6 100644
--- a/hash.h
+++ b/hash.h
@@ -2,16 +2,20 @@
 #define HASH_H
 
 #if defined(SHA1_APPLE)
+#define SHA1_BACKEND "SHA1_APPLE (No collision detection)"
 #include <CommonCrypto/CommonDigest.h>
 #elif defined(SHA1_OPENSSL)
+#  define SHA1_BACKEND "SHA1_OPENSSL (No collision detection)"
 #  include <openssl/sha.h>
 #  if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
 #    define SHA1_NEEDS_CLONE_HELPER
 #    include "sha1/openssl.h"
 #  endif
 #elif defined(SHA1_DC)
+#define SHA1_BACKEND "SHA1_DC"
 #include "sha1dc_git.h"
 #else /* SHA1_BLK */
+#define SHA1_BACKEND "SHA1_BLK (No collision detection)"
 #include "block-sha1/sha1.h"
 #endif
 
@@ -46,17 +50,21 @@
 #endif
 
 #if defined(SHA256_NETTLE)
+#define SHA256_BACKEND "SHA256_NETTLE"
 #include "sha256/nettle.h"
 #elif defined(SHA256_GCRYPT)
+#define SHA256_BACKEND "SHA256_GCRYPT"
 #define SHA256_NEEDS_CLONE_HELPER
 #include "sha256/gcrypt.h"
 #elif defined(SHA256_OPENSSL)
+#  define SHA256_BACKEND "SHA256_OPENSSL"
 #  include <openssl/sha.h>
 #  if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
 #    define SHA256_NEEDS_CLONE_HELPER
 #    include "sha256/openssl.h"
 #  endif
 #else
+#define SHA256_BACKEND "SHA256_BLK"
 #include "sha256/block/sha256.h"
 #endif
 
diff --git a/help.c b/help.c
index c54bd9918a..991a9525db 100644
--- a/help.c
+++ b/help.c
@@ -9,6 +9,7 @@
 #include "run-command.h"
 #include "levenshtein.h"
 #include "gettext.h"
+#include "hash.h"
 #include "help.h"
 #include "command-list.h"
 #include "string-list.h"
@@ -803,6 +804,8 @@ void get_version_info(struct strbuf *buf, int show_build_options)
 #elif defined ZLIB_VERSION
 		strbuf_addf(buf, "zlib: %s\n", ZLIB_VERSION);
 #endif
+		strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
+		strbuf_addf(buf, "SHA-256: %s\n", SHA256_BACKEND);
 	}
 }
 
-- 
2.49.0
Previous: Justin ToblerNext: Justin Tobler
Message 23 of 27 in “help: include SHA build options in version info”
  1. 0/2 help: include SHA build options in version infoJustin Tobler, Mar 28, 2025
  2. 1/2 help: include SHA implementation in version infoJustin Tobler, Mar 28, 2025
  3. Junio C HamanoMar 29, 2025
  4. Patrick SteinhardtMar 31, 2025
  5. Justin ToblerMar 31, 2025
  6. Junio C HamanoApr 1, 2025
  7. Justin ToblerMar 31, 2025
  8. 2/2 help: include unsafe SHA-1 build info in versionJustin Tobler, Mar 28, 2025
  9. Christian CouderMar 29, 2025
  10. Christian CouderMar 29, 2025
  11. Justin ToblerMar 31, 2025
  12. 0/2 help: include SHA build options in version infoJustin Tobler, Apr 1, 2025
  13. 1/2 help: include SHA implementation in version infoJustin Tobler, Apr 1, 2025
  14. Patrick SteinhardtApr 2, 2025
  15. Christian CouderApr 2, 2025
  16. Christian CouderApr 2, 2025
  17. Justin ToblerApr 2, 2025
  18. 2/2 help: include unsafe SHA-1 build info in versionJustin Tobler, Apr 1, 2025
  19. Patrick SteinhardtApr 2, 2025
  20. Justin ToblerApr 2, 2025
  21. Patrick SteinhardtApr 3, 2025
  22. 0/2 help: include SHA build options in version infoJustin Tobler, Apr 3, 2025
  23. 1/2 help: include SHA implementation in version infoJustin Tobler, Apr 3, 2025
  24. 2/2 help: include unsafe SHA-1 build info in versionJustin Tobler, Apr 3, 2025
  25. Patrick SteinhardtApr 4, 2025
  26. Christian CouderApr 4, 2025
  27. Junio C HamanoApr 8, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.