Closed conradludgate closed 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:
rotate_left(x, 7) ^ rotate_left(x, 18) ^ shift_left(x, 3)
This turns out to be ok because the shl and shr functions are also flipped:
shl
shr
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
The labels for these do appear to be swapped
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:This turns out to be ok because the
shl
andshr
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