Skip to content

Rust wrapper: add copy() to SHA256 and SHA384 via wc_Sha256Copy/wc_Sha384Copy#10425

Open
MarkAtwood wants to merge 2 commits intowolfSSL:masterfrom
MarkAtwood:feat/rust-sha-copy
Open

Rust wrapper: add copy() to SHA256 and SHA384 via wc_Sha256Copy/wc_Sha384Copy#10425
MarkAtwood wants to merge 2 commits intowolfSSL:masterfrom
MarkAtwood:feat/rust-sha-copy

Conversation

@MarkAtwood
Copy link
Copy Markdown
Contributor

@MarkAtwood MarkAtwood commented May 7, 2026

Summary

Implements the Clone trait for SHA256 and SHA384, backed by wc_Sha256Copy and wc_Sha384Copy respectively.

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: implement Clone for SHA256 and SHA384 using MaybeUninit and the corresponding C copy functions via FFI. Panics on copy failure (should not occur under normal conditions).

Notes

  • No public API breaking changes.
  • No new dependencies.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 via wc_Sha256Copy.
  • Add SHA384::copy() implemented via wc_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
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

MemBrowse Memory Report

No memory changes detected for:

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.

2 participants