Re: [PATCH] lib/crypto: sha1: use put_unaligned_be64() for length encoding
From: Mohamad Raizudeen
Date: Sun Oct 11 2026 - 05:15:35 EST
On Sun, Oct 11, 2026 at 03:10:44PM +0900, Simon Richter wrote:
> Hi,
>
> On 10/11/26 14:15, Mohamad Raizudeen wrote:
>
> > The rest of this file already uses the unaligned access helpers like
> > get_unaligned_be32() for reading input and put_unaligned_be32() for writing
> > the digest, for all structured buffer accesses. Replace both casts with
> > put_unaligned_be64() for consistency.
>
> These aren't unaligned accesses, though.
>
> > In hmac_sha1_final(), this also writes the full 64-bit length field
> > explicitly rather than writing only 32 bits and relying on a preceding
> > memset() to zero the upper 32 bits. The resulting bytes are identical,
> > nothing changes functionally.
>
> These aren't unaligned either, and the size here is fixed (which is also why
> we don't need to handle the case where the size does not fit into the
> current block).
>
> The get_unaligned and put_unaligned functions aren't used as convenience
> functions, but because the data might actually be unaligned, so we need to
> eat the cost of doing an unaligned access.
>
> Simon
Hi,
Well, you are right. My patch would have added unnecessary overhead on
strict alignment architectures.
Withdrawing this patch.
Thanks,
Mohamad Raizudeen