Skip to content

sponge-cursor: initial implementation#1477

Open
newpavlov wants to merge 3 commits intomasterfrom
add-sponge-cursor
Open

sponge-cursor: initial implementation#1477
newpavlov wants to merge 3 commits intomasterfrom
add-sponge-cursor

Conversation

@newpavlov
Copy link
Copy Markdown
Member

@newpavlov newpavlov commented May 2, 2026

sponge-cursor is a helper crate which allows to remove unnecessary buffering from sponge-based constructions.

TODO: add tests, examples, and CI config

Comment thread sponge-cursor/src/lib.rs
let mut buf = Array::<u8, Rate>::default();
let mut chunks = buf.chunks_exact_mut(size_of::<u64>());
for (src, dst) in state.iter().zip(&mut chunks) {
dst.copy_from_slice(&src.to_le_bytes());
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation of xor_in and read_into for big-endian targets is quite sub-optimal, but I prioritized simplicity of implementation. Considering that big-endian targets are practically extinct, I think it's a fine trade-off. We could easily improve it in future if someone interested in it.

Comment thread sponge-cursor/src/lib.rs
/// `Rate` MUST be smaller than `U256`, trying to initialize cursor with an invalid rate will
/// result in a compilation error.
#[derive(Debug, Clone)]
pub struct SpongeCursor<Rate: ArraySize> {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to implement the crate using const generics (i.e. const RATE: usize instead of Rate: ArraySize>), but it would not work with generic rates (e.g. in cshake) since we can not currently use SpongeCursor<{ Rate::USIZE }>.

We could drop the BlockSizeUser impl and use const generic rates in implementation crates (since they are unlikely to be used with HMAC), but I am not sure whether we should do it.

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.

1 participant