Skip to content

Commit 8f490db

Browse files
committed
Merge branch 'jt/help-sha-backend-info-in-build-options'
"git help --build-options" reports SHA-1 and SHA-256 backends used in the build. * jt/help-sha-backend-info-in-build-options: help: include unsafe SHA-1 build info in version help: include SHA implementation in version info
2 parents 4747880 + 6cf6544 commit 8f490db

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Documentation/git-version.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ 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. When a faster SHA-1 implementation without collision detection is used
31+
for only non-cryptographic purposes, the algorithm is displayed in the form
32+
`non-collision-detecting-SHA-1: <option>`.
2533

2634
GIT
2735
---

hash.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,32 @@
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

1822
#if defined(SHA1_APPLE_UNSAFE)
23+
# define SHA1_UNSAFE_BACKEND "SHA1_APPLE_UNSAFE"
1924
# include <CommonCrypto/CommonDigest.h>
2025
# define platform_SHA_CTX_unsafe CC_SHA1_CTX
2126
# define platform_SHA1_Init_unsafe CC_SHA1_Init
2227
# define platform_SHA1_Update_unsafe CC_SHA1_Update
2328
# define platform_SHA1_Final_unsafe CC_SHA1_Final
2429
#elif defined(SHA1_OPENSSL_UNSAFE)
30+
# define SHA1_UNSAFE_BACKEND "SHA1_OPENSSL_UNSAFE"
2531
# include <openssl/sha.h>
2632
# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
2733
# define SHA1_NEEDS_CLONE_HELPER_UNSAFE
@@ -38,6 +44,7 @@
3844
# define platform_SHA1_Final_unsafe SHA1_Final
3945
# endif
4046
#elif defined(SHA1_BLK_UNSAFE)
47+
# define SHA1_UNSAFE_BACKEND "SHA1_BLK_UNSAFE"
4148
# include "block-sha1/sha1.h"
4249
# define platform_SHA_CTX_unsafe blk_SHA_CTX
4350
# define platform_SHA1_Init_unsafe blk_SHA1_Init
@@ -46,17 +53,21 @@
4653
#endif
4754

4855
#if defined(SHA256_NETTLE)
56+
#define SHA256_BACKEND "SHA256_NETTLE"
4957
#include "sha256/nettle.h"
5058
#elif defined(SHA256_GCRYPT)
59+
#define SHA256_BACKEND "SHA256_GCRYPT"
5160
#define SHA256_NEEDS_CLONE_HELPER
5261
#include "sha256/gcrypt.h"
5362
#elif defined(SHA256_OPENSSL)
63+
# define SHA256_BACKEND "SHA256_OPENSSL"
5464
# include <openssl/sha.h>
5565
# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
5666
# define SHA256_NEEDS_CLONE_HELPER
5767
# include "sha256/openssl.h"
5868
# endif
5969
#else
70+
#define SHA256_BACKEND "SHA256_BLK"
6071
#include "sha256/block/sha256.h"
6172
#endif
6273

help.c

Lines changed: 7 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,12 @@ 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+
#if defined SHA1_UNSAFE_BACKEND
809+
strbuf_addf(buf, "non-collision-detecting-SHA-1: %s\n",
810+
SHA1_UNSAFE_BACKEND);
811+
#endif
812+
strbuf_addf(buf, "SHA-256: %s\n", SHA256_BACKEND);
806813
}
807814
}
808815

0 commit comments

Comments
 (0)