Skip to content

Rust wrapper: check DH::shared_secret buffer size against prime size#10924

Merged
JacobBarthelmeh merged 1 commit into
wolfSSL:masterfrom
holtrop-wolfssl:zd22155
Jul 16, 2026
Merged

Rust wrapper: check DH::shared_secret buffer size against prime size#10924
JacobBarthelmeh merged 1 commit into
wolfSSL:masterfrom
holtrop-wolfssl:zd22155

Conversation

@holtrop-wolfssl

Copy link
Copy Markdown
Contributor

Description

Rust wrapper: check DH::shared_secret buffer size against prime size

The underlying C API treats the agreeSz parameter as output-only.

Fixes ZD#22155

Testing

How did you test?

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@holtrop-wolfssl holtrop-wolfssl self-assigned this Jul 16, 2026
Copilot AI review requested due to automatic review settings July 16, 2026 03:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 hardens the Rust DH::shared_secret() wrapper by ensuring the caller-provided output buffer is large enough for the maximum possible DH shared secret (prime-sized), preventing a potential write past the end of the slice due to wc_DhAgree() treating agreeSz as output-only.

Changes:

  • Add DH::prime_size() to query the DH prime (p) size via wc_DhExportParamsRaw() length-only mode.
  • Reject undersized dout buffers in DH::shared_secret() before calling into wc_DhAgree().
  • Add Rust tests validating prime_size() and that undersized shared_secret() buffers are rejected without overwriting adjacent memory.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
wrapper/rust/wolfssl-wolfcrypt/src/dh.rs Adds prime_size() and uses it to preflight shared_secret() output buffer length.
wrapper/rust/wolfssl-wolfcrypt/tests/test_dh.rs Adds tests for prime size and for rejecting undersized shared-secret output buffers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread wrapper/rust/wolfssl-wolfcrypt/src/dh.rs Outdated
Comment thread wrapper/rust/wolfssl-wolfcrypt/src/dh.rs Outdated
Comment thread wrapper/rust/wolfssl-wolfcrypt/tests/test_dh.rs
The underlying C API treats the agreeSz parameter as output-only.
@holtrop-wolfssl

Copy link
Copy Markdown
Contributor Author

retest this please (build removed)

@holtrop-wolfssl

Copy link
Copy Markdown
Contributor Author

retest this please (ERROR: Build 'PRB-fips-ready-config' failed with result: ABORTED)

@JacobBarthelmeh
JacobBarthelmeh merged commit 7a062fd into wolfSSL:master Jul 16, 2026
332 of 335 checks passed
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.

4 participants