Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/crypto: sha256: Sync sha256_update() with sha512_update()

The BLOCK_HASH_UPDATE_BLOCKS macro is difficult to read. For now, let's
just write the update explicitly in the straightforward way, mirroring
sha512_update(). It's possible that we'll bring back a macro for this
later, but it needs to be properly justified and hopefully a bit more
readable.

Acked-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20250630160645.3198-14-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

+25 -3
+25 -3
lib/crypto/sha256.c
··· 10 10 */ 11 11 12 12 #include <crypto/hmac.h> 13 - #include <crypto/internal/blockhash.h> 14 13 #include <crypto/sha2.h> 15 14 #include <linux/export.h> 16 15 #include <linux/kernel.h> ··· 179 180 size_t partial = ctx->bytecount % SHA256_BLOCK_SIZE; 180 181 181 182 ctx->bytecount += len; 182 - BLOCK_HASH_UPDATE_BLOCKS(sha256_blocks, &ctx->state, data, len, 183 - SHA256_BLOCK_SIZE, ctx->buf, partial); 183 + 184 + if (partial + len >= SHA256_BLOCK_SIZE) { 185 + size_t nblocks; 186 + 187 + if (partial) { 188 + size_t l = SHA256_BLOCK_SIZE - partial; 189 + 190 + memcpy(&ctx->buf[partial], data, l); 191 + data += l; 192 + len -= l; 193 + 194 + sha256_blocks(&ctx->state, ctx->buf, 1); 195 + } 196 + 197 + nblocks = len / SHA256_BLOCK_SIZE; 198 + len %= SHA256_BLOCK_SIZE; 199 + 200 + if (nblocks) { 201 + sha256_blocks(&ctx->state, data, nblocks); 202 + data += nblocks * SHA256_BLOCK_SIZE; 203 + } 204 + partial = 0; 205 + } 206 + if (len) 207 + memcpy(&ctx->buf[partial], data, len); 184 208 } 185 209 EXPORT_SYMBOL(__sha256_update); 186 210