Skip to content

ed: Expose hazmat::raw_sign_byupdate() for streamed signing #765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 3, 2025

Conversation

rozbb
Copy link
Contributor

@rozbb rozbb commented Jun 3, 2025

Currently, if you want to sign a serialized object, you have to serialize it in full, then sign it. When memory is constrained, this is hard.

This PR defines a function, hazmat::raw_sign_byupdate, which, rather than taking a single contiguous message slice, takes a Fn(&mut Digest) that knows how to update a hasher with the parts of the message. So, in the case of serialization, the closure will simply serialize each component to a small buffer, do h.update(buf), then fill the buffer with the next serialized component, etc.

This comes from discussion here, here, and hypothetical impl here.

This is feature-gated behind hazmat because it takes an expanded secret key, which is possible to catastrophically misuse.

@mkj

@rozbb rozbb requested a review from tarcieri June 3, 2025 01:25
@rozbb
Copy link
Contributor Author

rozbb commented Jun 3, 2025

I don't see any performance degredation

@mkj
Copy link
Contributor

mkj commented Jun 3, 2025

Thanks. I've tested this PR raw_sign_byupdate() works in my codebase, can the raw_verify_byupdate() also be added? Edit: not thinking - I should just be able to use StreamVerifier.

@mkj
Copy link
Contributor

mkj commented Jun 3, 2025

I guess raw_verify_byupdate() doesn't have any use, I think StreamVerifier covers all those cases.

@mkj
Copy link
Contributor

mkj commented Jun 3, 2025

Tested StreamVerifier works well for my purposes here. Thanks!

@tarcieri
Copy link
Contributor

tarcieri commented Jun 3, 2025

I think an &[&[u8]] API is a lot more foolproof, though this is more flexible

@rozbb rozbb merged commit 08d7176 into main Jun 3, 2025
28 checks passed
@rozbb rozbb deleted the ed-sign-by-update branch June 3, 2025 13:14
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