Re: [PATCH] lib/crypto: sha1: use put_unaligned_be64() for length encoding

From: Simon Richter

Date: Sun Oct 11 2026 - 02:17:03 EST


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

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature