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

[RFC PATCH 00/12] Base SHA-256 algorithm implementation

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Aug 29, 2018, 00:58 UTC
Message-ID
<20180829005857.980820-1-sandals@crustytoothpaste.net>

This RFC series provides an actual SHA-256 implementation and wires it up, along with a few housekeeping patches to make it usable for testing.

As discussed in some threads, this changes the algorithm name from "sha-1" to "sha1" (and also adds "sha256") because it's far easier to type.

I introduced some basic tests for the hash algorithms in use. Since I did not import the SHA-256 implementation verbatim, I felt it was necessary to ensure that the hash algorithm implementations continued to function as expected. My main changes were to adjust the code to use our endianness functions, to adopt something closer to our style, and to make use of memcpy and friends for performance reasons.

I opted to place all the implementation code for SHA-256 into one directory, as opposed to the various directories we have for the SHA-1 implementations, mostly for tidiness and ease of use.

I wired up OpenSSL because we already have it and libgcrypt because it performs better than SHA-1. I didn't provide an implementation for SHA-1 with libgcrypt because everybody should be using SHA1DC for security.

I didn't provide an implementation based on libnettle because its x86-64 assembly implementation isn't vectorized and is pretty slow. Since this was written before I had access to a Mac, Apple Common Crypto hasn't been wired up, either. Patches welcome.

If libgit2 would like to import this SHA-256 implementation, they're welcome to do so under their normal license terms. If not, that's fine, too.

brian m. carlson (12):
  sha1-file: rename algorithm to "sha1"
  sha1-file: provide functions to look up hash algorithms
  hex: introduce functions to print arbitrary hashes
  t: add basic tests for our SHA-1 implementation
  t: make the sha1 test-tool helper generic
  sha1-file: add a constant for hash block size
  t/helper: add a test helper to compute hash speed
  commit-graph: convert to using the_hash_algo
  Add a base implementation of SHA-256 support
  sha256: add an SHA-256 implementation using libgcrypt
  hash: add an SHA-256 implementation using OpenSSL
  commit-graph: specify OID version for SHA-256
 Makefile                              |  22 ++++
 cache.h                               |  28 ++--
 commit-graph.c                        |  38 +++---
 hash.h                                |  41 +++++-
 hex.c                                 |  32 +++--
 sha1-file.c                           |  70 +++++++++-
 sha256/block/sha256.c                 | 180 ++++++++++++++++++++++++++
 sha256/block/sha256.h                 |  26 ++++
 sha256/gcrypt.h                       |  30 +++++
 t/helper/test-hash-speed.c            |  61 +++++++++
 t/helper/{test-sha1.c => test-hash.c} |  19 +--
 t/helper/test-sha1.c                  |  52 +-------
 t/helper/test-sha256.c                |   7 +
 t/helper/test-tool.c                  |   2 +
 t/helper/test-tool.h                  |   4 +
 t/t0014-hash.sh                       |  54 ++++++++
 16 files changed, 573 insertions(+), 93 deletions(-)
 create mode 100644 sha256/block/sha256.c
 create mode 100644 sha256/block/sha256.h
 create mode 100644 sha256/gcrypt.h
 create mode 100644 t/helper/test-hash-speed.c
 copy t/helper/{test-sha1.c => test-hash.c} (66%)
 create mode 100644 t/helper/test-sha256.c
 create mode 100755 t/t0014-hash.sh
Next: brian m. carlson
Message 1 of 24 in “Base SHA-256 algorithm implementation”
  1. 00/12 Base SHA-256 algorithm implementationbrian m. carlson, Aug 29, 2018
  2. 01/12 sha1-file: rename algorithm to "sha1"brian m. carlson, Aug 29, 2018
  3. 03/12 hex: introduce functions to print arbitrary hashesbrian m. carlson, Aug 29, 2018
  4. 04/12 t: add basic tests for our SHA-1 implementationbrian m. carlson, Aug 29, 2018
  5. 05/12 t: make the sha1 test-tool helper genericbrian m. carlson, Aug 29, 2018
  6. 07/12 t/helper: add a test helper to compute hash speedbrian m. carlson, Aug 29, 2018
  7. 06/12 sha1-file: add a constant for hash block sizebrian m. carlson, Aug 29, 2018
  8. 08/12 commit-graph: convert to using the_hash_algobrian m. carlson, Aug 29, 2018
  9. Derrick StoleeAug 29, 2018
  10. brian m. carlsonAug 30, 2018
  11. brian m. carlsonSep 3, 2018
  12. 09/12 Add a base implementation of SHA-256 supportbrian m. carlson, Aug 29, 2018
  13. Ævar Arnfjörð BjarmasonAug 29, 2018
  14. brian m. carlsonAug 29, 2018
  15. Derrick StoleeAug 29, 2018
  16. 10/12 sha256: add an SHA-256 implementation using libgcryptbrian m. carlson, Aug 29, 2018
  17. Ævar Arnfjörð BjarmasonAug 29, 2018
  18. brian m. carlsonAug 29, 2018
  19. 11/12 hash: add an SHA-256 implementation using OpenSSLbrian m. carlson, Aug 29, 2018
  20. 12/12 commit-graph: specify OID version for SHA-256brian m. carlson, Aug 29, 2018
  21. 02/12 sha1-file: provide functions to look up hash algorithmsbrian m. carlson, Aug 29, 2018
  22. Ævar Arnfjörð BjarmasonAug 29, 2018
  23. brian m. carlsonAug 30, 2018
  24. brian m. carlsonAug 30, 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.