pico_sha256 produces wrong digest for messages >= 512 MiB #3176

Closed
opened 2026-09-04 08:40:54 -05:00 by erichelgeson · 1 comment
erichelgeson commented 2026-09-04 08:40:54 -05:00 (Migrated from github.com)

write_padding() in src/rp2_common/pico_sha256/sha256.c computes the message length in bits as user_data_size * 8, where user_data_size is a size_t. The multiply wraps at 512 MiB, so the 64-bit length field appended to the final block is wrong and the resulting digest does not match SHA-256 for any input of 512 MiB or larger.

Found while hashing CD images streamed over Wi-Fi in BlueSCSI & PicoIDE.

Fixed in PR: #3177

`write_padding()` in `src/rp2_common/pico_sha256/sha256.c` computes the message length in bits as `user_data_size * 8`, where` user_data_size` is a `size_t`. The multiply wraps at 512 MiB, so the 64-bit length field appended to the final block is wrong and the resulting digest does not match SHA-256 for any input of 512 MiB or larger. Found while hashing CD images streamed over Wi-Fi in BlueSCSI & PicoIDE. Fixed in PR: #3177
kilograham commented 2026-09-04 15:48:54 -05:00 (Migrated from github.com)

merged into develop

merged into develop
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#3176
No description provided.