Skip to content

fix: wc_SignatureVerify/Generate allow empty messages#10253

Open
MarkAtwood wants to merge 1 commit intowolfSSL:masterfrom
MarkAtwood:fix/signature-verify-empty-message
Open

fix: wc_SignatureVerify/Generate allow empty messages#10253
MarkAtwood wants to merge 1 commit intowolfSSL:masterfrom
MarkAtwood:fix/signature-verify-empty-message

Conversation

@MarkAtwood
Copy link
Copy Markdown

Summary

wc_SignatureVerify and wc_SignatureGenerate_ex rejected data_len==0 with BAD_FUNC_ARG. Signing and verifying an empty message is valid — the hash of an empty string is well-defined for all supported hash algorithms, and PKCS#1 v1.5 / PSS impose no minimum message length.

wc_Hash already handles NULL data with data_len==0 correctly (producing e.g. SHA-256 of ""), so the only change needed is relaxing the argument check in the two wrapper functions.

Triggered by Wycheproof RSA PKCS#1 v1.5 test vectors where tcId=1 in every file is a signature over an empty message.

Test plan

  • Wycheproof RSA PKCS#1 v1.5 tcId=1 (empty message) vectors pass
  • Existing signature verify/generate tests unaffected

/cc @wolfSSL-Fenrir-bot please review

wc_SignatureVerify and wc_SignatureGenerate_ex rejected data_len==0
(and data==NULL) with BAD_FUNC_ARG. Signing and verifying an empty
message is valid — the hash of an empty string is well-defined for
all hash algorithms, and PKCS#1 v1.5 / PSS impose no minimum message
length.

wc_Hash already handles NULL data with data_len==0 correctly
(producing e.g. SHA-256 of ""), so the only change needed is relaxing
the argument check in the two wrapper functions.

Triggered by Wycheproof RSA PKCS#1 v1.5 test vectors where tcId=1
in every file is a signature over an empty message.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 17, 2026 21:43
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

Note

Copilot was unable to run its full agentic suite in this review.

Relaxes argument validation in wc_SignatureVerify and wc_SignatureGenerate_ex so signing/verifying an empty message (data_len == 0) is allowed (including data == NULL), aligning behavior with wc_Hash and enabling Wycheproof empty-message vectors.

Changes:

  • Update wc_SignatureVerify argument checks to allow data_len == 0 with data == NULL.
  • Update wc_SignatureGenerate_ex argument checks to allow data_len == 0 with data == NULL.
  • Add clarifying comments about empty-message validity.

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

Comment thread wolfcrypt/src/signature.c
/* Check arguments */
if (data == NULL || data_len == 0 ||
/* Check arguments.
* data may be NULL when data_len is 0 (empty message is valid —
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

These new comments introduce a non-ASCII em dash character (—). This can cause portability/encoding issues for toolchains that assume ASCII-only C sources or have strict source-charset settings. Consider replacing it with an ASCII sequence like '-' or '--' to avoid build problems in constrained environments.

Suggested change
* data may be NULL when data_len is 0 (empty message is valid
* data may be NULL when data_len is 0 (empty message is valid -

Copilot uses AI. Check for mistakes.
Comment thread wolfcrypt/src/signature.c
/* Check arguments.
* data may be NULL when data_len is 0 (empty message is valid —
* the hash of an empty string is well-defined). */
if ((data == NULL && data_len > 0) ||
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

This change introduces new behavior (allowing empty-message verify). To prevent regressions, add an automated regression test that verifies a known-good signature over an empty message (including the data == NULL, data_len == 0 case), matching the reported Wycheproof vectors.

Copilot uses AI. Check for mistakes.
Comment thread wolfcrypt/src/signature.c
if (data == NULL || data_len == 0 ||
/* Check arguments.
* data may be NULL when data_len is 0 (signing an empty message). */
if ((data == NULL && data_len > 0) ||
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

This change introduces new behavior (allowing empty-message signing). Add an automated regression test that signs an empty message (including data == NULL, data_len == 0) and then verifies it, ensuring the previous BAD_FUNC_ARG behavior does not return.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown

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