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

[PATCH v5 05/12] t: add basic tests for our SHA-1 implementation

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Nov 4, 2018, 23:44 UTC
Message-ID
<20181104234458.139223-6-sandals@crustytoothpaste.net>
In-Reply-To
<20181104234458.139223-1-sandals@crustytoothpaste.net>

We have in the past had some unfortunate endianness issues with some SHA-1 implementations we ship, especially on big-endian machines. Add an explicit test using the test helper to catch these issues and point them out prominently. This test can also be used as a staging ground for people testing additional algorithms to verify that their implementations are working as expected.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t0015-hash.sh | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100755 t/t0015-hash.sh
diff --git a/t/t0015-hash.sh b/t/t0015-hash.sh
new file mode 100755
index 0000000000..8e763c2c3d
--- /dev/null
+++ b/t/t0015-hash.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+test_description='test basic hash implementation'
+. ./test-lib.sh
+
+
+test_expect_success 'test basic SHA-1 hash values' '
+	test-tool sha1 </dev/null >actual &&
+	grep da39a3ee5e6b4b0d3255bfef95601890afd80709 actual &&
+	printf "a" | test-tool sha1 >actual &&
+	grep 86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 actual &&
+	printf "abc" | test-tool sha1 >actual &&
+	grep a9993e364706816aba3e25717850c26c9cd0d89d actual &&
+	printf "message digest" | test-tool sha1 >actual &&
+	grep c12252ceda8be8994d5fa0290a47231c1d16aae3 actual &&
+	printf "abcdefghijklmnopqrstuvwxyz" | test-tool sha1 >actual &&
+	grep 32d10c7b8cf96570ca04ce37f2a19d84240d3a89 actual &&
+	perl -E "for (1..100000) { print q{aaaaaaaaaa}; }" | \
+		test-tool sha1 >actual &&
+	grep 34aa973cd4c4daa4f61eeb2bdbad27316534016f actual &&
+	printf "blob 0\0" | test-tool sha1 >actual &&
+	grep e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 actual &&
+	printf "blob 3\0abc" | test-tool sha1 >actual &&
+	grep f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f actual &&
+	printf "tree 0\0" | test-tool sha1 >actual &&
+	grep 4b825dc642cb6eb9a060e54bf8d69288fbee4904 actual
+'
+
+test_done
Previous: brian m. carlsonNext: brian m. carlson
Message 33 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.