fix: EVP_DigestSignUpdate/VerifyUpdate accept size_t, not unsigned int#10365
Open
MarkAtwood wants to merge 2 commits into
Open
fix: EVP_DigestSignUpdate/VerifyUpdate accept size_t, not unsigned int#10365MarkAtwood wants to merge 2 commits into
MarkAtwood wants to merge 2 commits into
Conversation
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #10365
Scan targets checked: wolfcrypt-bugs, wolfcrypt-src
No new issues found in the changed files. ✅
Contributor
There was a problem hiding this comment.
Pull request overview
Aligns wolfSSL’s OpenSSL-compat EVP DigestSign/DigestVerify update APIs with OpenSSL’s size_t count type to restore source-level compatibility (including FFI bindings) and prevent silent truncation on 64-bit platforms.
Changes:
- Update
wolfSSL_EVP_DigestSignUpdate’s public declaration/definition to acceptsize_t cnt. - Change the shared internal helper to accept
size_tand add an overflow guard before narrowing forwc_HmacUpdate. - Add a regression test covering
size_tusage and the oversized-count failure behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| wolfssl/openssl/evp.h | Changes wolfSSL_EVP_DigestSignUpdate(..., cnt) to size_t for OpenSSL API parity. |
| wolfcrypt/src/evp.c | Updates helper + removes narrowing cast; adds overflow guard for HMAC update path. |
| tests/api/test_evp_pkey.h | Registers new EVP PKEY test in declarations list. |
| tests/api/test_evp_pkey.c | Adds regression test validating size_t usage and overflow handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Member
|
@MarkAtwood please resolve merge conflicts. |
EVP_DigestSignUpdate was declared with unsigned int for the count parameter, unlike OpenSSL's size_t. EVP_DigestVerifyUpdate had the right declaration but cast the size_t to unsigned int before passing it to the internal helper, silently truncating counts > UINT_MAX. Fix all three sites: - wolfssl_evp_digest_pk_update internal helper: unsigned int -> size_t - wolfSSL_EVP_DigestSignUpdate: unsigned int -> size_t in decl + defn - wolfSSL_EVP_DigestVerifyUpdate: remove (unsigned int) cast - Add overflow guard before narrowing to word32 for wc_HmacUpdate Refs: ZD-21734
967e13e to
c85b0eb
Compare
Replace section symbol and em-dashes with ASCII equivalents, and reference word32 instead of UINT_MAX for consistency with the code. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Root Cause
Three defects, all in
wolfcrypt/src/evp.candwolfssl/openssl/evp.h:wolfSSL_EVP_DigestSignUpdatewas declared withunsigned int cnt— unlike OpenSSL'ssize_t cnt, breaking source-level API compatibility and FFI bindings that passsize_t.wolfSSL_EVP_DigestVerifyUpdatehad the rightsize_t cntdeclaration but the implementation cast it tounsigned intbefore calling the internal helper, silently truncating any count larger thanUINT_MAXon 64-bit platforms.wolfssl_evp_digest_pk_updateacceptedunsigned int, which forced the truncating cast in powerPC changes #2.Why It Was Missed
DigestSignUpdateandDigestVerifyUpdatewere added at different times. TheVerifyside was updated to match OpenSSL'ssize_tin the public declaration but the internal helper (which served both) was never updated, leaving the cast in place. TheSignside declaration was never updated at all. Because both functions compile without warning (implicit narrowing is legal in C), the type mismatch survived code review and CI undetected.Fix
wolfssl_evp_digest_pk_update:unsigned int→size_t; add overflow guard before narrowing toword32forwc_HmacUpdatewolfSSL_EVP_DigestSignUpdatedeclaration (evp.h) and definition:unsigned int→size_twolfSSL_EVP_DigestVerifyUpdateimplementation: remove the(unsigned int)castTest
New test
test_wolfSSL_EVP_DigestSign_size_t_cntintests/api/test_evp_pkey.c:size_t msgSz(notunsigned int) to bothDigestSignUpdateandDigestVerifyUpdatecnt > UINT_MAXreturnsWOLFSSL_FAILUREinstead of truncatingRefs: ZD-21734