Rust wrapper: add copy() to SHA256 and SHA384 via wc_Sha256Copy/wc_Sha384Copy#10425
Open
MarkAtwood wants to merge 2 commits intowolfSSL:masterfrom
Open
Rust wrapper: add copy() to SHA256 and SHA384 via wc_Sha256Copy/wc_Sha384Copy#10425MarkAtwood wants to merge 2 commits intowolfSSL:masterfrom
MarkAtwood wants to merge 2 commits intowolfSSL:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the Rust wolfssl-wolfcrypt SHA wrappers to support O(1) snapshotting of in-progress transcript hashes by adding copy() methods backed by wolfCrypt’s wc_Sha256Copy and wc_Sha384Copy.
Changes:
- Add
SHA256::copy()implemented viawc_Sha256Copy. - Add
SHA384::copy()implemented viawc_Sha384Copy.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+648
to
+652
| /// # Panics | ||
| /// | ||
| /// Panics if the underlying `wc_Sha256Copy` call fails (should not occur | ||
| /// under normal conditions). | ||
| fn clone(&self) -> Self { |
Comment on lines
+881
to
+886
| /// Panics if the underlying `wc_Sha384Copy` call fails (should not occur | ||
| /// under normal conditions). | ||
| fn clone(&self) -> Self { | ||
| let mut dst: core::mem::MaybeUninit<sys::wc_Sha384> = core::mem::MaybeUninit::uninit(); | ||
| let rc = unsafe { sys::wc_Sha384Copy(&self.wc_sha384 as *const _ as *mut _, dst.as_mut_ptr()) }; | ||
| assert_eq!(rc, 0, "wc_Sha384Copy failed: {rc}"); |
| /// Allows the same in-progress computation to be continued independently | ||
| /// from the same point, e.g. for transcript snapshotting in TLS. | ||
| /// | ||
| /// # Panics |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the
Clonetrait forSHA256andSHA384, backed bywc_Sha256Copyandwc_Sha384Copyrespectively.This allows mid-computation hash state to be cloned into an independent context in O(1), without re-hashing from scratch. The motivating use case is the rustls TLS provider, which needs to snapshot transcript hash state at multiple points during the handshake.
Changes
wrapper/rust/wolfssl-wolfcrypt/src/sha.rs: implementCloneforSHA256andSHA384usingMaybeUninitand the corresponding C copy functions via FFI. Panics on copy failure (should not occur under normal conditions).Notes