From c82067334270187ef77d50715a838e3dbbdfea3c Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 23 Mar 2016 17:25:29 +1300 Subject: [PATCH] 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 --- ccan/crypto/sha256/sha256.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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++) -- 2.39.2