Skip to content

perf(k12): remove redundant 8KiB buffer zeroing in process_chunk#761

Open
Galoretka wants to merge 2 commits intoRustCrypto:masterfrom
Galoretka:perf/k12-remove-redundant-buffer-zeroing
Open

perf(k12): remove redundant 8KiB buffer zeroing in process_chunk#761
Galoretka wants to merge 2 commits intoRustCrypto:masterfrom
Galoretka:perf/k12-remove-redundant-buffer-zeroing

Conversation

@Galoretka
Copy link
Copy Markdown

The buffer was zeroed after each full chunk in KangarooTwelveCore::process_chunk(). This is unnecessary because subsequent reads only consume [..bufpos] and bufpos is reset to 0. Removing the memset avoids extra work on long inputs and aligns with the project’s pattern of cleaning sensitive data via Drop under the zeroize feature.

@tarcieri
Copy link
Copy Markdown
Member

tarcieri commented Dec 1, 2025

This is unnecessary because subsequent reads only consume [..bufpos]

I would feel better about that if there were a debug_assert_eq!(self.bufpos, CHUNK_SIZE) for the if self.chain_length == 0 above, though I guess if that weren't the case it could be unnecessarily hashing zeros

@newpavlov
Copy link
Copy Markdown
Member

I wonder why the implementation simply does not use CHUNK_SIZE for block size.

@tarcieri
Copy link
Copy Markdown
Member

tarcieri commented Dec 2, 2025

@newpavlov IIUC, the block size is implicitly CHUNK_SIZE unless chaining is being used

@Galoretka
Copy link
Copy Markdown
Author

This is unnecessary because subsequent reads only consume [..bufpos]

I would feel better about that if there were a debug_assert_eq!(self.bufpos, CHUNK_SIZE) for the if self.chain_length == 0 above, though I guess if that weren't the case it could be unnecessarily hashing zeros

corrected

@tarcieri
Copy link
Copy Markdown
Member

Oof, sorry this one went by the wayside.

@Galoretka can you rebase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants