git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v5 10/12] Add a base implementation of SHA-256 support

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Nov 7, 2018, 01:30 UTC
Message-ID
<20181107013026.GD890086@genre.crustytoothpaste.net>
In-Reply-To
<87h8gv7nz1.fsf@evledraar.gmail.com>
On Mon, Nov 05, 2018 at 12:39:14PM +0100, Ævar Arnfjörð Bjarmason wrote:
Show 12 quoted lines
> On Sun, Nov 04 2018, brian m. carlson wrote:
> > +	{
> > +		"sha256",
> > +		/* "s256", big-endian */
> 
> The existing entry/comment for sha1 is:
> 
> 		"sha1",
> 		/* "sha1", big-endian */
> 
> So why the sha256/s256 difference in the code/comment? Wondering if I'm
> missing something and we're using "s256" for something.

Ah, good question. The comment refers to the format_id field which follows this comment. The value is the big-endian representation of "s256" as a 32-bit value. I picked that over "sha2" to avoid confusion in case we add SHA-512 in the future, since that's also an SHA-2 algorithm.

Config files and command-line interfaces will use "sha1" or "sha256", and binary formats will use those 32-bit values ("sha1" or "s256").

Show 6 quoted lines
> >  const char *empty_tree_oid_hex(void)
> > diff --git a/sha256/block/sha256.c b/sha256/block/sha256.c
> > [...]
> 
> I had a question before about whether we see ourselves perma-forking
> this implementation based off libtomcrypt, as I recall you said yes.
Yes.
> Still, I think it would be better to introduce this in at least two-four
> commits where the upstream code is added as-is, then trimmed down to
> size, then adapted to our coding style, and finally we add our own
> utility functions.

At this point, the only code that's actually used from libtomcrypt is the block transform. The upstream code is split over multiple files in multiple directories and won't compile in our codebase without many files and a lot of work, so I don't feel good about either including code that doesn't compile or including large numbers of files that don't meet our coding standards (and that may still not compile because of platform issues).

> It'll make it easier to forward-port any future upstream changes.

I don't foresee many, if any, changes to this code. It either implements the specification or it doesn't, and it's objectively easy to determine which. There's not even an argument to port performance improvements, since almost everyone will be using a crypto library to provide this code because libraries perform so dramatically better. I've tried to not make the code perform worse than it did originally, but that's it.

Furthermore, the modified code carries a relatively small amount of resemblance to the original, so if we did port changes forward, we'd probably have conflicts.

It seems like you really want to include the upstream code as a separate commit and I understand where you're coming from with wanting to have this split out into logical commits, but due to the specific nature of this code, I see a lot of downsides and not a lot of upsides.

Show 9 quoted lines
> > +	perl -E "for (1..100000) { print q{aaaaaaaaaa}; }" | \
> > +		test-tool sha256 >actual &&
> > +	grep cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0 actual &&
> > +	perl -E "for (1..100000) { print q{abcdefghijklmnopqrstuvwxyz}; }" | \
> > +		test-tool sha256 >actual &&
> 
> I've been wanting to make use depend on perl >= 5.10 (previous noises
> about that on-list), but for now we claim to support >=5.8, which
> doesn't have the -E switch.

Good point. I'll fix that. After having written a lot of one-liners, I always write -E, and this was originally a one-liner.

Show 5 quoted lines
> But most importantly you aren't even using -E features here, and this
> isn't very idoimatic Perl. Instead do, respectively:
> 
>     perl -e 'print q{aaaaaaaaaa} x 100000'
>     perl -e "print q{abcdefghijklmnopqrstuvwxyz} x 100000"

