-
Notifications
You must be signed in to change notification settings - Fork 8.2k
crypto: Fix SHA-256 padding length field to 64-bit #98616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
crypto: Fix SHA-256 padding length field to 64-bit #98616
Conversation
2fde922 to
e89942d
Compare
e89942d to
329192f
Compare
The SHA-256 standard (FIPS 180-4) requires the total message
length (L) in bits to be appended as a 64-bit big-endian
integer across words W[14] and W[15] of the final block.
The previous code incorrectly calculated and wrote only the
lower 32 bits of the length (to W[15]). This failed
for messages longer than 2^{32}/8 bytes and relied on
W[14] being pre-zeroed.
This commit updates the SHA handlers for both it51xxx and
it8xxx2 to explicitly calculate L as a `uint64_t`. It then
correctly writes both the MSB (W[14]) and the LSB (W[15])
words in the required big-endian format.
This ensures standard compliance and correct hashing.
Signed-off-by: Badr Bacem KAABIA <[email protected]>
329192f to
c90121b
Compare
Commit message changed as requested. |
|
|
I have nothing more to say on this, my approval is still valid and not overridden (but I am not a maintainer with merge rights on the code) I believe currently many maintainers are busy with the release engineering process (and anyway during the release merges are usually suspended). So please wait, nothing to do on this PR at the moment Thanks for the contribution |



Fixes #98952
The SHA-256 standard (FIPS 180-4) requires the total message length (L) in bits to be appended as a 64-bit big-endian integer.
The previous implementation incorrectly calculated and wrote only the lower 32 bits of the length field (to W[15]), implicitly assuming the upper 32 bits (W[14]) were correctly zeroed.
This commit updates
it51xxx_hash_handler()to explicitly calculate the length usinguint64_tand writes both the MSB (W[14]) and LSB (W[15]) words in big-endian format. This ensures standard compliance and correct hashing for all message lengths.Reference: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf