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.