{"thread":{"id":"58107","subject":"[PATCH] sha256: add support for Nettle","startedAt":"2022-07-05T23:05:24Z","lastAt":"2022-08-31T05:36:09Z","messageCount":17,"participants":["brian m. carlson","Ramsay Jones","Jeff King","Ævar Arnfjörð Bjarmason","Junio C Hamano","Reza Mahdi"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"458499","messageId":"20220705230518.713218-1-sandals@crustytoothpaste.net","threadId":"58107","inReplyTo":null,"subject":"[PATCH] sha256: add support for Nettle","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2022-07-05T23:05:18Z","receivedAt":"2022-07-05T23:05:24Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"For SHA-256, we currently have support for OpenSSL and libgcrypt because\nthese two libraries contain optimized implementations that can take\nadvantage of native processor instructions.  However, OpenSSL is not\nsuitable for linking against for Linux distros due to licensing\nincompatibilities with the GPLv2, and libgcrypt has been less favored\nby cryptographers due to some security-related implementation issues.\n\nLet's add another option that's compatible with the GPLv2, which is\nNettle.  It also has recently gained support for Intel's SHA-NI\ninstructions, which compare very favorably to other implementations.\nFor example, using this implementation and SHA-1 DC on a machine with\nSHA-NI, hashing a 2 GiB file with SHA-1 takes 7.582 seconds, while\nhashing the same file with SHA-256 takes 2.278 seconds.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n Makefile        |  7 +++++++\n hash.h          |  4 +++-\n sha256/nettle.h | 28 ++++++++++++++++++++++++++++\n 3 files changed, 38 insertions(+), 1 deletion(-)\n create mode 100644 sha256/nettle.h\n\ndiff --git a/Makefile b/Makefile\nindex 04d0fd1fe6..ce99aecc31 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -182,6 +182,8 @@ include shared.mak\n #\n # Define BLK_SHA256 to use the built-in SHA-256 routines.\n #\n+# Define NETTLE_SHA256 to use the SHA-256 routines in libnettle.\n+#\n # Define GCRYPT_SHA256 to use the SHA-256 routines in libgcrypt.\n #\n # Define OPENSSL_SHA256 to use the SHA-256 routines in OpenSSL.\n@@ -1842,6 +1844,10 @@ ifdef OPENSSL_SHA256\n \tEXTLIBS += $(LIB_4_CRYPTO)\n \tBASIC_CFLAGS += -DSHA256_OPENSSL\n else\n+ifdef NETTLE_SHA256\n+\tBASIC_CFLAGS += -DSHA256_NETTLE\n+\tEXTLIBS += -lnettle\n+else\n ifdef GCRYPT_SHA256\n \tBASIC_CFLAGS += -DSHA256_GCRYPT\n \tEXTLIBS += -lgcrypt\n@@ -1850,6 +1856,7 @@ else\n \tBASIC_CFLAGS += -DSHA256_BLK\n endif\n endif\n+endif\n \n ifdef SHA1_MAX_BLOCK_SIZE\n \tLIB_OBJS += compat/sha1-chunked.o\ndiff --git a/hash.h b/hash.h\nindex 5d40368f18..ea87ae9d92 100644\n--- a/hash.h\n+++ b/hash.h\n@@ -16,7 +16,9 @@\n #include \"block-sha1/sha1.h\"\n #endif\n \n-#if defined(SHA256_GCRYPT)\n+#if defined(SHA256_NETTLE)\n+#include \"sha256/nettle.h\"\n+#elif defined(SHA256_GCRYPT)\n #define SHA256_NEEDS_CLONE_HELPER\n #include \"sha256/gcrypt.h\"\n #elif defined(SHA256_OPENSSL)\ndiff --git a/sha256/nettle.h b/sha256/nettle.h\nnew file mode 100644\nindex 0000000000..9b2845babc\n--- /dev/null\n+++ b/sha256/nettle.h\n@@ -0,0 +1,28 @@\n+#ifndef SHA256_GCRYPT_H\n+#define SHA256_GCRYPT_H\n+\n+#include <nettle/sha2.h>\n+\n+typedef struct sha256_ctx nettle_SHA256_CTX;\n+\n+inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n+{\n+\tsha256_init(ctx);\n+}\n+\n+inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx, const void *data, size_t len)\n+{\n+\tsha256_update(ctx, len, data);\n+}\n+\n+inline void nettle_SHA256_Final(unsigned char *digest, nettle_SHA256_CTX *ctx)\n+{\n+\tsha256_digest(ctx, SHA256_DIGEST_SIZE, digest);\n+}\n+\n+#define platform_SHA256_CTX nettle_SHA256_CTX\n+#define platform_SHA256_Init nettle_SHA256_Init\n+#define platform_SHA256_Update nettle_SHA256_Update\n+#define platform_SHA256_Final nettle_SHA256_Final\n+\n+#endif\n"},{"id":"458501","messageId":"YsTerevSOG9Q76qt@satellite","threadId":"58107","inReplyTo":"20220705230518.713218-1-sandals@crustytoothpaste.net","subject":"Re: [PATCH] sha256: add support for Nettle","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2022-07-06T01:00:29Z","receivedAt":"2022-07-06T01:03:40Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"On Tue, Jul 05, 2022 at 11:05:18PM +0000, brian m. carlson wrote:\n\n[snip]\n\n> diff --git a/sha256/nettle.h b/sha256/nettle.h\n> new file mode 100644\n> index 0000000000..9b2845babc\n> --- /dev/null\n> +++ b/sha256/nettle.h\n> @@ -0,0 +1,28 @@\n> +#ifndef SHA256_GCRYPT_H\n> +#define SHA256_GCRYPT_H\n\nI'm guessing you had intended: s/GCRYPT/NETTLE/ here. :)\n\nATB,\nRamsay Jones\n\n> +\n> +#include <nettle/sha2.h>\n> +\n> +typedef struct sha256_ctx nettle_SHA256_CTX;\n> +\n> +inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n> +{\n> +\tsha256_init(ctx);\n> +}\n> +\n> +inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx, const void *data, size_t len)\n> +{\n> +\tsha256_update(ctx, len, data);\n> +}\n> +\n> +inline void nettle_SHA256_Final(unsigned char *digest, nettle_SHA256_CTX *ctx)\n> +{\n> +\tsha256_digest(ctx, SHA256_DIGEST_SIZE, digest);\n> +}\n> +\n> +#define platform_SHA256_CTX nettle_SHA256_CTX\n> +#define platform_SHA256_Init nettle_SHA256_Init\n> +#define platform_SHA256_Update nettle_SHA256_Update\n> +#define platform_SHA256_Final nettle_SHA256_Final\n> +\n> +#endif\n"},{"id":"458502","messageId":"YsTgmv+h2SFFFMga@tapette.crustytoothpaste.net","threadId":"58107","inReplyTo":"YsTerevSOG9Q76qt@satellite","subject":"Re: [PATCH] sha256: add support for Nettle","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2022-07-06T01:08:42Z","receivedAt":"2022-07-06T01:08:47Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2022-07-06 at 01:00:29, Ramsay Jones wrote:\n> On Tue, Jul 05, 2022 at 11:05:18PM +0000, brian m. carlson wrote:\n> \n> [snip]\n> \n> > diff --git a/sha256/nettle.h b/sha256/nettle.h\n> > new file mode 100644\n> > index 0000000000..9b2845babc\n> > --- /dev/null\n> > +++ b/sha256/nettle.h\n> > @@ -0,0 +1,28 @@\n> > +#ifndef SHA256_GCRYPT_H\n> > +#define SHA256_GCRYPT_H\n> \n> I'm guessing you had intended: s/GCRYPT/NETTLE/ here. :)\n\nAh, yes.  I'll see if anyone has other comments and then send out a v2.\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"458509","messageId":"YsVGgFlxUbwtL6zn@coredump.intra.peff.net","threadId":"58107","inReplyTo":"20220705230518.713218-1-sandals@crustytoothpaste.net","subject":"Re: [PATCH] sha256: add support for Nettle","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-07-06T08:23:28Z","receivedAt":"2022-07-06T08:23:55Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jul 05, 2022 at 11:05:18PM +0000, brian m. carlson wrote:\n\n> Let's add another option that's compatible with the GPLv2, which is\n> Nettle.  It also has recently gained support for Intel's SHA-NI\n> instructions, which compare very favorably to other implementations.\n> For example, using this implementation and SHA-1 DC on a machine with\n> SHA-NI, hashing a 2 GiB file with SHA-1 takes 7.582 seconds, while\n> hashing the same file with SHA-256 takes 2.278 seconds.\n\nNifty. I was curious about the speed on my machine, since I still had\nthat sha256 import of linux.git. Sadly, it's not nearly as impressive:\n\n  [blk_sha256]\n  $ time git index-pack --verify objects/pack/*.pack\n  real\t2m40.164s\n  user\t12m30.626s\n  sys\t0m31.567s\n\n  [nettle]\n  $ time git index-pack --verify objects/pack/*.pack\n  real\t2m21.346s\n  user\t10m14.507s\n  sys\t0m30.943s\n\nwhich I take to mean that it doesn't support the Intel SHA extensions\n(and /proc/cpuinfo confirms that). Still, 12-18% speedup is a nice and\neasy win.\n\n>  Makefile        |  7 +++++++\n>  hash.h          |  4 +++-\n>  sha256/nettle.h | 28 ++++++++++++++++++++++++++++\n>  3 files changed, 38 insertions(+), 1 deletion(-)\n>  create mode 100644 sha256/nettle.h\n\nThe patch itself looks good to me, modulo the guard typo already pointed\nout.\n\n-Peff\n"},{"id":"458510","messageId":"220706.86fsjeaalo.gmgdl@evledraar.gmail.com","threadId":"58107","inReplyTo":"20220705230518.713218-1-sandals@crustytoothpaste.net","subject":"Re: [PATCH] sha256: add support for Nettle","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-07-06T08:45:06Z","receivedAt":"2022-07-06T08:50:35Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Tue, Jul 05 2022, brian m. carlson wrote:\n\nDo any of those security issues in libcrypt have to do with the narrow\n\"hash stuff\" part of the API we're using?\n\n> Let's add another option that's compatible with the GPLv2, which is\n> Nettle.  It also has recently gained support for Intel's SHA-NI\n> instructions, which compare very favorably to other implementations.\n> For example, using this implementation and SHA-1 DC on a machine with\n> SHA-NI, hashing a 2 GiB file with SHA-1 takes 7.582 seconds, while\n> hashing the same file with SHA-256 takes 2.278 seconds.\n\nInteresting, but as Jeff notes downthread we really should be comparing\nthe different sha256 backends for speed, i.e. the interesting thing\nisn't sha1dc v.s. this sha256 ,but if this sha256 backend in particular\noffers performance benefits.\n\n> -#if defined(SHA256_GCRYPT)\n> +#if defined(SHA256_NETTLE)\n> +#include \"sha256/nettle.h\"\n> +#elif defined(SHA256_GCRYPT)\n>  #define SHA256_NEEDS_CLONE_HELPER\n>  #include \"sha256/gcrypt.h\"\n>  #elif defined(SHA256_OPENSSL)\n> diff --git a/sha256/nettle.h b/sha256/nettle.h\n> new file mode 100644\n> index 0000000000..9b2845babc\n> --- /dev/null\n> +++ b/sha256/nettle.h\n> @@ -0,0 +1,28 @@\n> +#ifndef SHA256_GCRYPT_H\n> +#define SHA256_GCRYPT_H\n> +\n> +#include <nettle/sha2.h>\n> +\n> +typedef struct sha256_ctx nettle_SHA256_CTX;\n> +\n> +inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n> +{\n> +\tsha256_init(ctx);\n> +}\n> +\n> +inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx, const void *data, size_t len)\n\nNeeds a line wrap;\n\n> +{\n> +\tsha256_update(ctx, len, data);\n> +}\n> +\n> +inline void nettle_SHA256_Final(unsigned char *digest, nettle_SHA256_CTX *ctx)\n> +{\n> +\tsha256_digest(ctx, SHA256_DIGEST_SIZE, digest);\n> +}\n> +\n> +#define platform_SHA256_CTX nettle_SHA256_CTX\n> +#define platform_SHA256_Init nettle_SHA256_Init\n> +#define platform_SHA256_Update nettle_SHA256_Update\n> +#define platform_SHA256_Final nettle_SHA256_Final\n> +\n> +#endif\n\nWould it be viable / at all sane to embed the part of the library we\nneed in our sources, similar to what we do for sha1dc? Or perhaps it's\nnot worth it at all...\n"},{"id":"458515","messageId":"YsVUhjrxPGdZuVWN@coredump.intra.peff.net","threadId":"58107","inReplyTo":"220706.86fsjeaalo.gmgdl@evledraar.gmail.com","subject":"Re: [PATCH] sha256: add support for Nettle","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-07-06T09:23:18Z","receivedAt":"2022-07-06T09:23:22Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jul 06, 2022 at 10:45:06AM +0200, Ævar Arnfjörð Bjarmason wrote:\n\n> Would it be viable / at all sane to embed the part of the library we\n> need in our sources, similar to what we do for sha1dc? Or perhaps it's\n> not worth it at all...\n\nI doubt it's worth it. It's a big library with tons of algorithms, most\nof which we won't need. And the implementation has lots of asm and\nplatform-specific knobs. I wouldn't want to try extracting any of that\nfrom their autoconf file, nor putting (more) autoconf inside our\nrepository.\n\nFor sha1dc, I think including a vendored copy was important for us\nmaking it the default, and we wanted to do that for the security\nimplications. A 12% speedup is OK to leave on the able for the default\nbuild, and people can easily link against the system libnettle if they\ncare enough. And other linkable implementations are in the same boat;\nopenssl is even faster than libnettle on my machine.\n\n-Peff\n"},{"id":"458516","messageId":"YsVmVsn65/NUKeXz@tapette.crustytoothpaste.net","threadId":"58107","inReplyTo":"YsVUhjrxPGdZuVWN@coredump.intra.peff.net","subject":"Re: [PATCH] sha256: add support for Nettle","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2022-07-06T10:39:18Z","receivedAt":"2022-07-06T10:39:24Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2022-07-06 at 09:23:18, Jeff King wrote:\n> On Wed, Jul 06, 2022 at 10:45:06AM +0200, Ævar Arnfjörð Bjarmason wrote:\n> \n> > Would it be viable / at all sane to embed the part of the library we\n> > need in our sources, similar to what we do for sha1dc? Or perhaps it's\n> > not worth it at all...\n> \n> I doubt it's worth it. It's a big library with tons of algorithms, most\n> of which we won't need. And the implementation has lots of asm and\n> platform-specific knobs. I wouldn't want to try extracting any of that\n> from their autoconf file, nor putting (more) autoconf inside our\n> repository.\n\nYeah, it requires doing a CPUID check on different platforms to\ndetermine which CPU to use at runtime.  Depending on platform, CPUID\nisn't always available, and sometimes you end up needing to use a\ndifferent method, which we wouldn't want to port here.\n\nIf we just want a basic option, we have that in the block SHA-256\nalgorithm, which is probably no better or worse than Nettle's\nimplementation.\n\n> For sha1dc, I think including a vendored copy was important for us\n> making it the default, and we wanted to do that for the security\n> implications. A 12% speedup is OK to leave on the able for the default\n> build, and people can easily link against the system libnettle if they\n> care enough. And other linkable implementations are in the same boat;\n> openssl is even faster than libnettle on my machine.\n\nRight.  I'm not surprised that OpenSSL is faster here, and that's\nexpected, since OpenSSL tends to outperform other libraries.  Even with\nSHA-NI extensions, it's slightly faster still (1.415 s vs. 1.529 s for a\n2 GB file), but I'm sure with a small amount of tuning Nettle could\ncatch up, because it's essentially the same instructions.\n\nFor block SHA-256, the time taken for the same file is 7.296 seconds, so\nthe performance improvement is substantial if you have the extensions\n(and maybe even if you don't since both Nettle and OpenSSL have SIMD\nimplementations as well). That's why I wanted to send this patch: I'd\nlike to see if Debian can link against libnettle in the future,\nespecially since it's already in at least some binaries due to GnuTLS.\n\nFor SHA-1 DC, we definitely want it to be the default for security, so\nvendoring a copy matters.\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"458533","messageId":"xmqqedyyi11y.fsf@gitster.g","threadId":"58107","inReplyTo":"20220705230518.713218-1-sandals@crustytoothpaste.net","subject":"Re: [PATCH] sha256: add support for Nettle","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-07-06T17:49:29Z","receivedAt":"2022-07-06T17:49:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> diff --git a/hash.h b/hash.h\n> index 5d40368f18..ea87ae9d92 100644\n> --- a/hash.h\n> +++ b/hash.h\n> @@ -16,7 +16,9 @@\n>  #include \"block-sha1/sha1.h\"\n>  #endif\n>  \n> -#if defined(SHA256_GCRYPT)\n> +#if defined(SHA256_NETTLE)\n> +#include \"sha256/nettle.h\"\n> +#elif defined(SHA256_GCRYPT)\n>  #define SHA256_NEEDS_CLONE_HELPER\n>  #include \"sha256/gcrypt.h\"\n>  #elif defined(SHA256_OPENSSL)\n\nWhen it does not make any semantic difference, it is preferrable to\nadd a new thing after existing things.  But this sequence is meant\nto list them in the order of preference when multiple choices are\navailble, so it is OK to prepend nettle IF our intention is to favor\nit over all others.\n\nI am OK with that design choice, and I think the first paragraph of\nthe proposed log message adequately justifies why, but I'd prefer to\nsee it a bit more explicitly stated in the log message.\n\n> For SHA-256, we currently have support for OpenSSL and libgcrypt because\n> these two libraries contain optimized implementations that can take\n> advantage of native processor instructions.  However, OpenSSL is not\n> suitable for linking against for Linux distros due to licensing\n> incompatibilities with the GPLv2, and libgcrypt has been less favored\n> by cryptographers due to some security-related implementation issues.\n>\n> Let's add another option that's compatible with the GPLv2, which is\n> Nettle.  It also has recently gained support for Intel's SHA-NI\n> instructions, which compare very favorably to other implementations.\n> For example, using this implementation and SHA-1 DC on a machine with\n> SHA-NI, hashing a 2 GiB file with SHA-1 takes 7.582 seconds, while\n> hashing the same file with SHA-256 takes 2.278 seconds.\n\nPerhaps \"Let's add another option ..., which is Nettle, and give it\npreference over all others when multiple libraries are availalble\"\nor something along that line?\n\n> diff --git a/sha256/nettle.h b/sha256/nettle.h\n> new file mode 100644\n> index 0000000000..9b2845babc\n> --- /dev/null\n> +++ b/sha256/nettle.h\n> @@ -0,0 +1,28 @@\n> +#ifndef SHA256_GCRYPT_H\n> +#define SHA256_GCRYPT_H\n\nNot really ;-)\n\n> +\n> +#include <nettle/sha2.h>\n\n\n\n"},{"id":"458546","messageId":"xmqqilo94zc2.fsf@gitster.g","threadId":"58107","inReplyTo":"xmqqedyyi11y.fsf@gitster.g","subject":"Re: [PATCH] sha256: add support for Nettle","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-07-06T23:05:01Z","receivedAt":"2022-07-06T23:05:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Perhaps \"Let's add another option ..., which is Nettle, and give it\n> preference over all others when multiple libraries are availalble\"\n> or something along that line?\n>\n>> diff --git a/sha256/nettle.h b/sha256/nettle.h\n>> new file mode 100644\n>> index 0000000000..9b2845babc\n>> --- /dev/null\n>> +++ b/sha256/nettle.h\n>> @@ -0,0 +1,28 @@\n>> +#ifndef SHA256_GCRYPT_H\n>> +#define SHA256_GCRYPT_H\n>\n> Not really ;-)\n\nFWIW, I needed the following to successfully build with\nNETTLE_SHA256=YesPlease defined.  The final linkage step complained\nabout missing nettle_SHA256_{Init,Update,Final}() functions without\nthe tweak.\n\ndiff --git c/sha256/nettle.h w/sha256/nettle.h\nindex 9b2845babc..8c93f29dda 100644\n--- c/sha256/nettle.h\n+++ w/sha256/nettle.h\n@@ -1,21 +1,21 @@\n-#ifndef SHA256_GCRYPT_H\n-#define SHA256_GCRYPT_H\n+#ifndef SHA256_NETTLE_H\n+#define SHA256_NETTLE_H\n \n #include <nettle/sha2.h>\n \n typedef struct sha256_ctx nettle_SHA256_CTX;\n \n-inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n+static inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n {\n \tsha256_init(ctx);\n }\n \n-inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx, const void *data, size_t len)\n+static inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx, const void *data, size_t len)\n {\n \tsha256_update(ctx, len, data);\n }\n \n-inline void nettle_SHA256_Final(unsigned char *digest, nettle_SHA256_CTX *ctx)\n+static inline void nettle_SHA256_Final(unsigned char *digest, nettle_SHA256_CTX *ctx)\n {\n \tsha256_digest(ctx, SHA256_DIGEST_SIZE, digest);\n }\n\n\n"},{"id":"458556","messageId":"xmqqpmih2zix.fsf@gitster.g","threadId":"58107","inReplyTo":"xmqqilo94zc2.fsf@gitster.g","subject":"Re: [PATCH] sha256: add support for Nettle","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-07-07T06:43:50Z","receivedAt":"2022-07-07T06:43:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> FWIW, I needed the following to successfully build with\n> NETTLE_SHA256=YesPlease defined.  The final linkage step complained\n> about missing nettle_SHA256_{Init,Update,Final}() functions without\n> the tweak.\n> ...\n\nAnother glitch.\n\nAs \"make hdr-check\" is pretty much indiscriminatory, my build failed\non a box without libnettle-dev (hence /usr/include/nettle/sha2.h\nmissing).\n\ndiff --git a/Makefile b/Makefile\nindex ce99aecc31..52a9f97997 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -3098,6 +3098,9 @@ $(SP_OBJ): %.sp: %.c %.o\n sparse: $(SP_OBJ)\n \n EXCEPT_HDRS := $(GENERATED_H) unicode-width.h compat/% xdiff/%\n+ifndef NETTLE_SHA256\n+\tEXCEPT_HDRS += sha256/nettle.h\n+endif\n ifndef GCRYPT_SHA256\n \tEXCEPT_HDRS += sha256/gcrypt.h\n endif\ndiff --git a/sha256/nettle.h b/sha256/nettle.h\nindex 159239a785..8c93f29dda 100644\n--- a/sha256/nettle.h\n+++ b/sha256/nettle.h\n@@ -5,17 +5,17 @@\n \n typedef struct sha256_ctx nettle_SHA256_CTX;\n \n-inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n+static inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n {\n \tsha256_init(ctx);\n }\n \n-inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx, const void *data, size_t len)\n+static inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx, const void *data, size_t len)\n {\n \tsha256_update(ctx, len, data);\n }\n \n-inline void nettle_SHA256_Final(unsigned char *digest, nettle_SHA256_CTX *ctx)\n+static inline void nettle_SHA256_Final(unsigned char *digest, nettle_SHA256_CTX *ctx)\n {\n \tsha256_digest(ctx, SHA256_DIGEST_SIZE, digest);\n }\n"},{"id":"458574","messageId":"xmqqk08o3ngz.fsf@gitster.g","threadId":"58107","inReplyTo":"xmqqpmih2zix.fsf@gitster.g","subject":"Re: [PATCH] sha256: add support for Nettle","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-07-07T16:18:52Z","receivedAt":"2022-07-07T16:19:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>> FWIW, I needed the following to successfully build with\n>> NETTLE_SHA256=YesPlease defined.  The final linkage step complained\n>> about missing nettle_SHA256_{Init,Update,Final}() functions without\n>> the tweak.\n>> ...\n>\n> Another glitch.\n> \n> As \"make hdr-check\" is pretty much indiscriminatory, my build failed\n> on a box without libnettle-dev (hence /usr/include/nettle/sha2.h\n> missing).\n> ...\n\nTaking all together, here is a copy I have in my tree right now (see\nthe range diff for what changed since your initial version).\n\nThanks.\n\n----- >8 --------- >8 --------- >8 --------- >8 --------- >8 -----\nFrom e8713290975d171764768bea99d686243e23ef8e Mon Sep 17 00:00:00 2001\nFrom: \"brian m. carlson\" <sandals@crustytoothpaste.net>\nDate: Tue, 5 Jul 2022 23:05:18 +0000\nSubject: [PATCH] sha256: add support for Nettle\n\nFor SHA-256, we currently have support for OpenSSL and libgcrypt because\nthese two libraries contain optimized implementations that can take\nadvantage of native processor instructions.  However, OpenSSL is not\nsuitable for linking against for Linux distros due to licensing\nincompatibilities with the GPLv2, and libgcrypt has been less favored\nby cryptographers due to some security-related implementation issues.\n\nLet's add another option that's compatible with the GPLv2, which is\nNettle, and give it preference over all others when Nettle and other\nchoices are possible.  It also has recently gained support for\nIntel's SHA-NI instructions, which compare very favorably to other\nimplementations.  For example, using this implementation and SHA-1\nDC on a machine with SHA-NI, hashing a 2 GiB file with SHA-1 takes\n7.582 seconds, while hashing the same file with SHA-256 takes 2.278\nseconds.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n1:  3bcd13c813 ! 1:  e871329097 sha256: add support for Nettle\n    @@ Commit message\n         by cryptographers due to some security-related implementation issues.\n     \n         Let's add another option that's compatible with the GPLv2, which is\n    -    Nettle.  It also has recently gained support for Intel's SHA-NI\n    -    instructions, which compare very favorably to other implementations.\n    -    For example, using this implementation and SHA-1 DC on a machine with\n    -    SHA-NI, hashing a 2 GiB file with SHA-1 takes 7.582 seconds, while\n    -    hashing the same file with SHA-256 takes 2.278 seconds.\n    +    Nettle, and give it preference over all others when Nettle and other\n    +    choices are possible.  It also has recently gained support for\n    +    Intel's SHA-NI instructions, which compare very favorably to other\n    +    implementations.  For example, using this implementation and SHA-1\n    +    DC on a machine with SHA-NI, hashing a 2 GiB file with SHA-1 takes\n    +    7.582 seconds, while hashing the same file with SHA-256 takes 2.278\n    +    seconds.\n     \n         Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n         Signed-off-by: Junio C Hamano <gitster@pobox.com>\n    @@ Makefile: else\n      \n      ifdef SHA1_MAX_BLOCK_SIZE\n      \tLIB_OBJS += compat/sha1-chunked.o\n    +@@ Makefile: $(SP_OBJ): %.sp: %.c %.o\n    + sparse: $(SP_OBJ)\n    + \n    + EXCEPT_HDRS := $(GENERATED_H) unicode-width.h compat/% xdiff/%\n    ++ifndef NETTLE_SHA256\n    ++\tEXCEPT_HDRS += sha256/nettle.h\n    ++endif\n    + ifndef GCRYPT_SHA256\n    + \tEXCEPT_HDRS += sha256/gcrypt.h\n    + endif\n     \n      ## hash.h ##\n     @@\n    @@ hash.h\n     \n      ## sha256/nettle.h (new) ##\n     @@\n    -+#ifndef SHA256_GCRYPT_H\n    -+#define SHA256_GCRYPT_H\n    ++#ifndef SHA256_NETTLE_H\n    ++#define SHA256_NETTLE_H\n     +\n     +#include <nettle/sha2.h>\n     +\n     +typedef struct sha256_ctx nettle_SHA256_CTX;\n     +\n    -+inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n    ++static inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n     +{\n     +\tsha256_init(ctx);\n     +}\n     +\n    -+inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx, const void *data, size_t len)\n    ++static inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx, const void *data, size_t len)\n     +{\n     +\tsha256_update(ctx, len, data);\n     +}\n     +\n    -+inline void nettle_SHA256_Final(unsigned char *digest, nettle_SHA256_CTX *ctx)\n    ++static inline void nettle_SHA256_Final(unsigned char *digest, nettle_SHA256_CTX *ctx)\n     +{\n     +\tsha256_digest(ctx, SHA256_DIGEST_SIZE, digest);\n     +}\n\n\n\n Makefile        | 10 ++++++++++\n hash.h          |  4 +++-\n sha256/nettle.h | 28 ++++++++++++++++++++++++++++\n 3 files changed, 41 insertions(+), 1 deletion(-)\n create mode 100644 sha256/nettle.h\n\ndiff --git a/Makefile b/Makefile\nindex 04d0fd1fe6..52a9f97997 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -182,6 +182,8 @@ include shared.mak\n #\n # Define BLK_SHA256 to use the built-in SHA-256 routines.\n #\n+# Define NETTLE_SHA256 to use the SHA-256 routines in libnettle.\n+#\n # Define GCRYPT_SHA256 to use the SHA-256 routines in libgcrypt.\n #\n # Define OPENSSL_SHA256 to use the SHA-256 routines in OpenSSL.\n@@ -1842,6 +1844,10 @@ ifdef OPENSSL_SHA256\n \tEXTLIBS += $(LIB_4_CRYPTO)\n \tBASIC_CFLAGS += -DSHA256_OPENSSL\n else\n+ifdef NETTLE_SHA256\n+\tBASIC_CFLAGS += -DSHA256_NETTLE\n+\tEXTLIBS += -lnettle\n+else\n ifdef GCRYPT_SHA256\n \tBASIC_CFLAGS += -DSHA256_GCRYPT\n \tEXTLIBS += -lgcrypt\n@@ -1850,6 +1856,7 @@ else\n \tBASIC_CFLAGS += -DSHA256_BLK\n endif\n endif\n+endif\n \n ifdef SHA1_MAX_BLOCK_SIZE\n \tLIB_OBJS += compat/sha1-chunked.o\n@@ -3091,6 +3098,9 @@ $(SP_OBJ): %.sp: %.c %.o\n sparse: $(SP_OBJ)\n \n EXCEPT_HDRS := $(GENERATED_H) unicode-width.h compat/% xdiff/%\n+ifndef NETTLE_SHA256\n+\tEXCEPT_HDRS += sha256/nettle.h\n+endif\n ifndef GCRYPT_SHA256\n \tEXCEPT_HDRS += sha256/gcrypt.h\n endif\ndiff --git a/hash.h b/hash.h\nindex 5d40368f18..ea87ae9d92 100644\n--- a/hash.h\n+++ b/hash.h\n@@ -16,7 +16,9 @@\n #include \"block-sha1/sha1.h\"\n #endif\n \n-#if defined(SHA256_GCRYPT)\n+#if defined(SHA256_NETTLE)\n+#include \"sha256/nettle.h\"\n+#elif defined(SHA256_GCRYPT)\n #define SHA256_NEEDS_CLONE_HELPER\n #include \"sha256/gcrypt.h\"\n #elif defined(SHA256_OPENSSL)\ndiff --git a/sha256/nettle.h b/sha256/nettle.h\nnew file mode 100644\nindex 0000000000..8c93f29dda\n--- /dev/null\n+++ b/sha256/nettle.h\n@@ -0,0 +1,28 @@\n+#ifndef SHA256_NETTLE_H\n+#define SHA256_NETTLE_H\n+\n+#include <nettle/sha2.h>\n+\n+typedef struct sha256_ctx nettle_SHA256_CTX;\n+\n+static inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n+{\n+\tsha256_init(ctx);\n+}\n+\n+static inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx, const void *data, size_t len)\n+{\n+\tsha256_update(ctx, len, data);\n+}\n+\n+static inline void nettle_SHA256_Final(unsigned char *digest, nettle_SHA256_CTX *ctx)\n+{\n+\tsha256_digest(ctx, SHA256_DIGEST_SIZE, digest);\n+}\n+\n+#define platform_SHA256_CTX nettle_SHA256_CTX\n+#define platform_SHA256_Init nettle_SHA256_Init\n+#define platform_SHA256_Update nettle_SHA256_Update\n+#define platform_SHA256_Final nettle_SHA256_Final\n+\n+#endif\n-- \n2.37.0-211-gafcdf5f063\n\n"},{"id":"458709","messageId":"20220710132907.1499365-1-sandals@crustytoothpaste.net","threadId":"58107","inReplyTo":"20220705230518.713218-1-sandals@crustytoothpaste.net","subject":"[PATCH v2] sha256: add support for Nettle","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2022-07-10T13:29:07Z","receivedAt":"2022-07-10T13:30:02Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"For SHA-256, we currently have support for OpenSSL and libgcrypt because\nthese two libraries contain optimized implementations that can take\nadvantage of native processor instructions.  However, OpenSSL is not\nsuitable for linking against for Linux distros due to licensing\nincompatibilities with the GPLv2, and libgcrypt has been less favored by\ncryptographers due to some security-related implementation issues,\nwhich, while not affecting our use of hash algorithms, has affected its\nreputation.\n\nLet's add another option that's compatible with the GPLv2, which is\nNettle.  This is an option which is generally better than libgcrypt\nbecause on many distros GnuTLS (which uses Nettle) is used for HTTPS and\ntherefore as a practical matter it will be available on most systems.\nAs a result, prefer it over libgcrypt and our built-in implementation.\n\nNettle also has recently gained support for Intel's SHA-NI instructions,\nwhich compare very favorably to other implementations, as well as\nassembly implementations for when SHA-NI is not available.\n\nA git gc on git.git sees a 12% performance improvement with Nettle over\nour block SHA-256 implementation due to general assembly improvements.\nWith SHA-NI, the performance of raw SHA-256 on a 2 GiB file goes from\n7.296 seconds with block SHA-256 to 1.523 seconds with Nettle.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n\nChanges from v1:\n\n* Improve commit message to provide better statistics and rationale.\n* Fix include guard typo.\n* Exclude header in Makefile unless we're building it.\n\n Makefile        | 10 ++++++++++\n hash.h          |  4 +++-\n sha256/nettle.h | 31 +++++++++++++++++++++++++++++++\n 3 files changed, 44 insertions(+), 1 deletion(-)\n create mode 100644 sha256/nettle.h\n\ndiff --git a/Makefile b/Makefile\nindex 04d0fd1fe6..52a9f97997 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -182,6 +182,8 @@ include shared.mak\n #\n # Define BLK_SHA256 to use the built-in SHA-256 routines.\n #\n+# Define NETTLE_SHA256 to use the SHA-256 routines in libnettle.\n+#\n # Define GCRYPT_SHA256 to use the SHA-256 routines in libgcrypt.\n #\n # Define OPENSSL_SHA256 to use the SHA-256 routines in OpenSSL.\n@@ -1842,6 +1844,10 @@ ifdef OPENSSL_SHA256\n \tEXTLIBS += $(LIB_4_CRYPTO)\n \tBASIC_CFLAGS += -DSHA256_OPENSSL\n else\n+ifdef NETTLE_SHA256\n+\tBASIC_CFLAGS += -DSHA256_NETTLE\n+\tEXTLIBS += -lnettle\n+else\n ifdef GCRYPT_SHA256\n \tBASIC_CFLAGS += -DSHA256_GCRYPT\n \tEXTLIBS += -lgcrypt\n@@ -1850,6 +1856,7 @@ else\n \tBASIC_CFLAGS += -DSHA256_BLK\n endif\n endif\n+endif\n \n ifdef SHA1_MAX_BLOCK_SIZE\n \tLIB_OBJS += compat/sha1-chunked.o\n@@ -3091,6 +3098,9 @@ $(SP_OBJ): %.sp: %.c %.o\n sparse: $(SP_OBJ)\n \n EXCEPT_HDRS := $(GENERATED_H) unicode-width.h compat/% xdiff/%\n+ifndef NETTLE_SHA256\n+\tEXCEPT_HDRS += sha256/nettle.h\n+endif\n ifndef GCRYPT_SHA256\n \tEXCEPT_HDRS += sha256/gcrypt.h\n endif\ndiff --git a/hash.h b/hash.h\nindex 5d40368f18..ea87ae9d92 100644\n--- a/hash.h\n+++ b/hash.h\n@@ -16,7 +16,9 @@\n #include \"block-sha1/sha1.h\"\n #endif\n \n-#if defined(SHA256_GCRYPT)\n+#if defined(SHA256_NETTLE)\n+#include \"sha256/nettle.h\"\n+#elif defined(SHA256_GCRYPT)\n #define SHA256_NEEDS_CLONE_HELPER\n #include \"sha256/gcrypt.h\"\n #elif defined(SHA256_OPENSSL)\ndiff --git a/sha256/nettle.h b/sha256/nettle.h\nnew file mode 100644\nindex 0000000000..b63e1c8190\n--- /dev/null\n+++ b/sha256/nettle.h\n@@ -0,0 +1,31 @@\n+#ifndef SHA256_NETTLE_H\n+#define SHA256_NETTLE_H\n+\n+#include <nettle/sha2.h>\n+\n+typedef struct sha256_ctx nettle_SHA256_CTX;\n+\n+static inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n+{\n+\tsha256_init(ctx);\n+}\n+\n+static inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx,\n+\t\t\t\t\tconst void *data,\n+\t\t\t\t\tsize_t len)\n+{\n+\tsha256_update(ctx, len, data);\n+}\n+\n+static inline void nettle_SHA256_Final(unsigned char *digest,\n+\t\t\t\t       nettle_SHA256_CTX *ctx)\n+{\n+\tsha256_digest(ctx, SHA256_DIGEST_SIZE, digest);\n+}\n+\n+#define platform_SHA256_CTX nettle_SHA256_CTX\n+#define platform_SHA256_Init nettle_SHA256_Init\n+#define platform_SHA256_Update nettle_SHA256_Update\n+#define platform_SHA256_Final nettle_SHA256_Final\n+\n+#endif\n"},{"id":"458711","messageId":"220710.86mtdh81ty.gmgdl@evledraar.gmail.com","threadId":"58107","inReplyTo":"20220710132907.1499365-1-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2] sha256: add support for Nettle","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-07-10T14:41:23Z","receivedAt":"2022-07-10T14:44:15Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sun, Jul 10 2022, brian m. carlson wrote:\n\n> @@ -182,6 +182,8 @@ include shared.mak\n>  #\n>  # Define BLK_SHA256 to use the built-in SHA-256 routines.\n>  #\n> +# Define NETTLE_SHA256 to use the SHA-256 routines in libnettle.\n> +#\n>  # Define GCRYPT_SHA256 to use the SHA-256 routines in libgcrypt.\n>  #\n>  # Define OPENSSL_SHA256 to use the SHA-256 routines in OpenSSL.\n> @@ -1842,6 +1844,10 @@ ifdef OPENSSL_SHA256\n>  \tEXTLIBS += $(LIB_4_CRYPTO)\n>  \tBASIC_CFLAGS += -DSHA256_OPENSSL\n>  else\n> +ifdef NETTLE_SHA256\n> +\tBASIC_CFLAGS += -DSHA256_NETTLE\n> +\tEXTLIBS += -lnettle\n> +else\n>  ifdef GCRYPT_SHA256\n>  \tBASIC_CFLAGS += -DSHA256_GCRYPT\n>  \tEXTLIBS += -lgcrypt\n> @@ -1850,6 +1856,7 @@ else\n>  \tBASIC_CFLAGS += -DSHA256_BLK\n>  endif\n>  endif\n> +endif\n\nThis just carries forward existing technical debt, but it's unfortunate\nthat we don't catch OPENSSL_SHA256 overridding NETTLE_SHA256, and error\nif both are defined.\n\n>  ifdef SHA1_MAX_BLOCK_SIZE\n>  \tLIB_OBJS += compat/sha1-chunked.o\n> @@ -3091,6 +3098,9 @@ $(SP_OBJ): %.sp: %.c %.o\n>  sparse: $(SP_OBJ)\n>  \n>  EXCEPT_HDRS := $(GENERATED_H) unicode-width.h compat/% xdiff/%\n> +ifndef NETTLE_SHA256\n> +\tEXCEPT_HDRS += sha256/nettle.h\n> +endif\n>  ifndef GCRYPT_SHA256\n>  \tEXCEPT_HDRS += sha256/gcrypt.h\n>  endif\n> diff --git a/hash.h b/hash.h\n> index 5d40368f18..ea87ae9d92 100644\n> --- a/hash.h\n> +++ b/hash.h\n> @@ -16,7 +16,9 @@\n>  #include \"block-sha1/sha1.h\"\n>  #endif\n>  \n> -#if defined(SHA256_GCRYPT)\n> +#if defined(SHA256_NETTLE)\n> +#include \"sha256/nettle.h\"\n> +#elif defined(SHA256_GCRYPT)\n>  #define SHA256_NEEDS_CLONE_HELPER\n>  #include \"sha256/gcrypt.h\"\n>  #elif defined(SHA256_OPENSSL)\n> diff --git a/sha256/nettle.h b/sha256/nettle.h\n> new file mode 100644\n> index 0000000000..b63e1c8190\n> --- /dev/null\n> +++ b/sha256/nettle.h\n> @@ -0,0 +1,31 @@\n> +#ifndef SHA256_NETTLE_H\n> +#define SHA256_NETTLE_H\n> +\n> +#include <nettle/sha2.h>\n> +\n> +typedef struct sha256_ctx nettle_SHA256_CTX;\n> +\n> +static inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n> +{\n> +\tsha256_init(ctx);\n> +}\n> +\n> +static inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx,\n> +\t\t\t\t\tconst void *data,\n> +\t\t\t\t\tsize_t len)\n> +{\n> +\tsha256_update(ctx, len, data);\n> +}\n> +\n> +static inline void nettle_SHA256_Final(unsigned char *digest,\n> +\t\t\t\t       nettle_SHA256_CTX *ctx)\n> +{\n> +\tsha256_digest(ctx, SHA256_DIGEST_SIZE, digest);\n> +}\n> +\n> +#define platform_SHA256_CTX nettle_SHA256_CTX\n> +#define platform_SHA256_Init nettle_SHA256_Init\n> +#define platform_SHA256_Update nettle_SHA256_Update\n> +#define platform_SHA256_Final nettle_SHA256_Final\n> +\n> +#endif\n\nThis looks good to me, except for the small nit that I think this should\nbe squashed in. For the others we need this inline wrappers, but not for\n\"init\":\n\ndiff --git a/sha256/nettle.h b/sha256/nettle.h\nindex b63e1c81903..5c9811c309a 100644\n--- a/sha256/nettle.h\n+++ b/sha256/nettle.h\n@@ -5,11 +5,6 @@\n \n typedef struct sha256_ctx nettle_SHA256_CTX;\n \n-static inline void nettle_SHA256_Init(nettle_SHA256_CTX *ctx)\n-{\n-\tsha256_init(ctx);\n-}\n-\n static inline void nettle_SHA256_Update(nettle_SHA256_CTX *ctx,\n \t\t\t\t\tconst void *data,\n \t\t\t\t\tsize_t len)\n@@ -24,7 +19,7 @@ static inline void nettle_SHA256_Final(unsigned char *digest,\n }\n \n #define platform_SHA256_CTX nettle_SHA256_CTX\n-#define platform_SHA256_Init nettle_SHA256_Init\n+#define platform_SHA256_Init sha256_init\n #define platform_SHA256_Update nettle_SHA256_Update\n #define platform_SHA256_Final nettle_SHA256_Final\n \n"},{"id":"458721","messageId":"xmqqwnckrkg9.fsf@gitster.g","threadId":"58107","inReplyTo":"220710.86mtdh81ty.gmgdl@evledraar.gmail.com","subject":"Re: [PATCH v2] sha256: add support for Nettle","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-07-10T16:39:18Z","receivedAt":"2022-07-10T16:39:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n> This just carries forward existing technical debt, but it's unfortunate\n> that we don't catch OPENSSL_SHA256 overridding NETTLE_SHA256, and error\n> if both are defined.\n\nYou are mistaken, unless I am ;-)  \n\nAllowing users to list whatever is available, instead of requiring\nall users to choose only one, is a deliberate feature in the\narrangement, so it is not unfortunate and it would be breaking\nend-user expectation if we gave an error when more than one is\ngiven (and it would be easier to write and maintain autoconf rules\nfor the feature---we do not want to have two places that makes\ndecisions on precedence).\n\n\n"},{"id":"458727","messageId":"Yssyt40xrxjtaL6m@tapette.crustytoothpaste.net","threadId":"58107","inReplyTo":"xmqqwnckrkg9.fsf@gitster.g","subject":"Re: [PATCH v2] sha256: add support for Nettle","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2022-07-10T20:12:39Z","receivedAt":"2022-07-10T20:12:52Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2022-07-10 at 16:39:18, Junio C Hamano wrote:\n> Allowing users to list whatever is available, instead of requiring\n> all users to choose only one, is a deliberate feature in the\n> arrangement, so it is not unfortunate and it would be breaking\n> end-user expectation if we gave an error when more than one is\n> given (and it would be easier to write and maintain autoconf rules\n> for the feature---we do not want to have two places that makes\n> decisions on precedence).\n\nYeah, I think given the fact that many folks use autoconf, it's\nbeneficial to allow multiple options and just choose the one we like the\nmost.\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"458728","messageId":"xmqqa69gr9ei.fsf@gitster.g","threadId":"58107","inReplyTo":"Yssyt40xrxjtaL6m@tapette.crustytoothpaste.net","subject":"Re: [PATCH v2] sha256: add support for Nettle","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-07-10T20:37:57Z","receivedAt":"2022-07-10T20:40:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> Yeah, I think given the fact that many folks use autoconf, it's\n> beneficial to allow multiple options and just choose the one we like the\n> most.\n\nNot that we any of *_SHA256 set in the configure script ;-) It still\nis worth noting that the Makefile is prepared to deal with configure\nscripts written in the most simple way, i.e. test for any backend\nindependent of other possible backends.\n\nThere can be at least three possible arrangements, and I think the\ncurrent one is the most sensible.\n\n (1) We can allow multiple to be set and let Makefile define\n     precedence.  \"If you do not choose any, then we fall back to\n     ...\" will fall out as a natural consequence.  \n\n     If somebody wants to write autoconf support, they do not have\n     to reinvent the precedence order.  They can just check for the\n     presence of individual libraries independently from each other.\n\n     This is what we have today.\n\n (2) We can allow multiple to be set and let Makefile define\n     precedence.  But a misguided autoconf author can invent their\n     own precedence order that may not be compatible with what the\n     Makefile has.\n\n     This allows the autoconf author weird satisifaction for being\n     different from what Makefile already decided for the sake of\n     being different.\n\n     This would be unfortunate, and we should watch out when we\n     review patches to add autoconf support for *_SHA256 variables.\n\n (3) We can allow only one to be set and otherwise error out.\n\n     If somebody wants to write autoconf support, they have to come\n     up with the precedence order, or support the \"--with[out]-X\"\n     thing to customize, in order to ensure that the configure\n     script picks exactly one.\n\n     Because not everybody has nor need to have enough knowledge to\n     choose one among the multiple choices available to them, this\n     is hostile to those who do not use configure.\n\n     Not an improvement over what we have today.\n\n"},{"id":"462250","messageId":"a1a0672b-4f6b-debd-34d1-bbd9e60f520e@rzmahdi.ir","threadId":"58107","inReplyTo":"xmqqa69gr9ei.fsf@gitster.g","subject":"Re: [PATCH v2] sha256: add support for Nettle","fromName":"Reza Mahdi","fromEmail":"admin@rzmahdi.ir","sentAt":"2022-08-31T05:34:31Z","receivedAt":"2022-08-31T05:36:09Z","isPatch":true,"sender":{"key":"admin@rzmahdi.ir","avatar":null},"body":"On 7/11/2022 1:07 AM, Junio C Hamano wrote:\n>   (3) We can allow only one to be set and otherwise error out.\n> \n>       If somebody wants to write autoconf support, they have to come\n>       up with the precedence order, or support the \"--with[out]-X\"\n>       thing to customize, in order to ensure that the configure\n>       script picks exactly one.\n> \n>       Because not everybody has nor need to have enough knowledge to\n>       choose one among the multiple choices available to them, this\n>       is hostile to those who do not use configure.\n> \n>       Not an improvement over what we have today.\n\nI think this is the most used and familiar to folk. There is no need\nto have multiple options since all of backends work perfectly.\n\nAnd, of curse \"--with-X\" option must be meaningful when the sha256 is\nenabled.\n"}]}