RustCrypto / hashes

Collection of cryptographic hash functions written in pure Rust
1.84k stars 247 forks source link

Strange quirk in SHA256 impl #525

Closed conradludgate closed 9 months ago

conradludgate commented 9 months ago

https://github.com/RustCrypto/hashes/blob/74dcc278daabd787ed9ec30c66616aa729ae6bbc/sha2/src/sha256/soft.rs#L46-L51

The code appears to be doing rotate_left(x, 7) ^ rotate_left(x, 18) ^ shift_left(x, 3), whereas the specification has these flipped:

Screenshot_2024-01-05-08-25-21-55_3aea4af51f236e4932235fdada7d1643

This turns out to be ok because the shl and shr functions are also flipped:

https://github.com/RustCrypto/hashes/blob/74dcc278daabd787ed9ec30c66616aa729ae6bbc/sha2/src/sha256/soft.rs#L5-L13

So, nothing is broken, just a weird quirk. Should probably be renamed

tarcieri commented 9 months ago

The labels for these do appear to be swapped