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

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

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Oct 22, 2018, 09:44 UTC
Message-ID
<20181022094440.GD30222@szeder.dev>
In-Reply-To
<20181022024342.489564-11-sandals@crustytoothpaste.net>
On Mon, Oct 22, 2018 at 02:43:40AM +0000, brian m. carlson wrote:
Show 10 quoted lines
> diff --git a/sha256/block/sha256.c b/sha256/block/sha256.c
> new file mode 100644
> index 0000000000..683bc6e39b
> --- /dev/null
> +++ b/sha256/block/sha256.c
> @@ -0,0 +1,186 @@
> +#include "git-compat-util.h"
> +#include "./sha256.h"
> +
> +#define BLKSIZE blk_SHA256_BLKSIZE
[...]
Show 8 quoted lines
> +#define Ch(x,y,z)       (z ^ (x & (y ^ z)))
> +#define Maj(x,y,z)      (((x | y) & z) | (x & y))
> +#define S(x, n)         ror((x),(n))
> +#define R(x, n)         ((x)>>(n))
> +#define Sigma0(x)       (S(x, 2) ^ S(x, 13) ^ S(x, 22))
> +#define Sigma1(x)       (S(x, 6) ^ S(x, 11) ^ S(x, 25))
> +#define Gamma0(x)       (S(x, 7) ^ S(x, 18) ^ R(x, 3))
> +#define Gamma1(x)       (S(x, 17) ^ S(x, 19) ^ R(x, 10))
[...]
Show 5 quoted lines
> +#define RND(a,b,c,d,e,f,g,h,i,ki)                    \
> +	t0 = h + Sigma1(e) + Ch(e, f, g) + ki + W[i];   \
> +	t1 = Sigma0(a) + Maj(a, b, c);                  \
> +	d += t0;                                        \
> +	h  = t0 + t1;
[...]
Show 9 quoted lines
> +#undef RND
> +#undef Ch
> +#undef Maj
> +#undef S
> +#undef R
> +#undef Sigma0
> +#undef Sigma1
> +#undef Gamma0
> +#undef Gamma1

To protect us from potential "macro redefinition" errors, these #undefs should come before the #defines above. Note also that BLKSIZE is not #undef-ed.

Previous: brian m. carlsonNext: brian m. carlson
Message 14 of 17 in “Base SHA-256 implementation”
  1. 00/12 Base SHA-256 implementationbrian m. carlson, Oct 22, 2018
  2. 01/12 sha1-file: rename algorithm to "sha1"brian m. carlson, Oct 22, 2018
  3. 02/12 sha1-file: provide functions to look up hash algorithmsbrian m. carlson, Oct 22, 2018
  4. 03/12 hex: introduce functions to print arbitrary hashesbrian m. carlson, Oct 22, 2018
  5. 04/12 cache: make hashcmp and hasheq work with larger hashesbrian m. carlson, Oct 22, 2018
  6. 05/12 t: add basic tests for our SHA-1 implementationbrian m. carlson, Oct 22, 2018
  7. 06/12 t: make the sha1 test-tool helper genericbrian m. carlson, Oct 22, 2018
  8. 07/12 sha1-file: add a constant for hash block sizebrian m. carlson, Oct 22, 2018
  9. 09/12 commit-graph: convert to using the_hash_algobrian m. carlson, Oct 22, 2018
  10. Derrick StoleeOct 24, 2018
  11. 08/12 t/helper: add a test helper to compute hash speedbrian m. carlson, Oct 22, 2018
  12. 11/12 sha256: add an SHA-256 implementation using libgcryptbrian m. carlson, Oct 22, 2018
  13. 10/12 Add a base implementation of SHA-256 supportbrian m. carlson, Oct 22, 2018
  14. SZEDER GáborOct 22, 2018
  15. brian m. carlsonOct 23, 2018
  16. Jakub NarebskiOct 27, 2018
  17. 12/12 hash: add an SHA-256 implementation using OpenSSLbrian m. carlson, Oct 22, 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.