* [PATCH v2 1/2] help: include SHA implementation in version info
2025-04-01 20:36 ` [PATCH v2 " Justin Tobler
@ 2025-04-01 20:36 ` Justin Tobler
2025-04-02 7:38 ` Patrick Steinhardt
2025-04-01 20:36 ` [PATCH v2 2/2] help: include unsafe SHA-1 build info in version Justin Tobler
2025-04-03 14:05 ` [PATCH v3 0/2] help: include SHA build options in version info Justin Tobler
2 siblings, 1 reply; 27+ messages in thread
From: Justin Tobler @ 2025-04-01 20:36 UTC (permalink / raw)
To: git; +Cc: christian.couder, ps, Justin Tobler
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 | 3 +++
hash.h | 8 ++++++++
help.c | 8 ++++++++
3 files changed, 19 insertions(+)
diff --git a/Documentation/git-version.adoc b/Documentation/git-version.adoc
index 80fa7754a6..f06758a7cf 100644
--- a/Documentation/git-version.adoc
+++ b/Documentation/git-version.adoc
@@ -22,6 +22,9 @@ OPTIONS
--build-options::
Include additional information about how git was built for diagnostic
purposes.
++
+Note that the SHA1 options `SHA1_APPLE`, `SHA1_OPENSSL`, and `SHA1_BLK` do not
+have collision detection.
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..3aebfb3681 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"
@@ -768,6 +769,12 @@ char *help_unknown_cmd(const char *cmd)
exit(1);
}
+static void get_sha_impl(struct strbuf *buf)
+{
+ strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
+ strbuf_addf(buf, "SHA-256: %s\n", SHA256_BACKEND);
+}
+
void get_version_info(struct strbuf *buf, int show_build_options)
{
/*
@@ -803,6 +810,7 @@ void get_version_info(struct strbuf *buf, int show_build_options)
#elif defined ZLIB_VERSION
strbuf_addf(buf, "zlib: %s\n", ZLIB_VERSION);
#endif
+ get_sha_impl(buf);
}
}
--
2.49.0
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v2 1/2] help: include SHA implementation in version info
2025-04-01 20:36 ` [PATCH v2 1/2] help: include SHA implementation " Justin Tobler
@ 2025-04-02 7:38 ` Patrick Steinhardt
2025-04-02 11:26 ` Christian Couder
0 siblings, 1 reply; 27+ messages in thread
From: Patrick Steinhardt @ 2025-04-02 7:38 UTC (permalink / raw)
To: Justin Tobler; +Cc: git, christian.couder
On Tue, Apr 01, 2025 at 03:36:29PM -0500, Justin Tobler wrote:
> diff --git a/Documentation/git-version.adoc b/Documentation/git-version.adoc
> index 80fa7754a6..f06758a7cf 100644
> --- a/Documentation/git-version.adoc
> +++ b/Documentation/git-version.adoc
> @@ -22,6 +22,9 @@ OPTIONS
> --build-options::
> Include additional information about how git was built for diagnostic
> purposes.
> ++
> +Note that the SHA1 options `SHA1_APPLE`, `SHA1_OPENSSL`, and `SHA1_BLK` do not
> +have collision detection.
>
> GIT
> ---
I think this note is somewhat funny for an unsuspecting reader. On the
one hand they're going to be puzzled why you're talking about SHA1 in
the first place because it isn't mentioned at all beforehand. And on the
other hand they will wonder what collision detection even is in the
first place.
So I would either drop this paragraph completely or expand it to give a
bit more context.
> 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
>
This feels way less fragile indeed, thanks for adapting.
> diff --git a/help.c b/help.c
> index c54bd9918a..3aebfb3681 100644
> --- a/help.c
> +++ b/help.c
> @@ -768,6 +769,12 @@ char *help_unknown_cmd(const char *cmd)
> exit(1);
> }
>
> +static void get_sha_impl(struct strbuf *buf)
> +{
> + strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
> + strbuf_addf(buf, "SHA-256: %s\n", SHA256_BACKEND);
> +}
> +
> void get_version_info(struct strbuf *buf, int show_build_options)
> {
> /*
> @@ -803,6 +810,7 @@ void get_version_info(struct strbuf *buf, int show_build_options)
> #elif defined ZLIB_VERSION
> strbuf_addf(buf, "zlib: %s\n", ZLIB_VERSION);
> #endif
> + get_sha_impl(buf);
I don't quite see the need for a new function, but don't mind it too
much, either.
Patrick
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 1/2] help: include SHA implementation in version info
2025-04-02 7:38 ` Patrick Steinhardt
@ 2025-04-02 11:26 ` Christian Couder
2025-04-02 11:27 ` Christian Couder
2025-04-02 14:56 ` Justin Tobler
0 siblings, 2 replies; 27+ messages in thread
From: Christian Couder @ 2025-04-02 11:26 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Justin Tobler, git
On Wed, Apr 2, 2025 at 9:38 AM Patrick Steinhardt <ps@pks.im> wrote:
>
> On Tue, Apr 01, 2025 at 03:36:29PM -0500, Justin Tobler wrote:
> > diff --git a/Documentation/git-version.adoc b/Documentation/git-version.adoc
> > index 80fa7754a6..f06758a7cf 100644
> > --- a/Documentation/git-version.adoc
> > +++ b/Documentation/git-version.adoc
> > @@ -22,6 +22,9 @@ OPTIONS
> > --build-options::
> > Include additional information about how git was built for diagnostic
> > purposes.
> > ++
> > +Note that the SHA1 options `SHA1_APPLE`, `SHA1_OPENSSL`, and `SHA1_BLK` do not
> > +have collision detection.
>
> I think this note is somewhat funny for an unsuspecting reader. On the
> one hand they're going to be puzzled why you're talking about SHA1 in
> the first place because it isn't mentioned at all beforehand. And on the
> other hand they will wonder what collision detection even is in the
> first place.
>
> So I would either drop this paragraph completely or expand it to give a
> bit more context.
Yeah, I think it's worth giving more information, like perhaps:
"For the libraries used to implement the SHA-1 and SHA-2 algorithms
only symbolic information, like `SHA-1: SHA1_APPLE` or `SHA-256:
SHA256_NETTLE` is displayed. Note that the SHA1 options `SHA1_APPLE`,
`SHA1_OPENSSL`, and `SHA1_BLK` mean that no collision detection
algorithm is used, so known SHA-1 attacks might be possible, see
https://en.wikipedia.org/wiki/SHA-1."
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 1/2] help: include SHA implementation in version info
2025-04-02 11:26 ` Christian Couder
@ 2025-04-02 11:27 ` Christian Couder
2025-04-02 14:56 ` Justin Tobler
1 sibling, 0 replies; 27+ messages in thread
From: Christian Couder @ 2025-04-02 11:27 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Justin Tobler, git
On Wed, Apr 2, 2025 at 1:26 PM Christian Couder
<christian.couder@gmail.com> wrote:
>
> On Wed, Apr 2, 2025 at 9:38 AM Patrick Steinhardt <ps@pks.im> wrote:
> >
> > On Tue, Apr 01, 2025 at 03:36:29PM -0500, Justin Tobler wrote:
> > > diff --git a/Documentation/git-version.adoc b/Documentation/git-version.adoc
> > > index 80fa7754a6..f06758a7cf 100644
> > > --- a/Documentation/git-version.adoc
> > > +++ b/Documentation/git-version.adoc
> > > @@ -22,6 +22,9 @@ OPTIONS
> > > --build-options::
> > > Include additional information about how git was built for diagnostic
> > > purposes.
> > > ++
> > > +Note that the SHA1 options `SHA1_APPLE`, `SHA1_OPENSSL`, and `SHA1_BLK` do not
> > > +have collision detection.
> >
> > I think this note is somewhat funny for an unsuspecting reader. On the
> > one hand they're going to be puzzled why you're talking about SHA1 in
> > the first place because it isn't mentioned at all beforehand. And on the
> > other hand they will wonder what collision detection even is in the
> > first place.
> >
> > So I would either drop this paragraph completely or expand it to give a
> > bit more context.
>
> Yeah, I think it's worth giving more information, like perhaps:
>
> "For the libraries used to implement the SHA-1 and SHA-2 algorithms
s/SHA-2/SHA-256/
> only symbolic information, like `SHA-1: SHA1_APPLE` or `SHA-256:
> SHA256_NETTLE` is displayed. Note that the SHA1 options `SHA1_APPLE`,
> `SHA1_OPENSSL`, and `SHA1_BLK` mean that no collision detection
> algorithm is used, so known SHA-1 attacks might be possible, see
> https://en.wikipedia.org/wiki/SHA-1."
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 1/2] help: include SHA implementation in version info
2025-04-02 11:26 ` Christian Couder
2025-04-02 11:27 ` Christian Couder
@ 2025-04-02 14:56 ` Justin Tobler
1 sibling, 0 replies; 27+ messages in thread
From: Justin Tobler @ 2025-04-02 14:56 UTC (permalink / raw)
To: Christian Couder; +Cc: Patrick Steinhardt, git
On 25/04/02 01:26PM, Christian Couder wrote:
> On Wed, Apr 2, 2025 at 9:38 AM Patrick Steinhardt <ps@pks.im> wrote:
> >
> > On Tue, Apr 01, 2025 at 03:36:29PM -0500, Justin Tobler wrote:
> > > diff --git a/Documentation/git-version.adoc b/Documentation/git-version.adoc
> > > index 80fa7754a6..f06758a7cf 100644
> > > --- a/Documentation/git-version.adoc
> > > +++ b/Documentation/git-version.adoc
> > > @@ -22,6 +22,9 @@ OPTIONS
> > > --build-options::
> > > Include additional information about how git was built for diagnostic
> > > purposes.
> > > ++
> > > +Note that the SHA1 options `SHA1_APPLE`, `SHA1_OPENSSL`, and `SHA1_BLK` do not
> > > +have collision detection.
> >
> > I think this note is somewhat funny for an unsuspecting reader. On the
> > one hand they're going to be puzzled why you're talking about SHA1 in
> > the first place because it isn't mentioned at all beforehand. And on the
> > other hand they will wonder what collision detection even is in the
> > first place.
> >
> > So I would either drop this paragraph completely or expand it to give a
> > bit more context.
>
> Yeah, I think it's worth giving more information, like perhaps:
>
> "For the libraries used to implement the SHA-1 and SHA-2 algorithms
> only symbolic information, like `SHA-1: SHA1_APPLE` or `SHA-256:
> SHA256_NETTLE` is displayed. Note that the SHA1 options `SHA1_APPLE`,
> `SHA1_OPENSSL`, and `SHA1_BLK` mean that no collision detection
> algorithm is used, so known SHA-1 attacks might be possible, see
> https://en.wikipedia.org/wiki/SHA-1."
Ya the documentation here should be expanded to provide some more
context. I'll adapt in my next version to something like this:
"The libraries used to implement the SHA-1 and SHA-256 algorithms are
displayed in the form `SHA-1: <option>` and `SHA-256: <option>`
respectively. 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."
-Justin
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 2/2] help: include unsafe SHA-1 build info in version
2025-04-01 20:36 ` [PATCH v2 " Justin Tobler
2025-04-01 20:36 ` [PATCH v2 1/2] help: include SHA implementation " Justin Tobler
@ 2025-04-01 20:36 ` Justin Tobler
2025-04-02 7:38 ` Patrick Steinhardt
2025-04-03 14:05 ` [PATCH v3 0/2] help: include SHA build options in version info Justin Tobler
2 siblings, 1 reply; 27+ messages in thread
From: Justin Tobler @ 2025-04-01 20:36 UTC (permalink / raw)
To: git; +Cc: christian.couder, ps, Justin Tobler
In 06c92dafb8 (Makefile: allow specifying a SHA-1 for non-cryptographic
uses, 2024-09-26), support for unsafe SHA-1 is added. Add the unsafe
SHA-1 build info to `git version --build-info` and update corresponding
documentation.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
Documentation/git-version.adoc | 3 +++
hash.h | 3 +++
help.c | 5 +++++
3 files changed, 11 insertions(+)
diff --git a/Documentation/git-version.adoc b/Documentation/git-version.adoc
index f06758a7cf..753794988c 100644
--- a/Documentation/git-version.adoc
+++ b/Documentation/git-version.adoc
@@ -25,6 +25,9 @@ OPTIONS
+
Note that the SHA1 options `SHA1_APPLE`, `SHA1_OPENSSL`, and `SHA1_BLK` do not
have collision detection.
++
+If built to use a faster SHA-1 implementation for non-cryptographic purposes,
+that implementation is denoted as "non-crypto-SHA-1".
GIT
---
diff --git a/hash.h b/hash.h
index 51cd0ec7b6..72334d3506 100644
--- a/hash.h
+++ b/hash.h
@@ -20,12 +20,14 @@
#endif
#if defined(SHA1_APPLE_UNSAFE)
+# define SHA1_UNSAFE_BACKEND "SHA1_APPLE_UNSAFE"
# include <CommonCrypto/CommonDigest.h>
# define platform_SHA_CTX_unsafe CC_SHA1_CTX
# define platform_SHA1_Init_unsafe CC_SHA1_Init
# define platform_SHA1_Update_unsafe CC_SHA1_Update
# define platform_SHA1_Final_unsafe CC_SHA1_Final
#elif defined(SHA1_OPENSSL_UNSAFE)
+# define SHA1_UNSAFE_BACKEND "SHA1_OPENSSL_UNSAFE"
# include <openssl/sha.h>
# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
# define SHA1_NEEDS_CLONE_HELPER_UNSAFE
@@ -42,6 +44,7 @@
# define platform_SHA1_Final_unsafe SHA1_Final
# endif
#elif defined(SHA1_BLK_UNSAFE)
+# define SHA1_UNSAFE_BACKEND "SHA1_BLK_UNSAFE"
# include "block-sha1/sha1.h"
# define platform_SHA_CTX_unsafe blk_SHA_CTX
# define platform_SHA1_Init_unsafe blk_SHA1_Init
diff --git a/help.c b/help.c
index 3aebfb3681..1238a962b0 100644
--- a/help.c
+++ b/help.c
@@ -772,6 +772,11 @@ char *help_unknown_cmd(const char *cmd)
static void get_sha_impl(struct strbuf *buf)
{
strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
+
+#if defined(SHA1_UNSAFE_BACKEND)
+ strbuf_addf(buf, "non-crypto-SHA-1: %s\n", SHA1_UNSAFE_BACKEND);
+#endif
+
strbuf_addf(buf, "SHA-256: %s\n", SHA256_BACKEND);
}
--
2.49.0
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v2 2/2] help: include unsafe SHA-1 build info in version
2025-04-01 20:36 ` [PATCH v2 2/2] help: include unsafe SHA-1 build info in version Justin Tobler
@ 2025-04-02 7:38 ` Patrick Steinhardt
2025-04-02 15:59 ` Justin Tobler
0 siblings, 1 reply; 27+ messages in thread
From: Patrick Steinhardt @ 2025-04-02 7:38 UTC (permalink / raw)
To: Justin Tobler; +Cc: git, christian.couder
On Tue, Apr 01, 2025 at 03:36:30PM -0500, Justin Tobler wrote:
> diff --git a/Documentation/git-version.adoc b/Documentation/git-version.adoc
> index f06758a7cf..753794988c 100644
> --- a/Documentation/git-version.adoc
> +++ b/Documentation/git-version.adoc
> @@ -25,6 +25,9 @@ OPTIONS
> +
> Note that the SHA1 options `SHA1_APPLE`, `SHA1_OPENSSL`, and `SHA1_BLK` do not
> have collision detection.
> ++
> +If built to use a faster SHA-1 implementation for non-cryptographic purposes,
> +that implementation is denoted as "non-crypto-SHA-1".
>
> GIT
> ---
I got basically the same comment for this new paragraph as for the first
one. I'd either drop it or expand it so that readers know what's going
on.
> diff --git a/help.c b/help.c
> index 3aebfb3681..1238a962b0 100644
> --- a/help.c
> +++ b/help.c
> @@ -772,6 +772,11 @@ char *help_unknown_cmd(const char *cmd)
> static void get_sha_impl(struct strbuf *buf)
> {
> strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
> +
> +#if defined(SHA1_UNSAFE_BACKEND)
> + strbuf_addf(buf, "non-crypto-SHA-1: %s\n", SHA1_UNSAFE_BACKEND);
> +#endif
> +
Should we maybe print the equivalent of "none" in case no unsafe backend
was selected?
I also think we shouldn't name this "non-crypto". The backend still is
SHA1, which is a proper cryptogtaphic hash function. It may be somewhat
broken nowadays, but that doesn't change the fact that it's a
cryptographic primitive.
How about we rename this to "SHA-1 without collision detection:"?
Patrick
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 2/2] help: include unsafe SHA-1 build info in version
2025-04-02 7:38 ` Patrick Steinhardt
@ 2025-04-02 15:59 ` Justin Tobler
2025-04-03 5:10 ` Patrick Steinhardt
0 siblings, 1 reply; 27+ messages in thread
From: Justin Tobler @ 2025-04-02 15:59 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, christian.couder
On 25/04/02 09:38AM, Patrick Steinhardt wrote:
> On Tue, Apr 01, 2025 at 03:36:30PM -0500, Justin Tobler wrote:
> > diff --git a/Documentation/git-version.adoc b/Documentation/git-version.adoc
> > index f06758a7cf..753794988c 100644
> > --- a/Documentation/git-version.adoc
> > +++ b/Documentation/git-version.adoc
> > @@ -25,6 +25,9 @@ OPTIONS
> > +
> > Note that the SHA1 options `SHA1_APPLE`, `SHA1_OPENSSL`, and `SHA1_BLK` do not
> > have collision detection.
> > ++
> > +If built to use a faster SHA-1 implementation for non-cryptographic purposes,
> > +that implementation is denoted as "non-crypto-SHA-1".
> >
> > GIT
> > ---
>
> I got basically the same comment for this new paragraph as for the first
> one. I'd either drop it or expand it so that readers know what's going
> on.
Ya, this should also be expanded a bit. I think in combination with the
expanded documentation for the prior patch, something like this might be
a bit better.
"When a faster SHA-1 implementation without collision detection is used
for only non-cryptographic purposes, the algorithm is diplayed in the form
`non-collision-detecting-SHA-1: <option>`."
> > diff --git a/help.c b/help.c
> > index 3aebfb3681..1238a962b0 100644
> > --- a/help.c
> > +++ b/help.c
> > @@ -772,6 +772,11 @@ char *help_unknown_cmd(const char *cmd)
> > static void get_sha_impl(struct strbuf *buf)
> > {
> > strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
> > +
> > +#if defined(SHA1_UNSAFE_BACKEND)
> > + strbuf_addf(buf, "non-crypto-SHA-1: %s\n", SHA1_UNSAFE_BACKEND);
> > +#endif
> > +
>
> Should we maybe print the equivalent of "none" in case no unsafe backend
> was selected?
It is suggested later to rename "non-crypto-SHA-1" to "SHA-1 without
collision detection", which could lead to something like this:
SHA-1: SHA1_OPENSSL (No collision detection)
SHA-1 without collision detection: none
which could be a bit misleading IMO. It might be best to leave the
option omitted if it is not defined.
> I also think we shouldn't name this "non-crypto". The backend still is
> SHA1, which is a proper cryptogtaphic hash function. It may be somewhat
> broken nowadays, but that doesn't change the fact that it's a
> cryptographic primitive.
I was trying to indicate that this SHA-1 backend was used only in
non-cryptographic scenarios, but I agree that this name is not great.
Calling it "SHA-1 used for non-cryptographic purposes" is a bit of a
mouthful, but maybe that is fine?
Another idea I had was to call it "fast-SHA-1:" since it's intended as a
performance optimization used in certain cases.
> How about we rename this to "SHA-1 without collision detection:"?
Being verbose here is probably best. I'll probably use something like
"non-collision-detecting-SHA-1:" in the next version.
-Justin
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 2/2] help: include unsafe SHA-1 build info in version
2025-04-02 15:59 ` Justin Tobler
@ 2025-04-03 5:10 ` Patrick Steinhardt
0 siblings, 0 replies; 27+ messages in thread
From: Patrick Steinhardt @ 2025-04-03 5:10 UTC (permalink / raw)
To: Justin Tobler; +Cc: git, christian.couder
On Wed, Apr 02, 2025 at 10:59:16AM -0500, Justin Tobler wrote:
> On 25/04/02 09:38AM, Patrick Steinhardt wrote:
> > On Tue, Apr 01, 2025 at 03:36:30PM -0500, Justin Tobler wrote:
> > > diff --git a/help.c b/help.c
> > > index 3aebfb3681..1238a962b0 100644
> > > --- a/help.c
> > > +++ b/help.c
> > > @@ -772,6 +772,11 @@ char *help_unknown_cmd(const char *cmd)
> > > static void get_sha_impl(struct strbuf *buf)
> > > {
> > > strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
> > > +
> > > +#if defined(SHA1_UNSAFE_BACKEND)
> > > + strbuf_addf(buf, "non-crypto-SHA-1: %s\n", SHA1_UNSAFE_BACKEND);
> > > +#endif
> > > +
> >
> > Should we maybe print the equivalent of "none" in case no unsafe backend
> > was selected?
>
> It is suggested later to rename "non-crypto-SHA-1" to "SHA-1 without
> collision detection", which could lead to something like this:
>
> SHA-1: SHA1_OPENSSL (No collision detection)
> SHA-1 without collision detection: none
>
> which could be a bit misleading IMO. It might be best to leave the
> option omitted if it is not defined.
The problem of leaving the info away entirely is that it also makes it
undiscoverable. Anyway -- I think it would be nice to always print this
line and improve the format a bit to make it less awkward, but I won't
resist if you decide to leave it as-is. After all we're already showing
strictly more information than before, so it's a net win regardless.
Patrick
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v3 0/2] help: include SHA build options in version info
2025-04-01 20:36 ` [PATCH v2 " Justin Tobler
2025-04-01 20:36 ` [PATCH v2 1/2] help: include SHA implementation " Justin Tobler
2025-04-01 20:36 ` [PATCH v2 2/2] help: include unsafe SHA-1 build info in version Justin Tobler
@ 2025-04-03 14:05 ` Justin Tobler
2025-04-03 14:05 ` [PATCH v3 1/2] help: include SHA implementation " Justin Tobler
` (2 more replies)
2 siblings, 3 replies; 27+ messages in thread
From: Justin Tobler @ 2025-04-03 14:05 UTC (permalink / raw)
To: git; +Cc: christian.couder, ps, Justin Tobler
Greetings,
Additional information regarding how Git was built can be found via the
`--build-options` flag for git-version(1). This currently does not
include information about the SHA-1 and SHA-256 implementations Git is
built with.
This short series adds build option info for the SHA-1, SHA-256, and
non-crypto-SHA-1 (if any) implementations which may be useful for
diagnostic purposes
Changes since V2:
- Updates to documentation to provide additional context.
- Inlined `get_sha_impl()` function.
Changes since V1:
- Each SHA backend is expected to define either `SHA1_BACKEND`,
`SHA1_UNSAFE_BACKEND`, or `SHA256_BACKEND` as appropriate.
These symbols are then used to print the SHA build options in
the additional version info.
- The names of the build options are used instead of
human-readable names.
- Appended "(No collision detection)" to warn about SHA1
backends without collision detection.
- Renamed "unsafe-SHA-1" to "non-crypto-SHA-1" in the printed
build options.
- Small updates to documentation.
Thanks,
-Justin
Justin Tobler (2):
help: include SHA implementation in version info
help: include unsafe SHA-1 build info in version
Documentation/git-version.adoc | 8 ++++++++
hash.h | 11 +++++++++++
help.c | 7 +++++++
3 files changed, 26 insertions(+)
Range-diff against v2:
1: aa0f464c52 ! 1: b01e5a18cb help: include SHA implementation in version info
@@ Documentation/git-version.adoc: OPTIONS
Include additional information about how git was built for diagnostic
purposes.
++
-+Note that the SHA1 options `SHA1_APPLE`, `SHA1_OPENSSL`, and `SHA1_BLK` do not
-+have collision detection.
++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
---
@@ help.c
#include "help.h"
#include "command-list.h"
#include "string-list.h"
-@@ help.c: char *help_unknown_cmd(const char *cmd)
- exit(1);
- }
-
-+static void get_sha_impl(struct strbuf *buf)
-+{
-+ strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
-+ strbuf_addf(buf, "SHA-256: %s\n", SHA256_BACKEND);
-+}
-+
- void get_version_info(struct strbuf *buf, int show_build_options)
- {
- /*
@@ help.c: void get_version_info(struct strbuf *buf, int show_build_options)
#elif defined ZLIB_VERSION
strbuf_addf(buf, "zlib: %s\n", ZLIB_VERSION);
#endif
-+ get_sha_impl(buf);
++ strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
++ strbuf_addf(buf, "SHA-256: %s\n", SHA256_BACKEND);
}
}
2: 95c92a05df ! 2: cf33e4ac9e help: include unsafe SHA-1 build info in version
@@ Commit message
Signed-off-by: Justin Tobler <jltobler@gmail.com>
## Documentation/git-version.adoc ##
-@@ Documentation/git-version.adoc: OPTIONS
- +
- Note that the SHA1 options `SHA1_APPLE`, `SHA1_OPENSSL`, and `SHA1_BLK` do not
- have collision detection.
-++
-+If built to use a faster SHA-1 implementation for non-cryptographic purposes,
-+that implementation is denoted as "non-crypto-SHA-1".
+@@ Documentation/git-version.adoc: 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.
++attacks. When a faster SHA-1 implementation without collision detection is used
++for only non-cryptographic purposes, the algorithm is displayed in the form
++`non-collision-detecting-SHA-1: <option>`.
GIT
---
@@ hash.h
# define platform_SHA1_Init_unsafe blk_SHA1_Init
## help.c ##
-@@ help.c: char *help_unknown_cmd(const char *cmd)
- static void get_sha_impl(struct strbuf *buf)
- {
- strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
-+
-+#if defined(SHA1_UNSAFE_BACKEND)
-+ strbuf_addf(buf, "non-crypto-SHA-1: %s\n", SHA1_UNSAFE_BACKEND);
+@@ help.c: void get_version_info(struct strbuf *buf, int show_build_options)
+ strbuf_addf(buf, "zlib: %s\n", ZLIB_VERSION);
+ #endif
+ strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
++#if defined SHA1_UNSAFE_BACKEND
++ strbuf_addf(buf, "non-collision-detecting-SHA-1: %s\n",
++ SHA1_UNSAFE_BACKEND);
+#endif
-+
- strbuf_addf(buf, "SHA-256: %s\n", SHA256_BACKEND);
+ strbuf_addf(buf, "SHA-256: %s\n", SHA256_BACKEND);
+ }
}
-
base-commit: 683c54c999c301c2cd6f715c411407c413b1d84e
--
2.49.0
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v3 1/2] help: include SHA implementation in version info
2025-04-03 14:05 ` [PATCH v3 0/2] help: include SHA build options in version info Justin Tobler
@ 2025-04-03 14:05 ` Justin Tobler
2025-04-03 14:05 ` [PATCH v3 2/2] help: include unsafe SHA-1 build info in version Justin Tobler
2025-04-04 9:20 ` [PATCH v3 0/2] help: include SHA build options in version info Patrick Steinhardt
2 siblings, 0 replies; 27+ messages in thread
From: Justin Tobler @ 2025-04-03 14:05 UTC (permalink / raw)
To: git; +Cc: christian.couder, ps, Justin Tobler
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
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v3 2/2] help: include unsafe SHA-1 build info in version
2025-04-03 14:05 ` [PATCH v3 0/2] help: include SHA build options in version info Justin Tobler
2025-04-03 14:05 ` [PATCH v3 1/2] help: include SHA implementation " Justin Tobler
@ 2025-04-03 14:05 ` Justin Tobler
2025-04-04 9:20 ` [PATCH v3 0/2] help: include SHA build options in version info Patrick Steinhardt
2 siblings, 0 replies; 27+ messages in thread
From: Justin Tobler @ 2025-04-03 14:05 UTC (permalink / raw)
To: git; +Cc: christian.couder, ps, Justin Tobler
In 06c92dafb8 (Makefile: allow specifying a SHA-1 for non-cryptographic
uses, 2024-09-26), support for unsafe SHA-1 is added. Add the unsafe
SHA-1 build info to `git version --build-info` and update corresponding
documentation.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
Documentation/git-version.adoc | 4 +++-
hash.h | 3 +++
help.c | 4 ++++
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/Documentation/git-version.adoc b/Documentation/git-version.adoc
index 913ebf147d..9462043a14 100644
--- a/Documentation/git-version.adoc
+++ b/Documentation/git-version.adoc
@@ -27,7 +27,9 @@ 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.
+attacks. When a faster SHA-1 implementation without collision detection is used
+for only non-cryptographic purposes, the algorithm is displayed in the form
+`non-collision-detecting-SHA-1: <option>`.
GIT
---
diff --git a/hash.h b/hash.h
index 51cd0ec7b6..72334d3506 100644
--- a/hash.h
+++ b/hash.h
@@ -20,12 +20,14 @@
#endif
#if defined(SHA1_APPLE_UNSAFE)
+# define SHA1_UNSAFE_BACKEND "SHA1_APPLE_UNSAFE"
# include <CommonCrypto/CommonDigest.h>
# define platform_SHA_CTX_unsafe CC_SHA1_CTX
# define platform_SHA1_Init_unsafe CC_SHA1_Init
# define platform_SHA1_Update_unsafe CC_SHA1_Update
# define platform_SHA1_Final_unsafe CC_SHA1_Final
#elif defined(SHA1_OPENSSL_UNSAFE)
+# define SHA1_UNSAFE_BACKEND "SHA1_OPENSSL_UNSAFE"
# include <openssl/sha.h>
# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
# define SHA1_NEEDS_CLONE_HELPER_UNSAFE
@@ -42,6 +44,7 @@
# define platform_SHA1_Final_unsafe SHA1_Final
# endif
#elif defined(SHA1_BLK_UNSAFE)
+# define SHA1_UNSAFE_BACKEND "SHA1_BLK_UNSAFE"
# include "block-sha1/sha1.h"
# define platform_SHA_CTX_unsafe blk_SHA_CTX
# define platform_SHA1_Init_unsafe blk_SHA1_Init
diff --git a/help.c b/help.c
index 991a9525db..6ef90838f1 100644
--- a/help.c
+++ b/help.c
@@ -805,6 +805,10 @@ void get_version_info(struct strbuf *buf, int show_build_options)
strbuf_addf(buf, "zlib: %s\n", ZLIB_VERSION);
#endif
strbuf_addf(buf, "SHA-1: %s\n", SHA1_BACKEND);
+#if defined SHA1_UNSAFE_BACKEND
+ strbuf_addf(buf, "non-collision-detecting-SHA-1: %s\n",
+ SHA1_UNSAFE_BACKEND);
+#endif
strbuf_addf(buf, "SHA-256: %s\n", SHA256_BACKEND);
}
}
--
2.49.0
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v3 0/2] help: include SHA build options in version info
2025-04-03 14:05 ` [PATCH v3 0/2] help: include SHA build options in version info Justin Tobler
2025-04-03 14:05 ` [PATCH v3 1/2] help: include SHA implementation " Justin Tobler
2025-04-03 14:05 ` [PATCH v3 2/2] help: include unsafe SHA-1 build info in version Justin Tobler
@ 2025-04-04 9:20 ` Patrick Steinhardt
2025-04-04 11:06 ` Christian Couder
2 siblings, 1 reply; 27+ messages in thread
From: Patrick Steinhardt @ 2025-04-04 9:20 UTC (permalink / raw)
To: Justin Tobler; +Cc: git, christian.couder
On Thu, Apr 03, 2025 at 09:05:27AM -0500, Justin Tobler wrote:
> Greetings,
>
> Additional information regarding how Git was built can be found via the
> `--build-options` flag for git-version(1). This currently does not
> include information about the SHA-1 and SHA-256 implementations Git is
> built with.
>
> This short series adds build option info for the SHA-1, SHA-256, and
> non-crypto-SHA-1 (if any) implementations which may be useful for
> diagnostic purposes
>
> Changes since V2:
>
> - Updates to documentation to provide additional context.
>
> - Inlined `get_sha_impl()` function.
Thanks, I'm happy with this version.
Patrick
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v3 0/2] help: include SHA build options in version info
2025-04-04 9:20 ` [PATCH v3 0/2] help: include SHA build options in version info Patrick Steinhardt
@ 2025-04-04 11:06 ` Christian Couder
2025-04-08 0:33 ` Junio C Hamano
0 siblings, 1 reply; 27+ messages in thread
From: Christian Couder @ 2025-04-04 11:06 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Justin Tobler, git
On Fri, Apr 4, 2025 at 11:20 AM Patrick Steinhardt <ps@pks.im> wrote:
>
> On Thu, Apr 03, 2025 at 09:05:27AM -0500, Justin Tobler wrote:
> > Greetings,
> >
> > Additional information regarding how Git was built can be found via the
> > `--build-options` flag for git-version(1). This currently does not
> > include information about the SHA-1 and SHA-256 implementations Git is
> > built with.
> >
> > This short series adds build option info for the SHA-1, SHA-256, and
> > non-crypto-SHA-1 (if any) implementations which may be useful for
> > diagnostic purposes
> >
> > Changes since V2:
> >
> > - Updates to documentation to provide additional context.
> >
> > - Inlined `get_sha_impl()` function.
>
> Thanks, I'm happy with this version.
I am fine with it as well. Thanks.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v3 0/2] help: include SHA build options in version info
2025-04-04 11:06 ` Christian Couder
@ 2025-04-08 0:33 ` Junio C Hamano
0 siblings, 0 replies; 27+ messages in thread
From: Junio C Hamano @ 2025-04-08 0:33 UTC (permalink / raw)
To: Christian Couder; +Cc: Patrick Steinhardt, Justin Tobler, git
Christian Couder <christian.couder@gmail.com> writes:
> On Fri, Apr 4, 2025 at 11:20 AM Patrick Steinhardt <ps@pks.im> wrote:
>>
>> On Thu, Apr 03, 2025 at 09:05:27AM -0500, Justin Tobler wrote:
>> >
>> Thanks, I'm happy with this version.
>
> I am fine with it as well. Thanks.
Thanks, all. Will replace. Let me mark the topic for 'next'.
^ permalink raw reply [flat|nested] 27+ messages in thread