From: Jon Griffiths Date: Wed, 23 Mar 2016 04:25:29 +0000 (+1300) Subject: sha256: Use fewer magic magic numbers X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=c82067334270187ef77d50715a838e3dbbdfea3c sha256: Use fewer magic magic numbers Show the derivation of the constants to match the comment above them. The compiler doesn't care, but it helps the code read better. Signed-off-by: Jon Griffiths --- diff --git a/ccan/crypto/sha256/sha256.c b/ccan/crypto/sha256/sha256.c index 3307e0b7..21d17c40 100644 --- a/ccan/crypto/sha256/sha256.c +++ b/ccan/crypto/sha256/sha256.c @@ -231,7 +231,7 @@ void sha256_done(struct sha256_ctx *ctx, struct sha256 *res) sizedesc = cpu_to_be64((uint64_t)ctx->bytes << 3); /* Add '1' bit to terminate, then all 0 bits, up to next block - 8. */ - add(ctx, pad, 1 + ((119 - (ctx->bytes % 64)) % 64)); + add(ctx, pad, 1 + ((128 - 8 - (ctx->bytes % 64) - 1) % 64)); /* Add number of bits of data (big endian) */ add(ctx, &sizedesc, 8); for (i = 0; i < sizeof(ctx->s) / sizeof(ctx->s[0]); i++)