From: Junio C Hamano <gitster@pobox.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: git@vger.kernel.org, Andreas Stieger <astieger@suse.com>
Subject: Re: [PATCH] hash: Allow building with the external sha1dc library
Date: Tue, 25 Jul 2017 12:06:11 -0700 [thread overview]
Message-ID: <xmqq60egbal8.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <s5hh8y19hyg.wl-tiwai@suse.de> (Takashi Iwai's message of "Tue, 25 Jul 2017 07:57:43 +0200")
Takashi Iwai <tiwai@suse.de> writes:
> Some distros provide SHA1 collision detect code as a shared library.
> It's the very same code as we have in git tree, and git can link with
> it as well; at least, it may make maintenance easier, according to our
> security guys.
>
> This patch allows user to build git linking with the external sha1dc
> library instead of the built-in sha1dc code. User needs to define
> DC_SHA1_EXTERNAL explicitly. As default, the built-in sha1dc code is
> used like before.
>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
I do not have such an environment to test this patch, but it looks
like a very sensible thing to do. Will queue; thanks.
> Makefile | 12 ++++++++++++
> hash.h | 4 +++-
> sha1dc_git_ext.c | 11 +++++++++++
> sha1dc_git_ext.h | 25 +++++++++++++++++++++++++
> 4 files changed, 51 insertions(+), 1 deletion(-)
> create mode 100644 sha1dc_git_ext.c
> create mode 100644 sha1dc_git_ext.h
>
> diff --git a/Makefile b/Makefile
> index 461c845d33cb..f1a262d56254 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -162,6 +162,12 @@ all::
> # algorithm. This is slower, but may detect attempted collision attacks.
> # Takes priority over other *_SHA1 knobs.
> #
> +# Define DC_SHA1_EXTERNAL in addition to DC_SHA1 if you want to build / link
> +# git with the external sha1collisiondetection library.
> +# Without this option, i.e. the default behavior is to build git with its
> +# own sha1dc code. If any extra linker option is required, define them in
> +# DC_SHA1_LINK variable in addition.
> +#
> # Define DC_SHA1_SUBMODULE in addition to DC_SHA1 to use the
> # sha1collisiondetection shipped as a submodule instead of the
> # non-submodule copy in sha1dc/. This is an experimental option used
> @@ -1472,6 +1478,11 @@ ifdef APPLE_COMMON_CRYPTO
> BASIC_CFLAGS += -DSHA1_APPLE
> else
> DC_SHA1 := YesPlease
> +ifdef DC_SHA1_EXTERNAL
> + LIB_OBJS += sha1dc_git_ext.o
> + BASIC_CFLAGS += -DSHA1_DC -DDC_SHA1_EXTERNAL
> + EXTLIBS += $(DC_SHA1_LINK) -lsha1detectcoll
> +else
> ifdef DC_SHA1_SUBMODULE
> LIB_OBJS += sha1collisiondetection/lib/sha1.o
> LIB_OBJS += sha1collisiondetection/lib/ubc_check.o
> @@ -1492,6 +1503,7 @@ endif
> endif
> endif
> endif
> +endif
>
> ifdef SHA1_MAX_BLOCK_SIZE
> LIB_OBJS += compat/sha1-chunked.o
> diff --git a/hash.h b/hash.h
> index bef3e630a093..dce327d58d07 100644
> --- a/hash.h
> +++ b/hash.h
> @@ -8,7 +8,9 @@
> #elif defined(SHA1_OPENSSL)
> #include <openssl/sha.h>
> #elif defined(SHA1_DC)
> -#ifdef DC_SHA1_SUBMODULE
> +#if defined(DC_SHA1_EXTERNAL)
> +#include "sha1dc_git_ext.h"
> +#elif defined(DC_SHA1_SUBMODULE)
> #include "sha1collisiondetection/lib/sha1.h"
> #else
> #include "sha1dc/sha1.h"
> diff --git a/sha1dc_git_ext.c b/sha1dc_git_ext.c
> new file mode 100644
> index 000000000000..359439fc3d93
> --- /dev/null
> +++ b/sha1dc_git_ext.c
> @@ -0,0 +1,11 @@
> +/* Only for DC_SHA1_EXTERNAL; sharing the same hooks as built-in sha1dc */
> +
> +#include "cache.h"
> +#include <sha1.h>
> +#include "sha1dc_git.c"
> +
> +void git_SHA1DCInit(SHA1_CTX *ctx)
> +{
> + SHA1DCInit(ctx);
> + SHA1DCSetSafeHash(ctx, 0);
> +}
> diff --git a/sha1dc_git_ext.h b/sha1dc_git_ext.h
> new file mode 100644
> index 000000000000..d0ea8ce518db
> --- /dev/null
> +++ b/sha1dc_git_ext.h
> @@ -0,0 +1,25 @@
> +/*
> + * This file is included by hash.h for DC_SHA1_EXTERNAL
> + */
> +
> +#include <sha1.h>
> +
> +/*
> + * Same as SHA1DCInit, but with default save_hash=0
> + */
> +void git_SHA1DCInit(SHA1_CTX *);
> +
> +/*
> + * Same as SHA1DCFinal, but convert collision attack case into a verbose die().
> + */
> +void git_SHA1DCFinal(unsigned char [20], SHA1_CTX *);
> +
> +/*
> + * Same as SHA1DCUpdate, but adjust types to match git's usual interface.
> + */
> +void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, unsigned long len);
> +
> +#define platform_SHA_CTX SHA1_CTX
> +#define platform_SHA1_Init git_SHA1DCInit
> +#define platform_SHA1_Update git_SHA1DCUpdate
> +#define platform_SHA1_Final git_SHA1DCFinal
next prev parent reply other threads:[~2017-07-25 19:06 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-25 5:57 [PATCH] hash: Allow building with the external sha1dc library Takashi Iwai
2017-07-25 19:06 ` Junio C Hamano [this message]
2017-07-28 15:58 ` Ævar Arnfjörð Bjarmason
2017-07-28 16:04 ` Ævar Arnfjörð Bjarmason
2017-07-31 22:28 ` Junio C Hamano
2017-08-01 5:52 ` Takashi Iwai
2017-08-12 0:42 ` Junio C Hamano
2017-08-12 6:50 ` Takashi Iwai
2017-08-01 5:46 ` Takashi Iwai
2017-08-01 15:56 ` Junio C Hamano
2017-08-01 16:12 ` Takashi Iwai
2017-08-01 19:55 ` Ævar Arnfjörð Bjarmason
2017-08-01 20:50 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq60egbal8.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=astieger@suse.com \
--cc=git@vger.kernel.org \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).