I considered the more idiomatic version originally, but the latter could allocate a decent amount of memory in one chunk, and I wanted to avoid that. I think what I'd like to do, actually, is turn on autoflush and use a postfix for, which would be more idiomatic and could potentially provide better testing of the chunking code. I'll add a comment to that effect.

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 41 of 58 in “Base SHA-256 implementation”
  1. 00/12 Base SHA-256 implementationbrian m. carlson, Oct 25, 2018
  2. 01/12 sha1-file: rename algorithm to "sha1"brian m. carlson, Oct 25, 2018
  3. 02/12 sha1-file: provide functions to look up hash algorithmsbrian m. carlson, Oct 25, 2018
  4. 03/12 hex: introduce functions to print arbitrary hashesbrian m. carlson, Oct 25, 2018
  5. 04/12 cache: make hashcmp and hasheq work with larger hashesbrian m. carlson, Oct 25, 2018
  6. 05/12 t: add basic tests for our SHA-1 implementationbrian m. carlson, Oct 25, 2018
  7. 06/12 t: make the sha1 test-tool helper genericbrian m. carlson, Oct 25, 2018
  8. 07/12 sha1-file: add a constant for hash block sizebrian m. carlson, Oct 25, 2018
  9. 08/12 t/helper: add a test helper to compute hash speedbrian m. carlson, Oct 25, 2018
  10. 09/12 commit-graph: convert to using the_hash_algobrian m. carlson, Oct 25, 2018
  11. 10/12 Add a base implementation of SHA-256 supportbrian m. carlson, Oct 25, 2018
  12. Carlo ArenasOct 25, 2018
  13. brian m. carlsonOct 28, 2018
  14. Junio C HamanoOct 29, 2018
  15. brian m. carlsonOct 31, 2018
  16. Junio C HamanoNov 1, 2018
  17. Christian CouderOct 27, 2018
  18. 11/12 sha256: add an SHA-256 implementation using libgcryptbrian m. carlson, Oct 25, 2018
  19. 12/12 hash: add an SHA-256 implementation using OpenSSLbrian m. carlson, Oct 25, 2018
  20. 00/12 Base SHA-256 implementationbrian m. carlson, Nov 4, 2018
  21. 01/12 sha1-file: rename algorithm to "sha1"brian m. carlson, Nov 4, 2018
  22. Ævar Arnfjörð BjarmasonNov 5, 2018
  23. 02/12 sha1-file: provide functions to look up hash algorithmsbrian m. carlson, Nov 4, 2018
  24. Derrick StoleeNov 13, 2018
  25. Duy NguyenNov 13, 2018
  26. brian m. carlsonNov 14, 2018
  27. Ramsay JonesNov 14, 2018
  28. Ramsay JonesNov 14, 2018
  29. Jeff KingNov 14, 2018
  30. brian m. carlsonNov 14, 2018
  31. Ramsay JonesNov 14, 2018
  32. 03/12 hex: introduce functions to print arbitrary hashesbrian m. carlson, Nov 4, 2018
  33. 05/12 t: add basic tests for our SHA-1 implementationbrian m. carlson, Nov 4, 2018
  34. 04/12 cache: make hashcmp and hasheq work with larger hashesbrian m. carlson, Nov 4, 2018
  35. 07/12 sha1-file: add a constant for hash block sizebrian m. carlson, Nov 4, 2018
  36. 06/12 t: make the sha1 test-tool helper genericbrian m. carlson, Nov 4, 2018
  37. 08/12 t/helper: add a test helper to compute hash speedbrian m. carlson, Nov 4, 2018
  38. 09/12 commit-graph: convert to using the_hash_algobrian m. carlson, Nov 4, 2018
  39. 10/12 Add a base implementation of SHA-256 supportbrian m. carlson, Nov 4, 2018
  40. Ævar Arnfjörð BjarmasonNov 5, 2018
  41. brian m. carlsonNov 7, 2018
  42. Ævar Arnfjörð BjarmasonNov 10, 2018
  43. 11/12 sha256: add an SHA-256 implementation using libgcryptbrian m. carlson, Nov 4, 2018
  44. 12/12 hash: add an SHA-256 implementation using OpenSSLbrian m. carlson, Nov 4, 2018
  45. Junio C HamanoNov 5, 2018
  46. 00/12 Base SHA-256 implementationbrian m. carlson, Nov 14, 2018
  47. 01/12 sha1-file: rename algorithm to "sha1"brian m. carlson, Nov 14, 2018
  48. 02/12 sha1-file: provide functions to look up hash algorithmsbrian m. carlson, Nov 14, 2018
  49. 03/12 hex: introduce functions to print arbitrary hashesbrian m. carlson, Nov 14, 2018
  50. 04/12 cache: make hashcmp and hasheq work with larger hashesbrian m. carlson, Nov 14, 2018
  51. 06/12 t: make the sha1 test-tool helper genericbrian m. carlson, Nov 14, 2018
  52. 05/12 t: add basic tests for our SHA-1 implementationbrian m. carlson, Nov 14, 2018
  53. 07/12 sha1-file: add a constant for hash block sizebrian m. carlson, Nov 14, 2018
  54. 08/12 t/helper: add a test helper to compute hash speedbrian m. carlson, Nov 14, 2018
  55. 09/12 commit-graph: convert to using the_hash_algobrian m. carlson, Nov 14, 2018
  56. 10/12 Add a base implementation of SHA-256 supportbrian m. carlson, Nov 14, 2018
  57. 11/12 sha256: add an SHA-256 implementation using libgcryptbrian m. carlson, Nov 14, 2018
  58. 12/12 hash: add an SHA-256 implementation using OpenSSLbrian m. carlson, Nov 14, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.