Skip to content

Commit 16fd6c8

Browse files
jltoblergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 683c54c commit 16fd6c8

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Documentation/git-version.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ OPTIONS
2222
--build-options::
2323
Include additional information about how git was built for diagnostic
2424
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.
2531

2632
GIT
2733
---

hash.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
#define HASH_H
33

44
#if defined(SHA1_APPLE)
5+
#define SHA1_BACKEND "SHA1_APPLE (No collision detection)"
56
#include <CommonCrypto/CommonDigest.h>
67
#elif defined(SHA1_OPENSSL)
8+
# define SHA1_BACKEND "SHA1_OPENSSL (No collision detection)"
79
# include <openssl/sha.h>
810
# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
911
# define SHA1_NEEDS_CLONE_HELPER
1012
# include "sha1/openssl.h"
1113
# endif
1214
#elif defined(SHA1_DC)
15+
#define SHA1_BACKEND "SHA1_DC"
1316
#include "sha1dc_git.h"
1417
#else /* SHA1_BLK */
18+
#define SHA1_BACKEND "SHA1_BLK (No collision detection)"
1519
#include "block-sha1/sha1.h"
1620
#endif
1721

@@ -46,17 +50,21 @@
4650
#endif
4751

4852
#if defined(SHA256_NETTLE)
53+
#define SHA256_BACKEND "SHA256_NETTLE"
4954
#include "sha256/nettle.h"
5055
#elif defined(SHA256_GCRYPT)
56+
#define SHA256_BACKEND "SHA256_GCRYPT"
5157
#define SHA256_NEEDS_CLONE_HELPER
5258
#include "sha256/gcrypt.h"
5359
#elif defined(SHA256_OPENSSL)
60+
# define SHA256_BACKEND "SHA256_OPENSSL"
5461
# include <openssl/sha.h>
5562
# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
5663
# define SHA256_NEEDS_CLONE_HELPER
5764
# include "sha256/openssl.h"
5865
# endif
5966
#else
67+
#define SHA256_BACKEND "SHA256_BLK"
6068
#include "sha256/block/sha256.h"
6169
#endif
6270

help.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "run-command.h"
1010
#include "levenshtein.h"
1111
#include "gettext.h"
12+
#include "hash.h"
1213
#include "help.h"
1314
#include "command-list.h"
1415
#include "string-list.h"
@@ -803,6 +804,8 @@ void get_version_info(struct strbuf *buf, int show_build_options)
803804
#elif defined ZLIB_VERSION
804805
strbuf_addf(buf, "zlib: %s\n", ZLIB_VERSION);
805806
#endif
807+
strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
808+
strbuf_addf(buf, "SHA-256: %s\n", SHA256_BACKEND);
806809
}
807810
}
808811

0 commit comments

Comments
 (0)