Skip to content

Validate DSA parameters when verifying DSA key.#10381

Open
kareem-wolfssl wants to merge 1 commit intowolfSSL:masterfrom
kareem-wolfssl:zd21694
Open

Validate DSA parameters when verifying DSA key.#10381
kareem-wolfssl wants to merge 1 commit intowolfSSL:masterfrom
kareem-wolfssl:zd21694

Conversation

@kareem-wolfssl
Copy link
Copy Markdown
Contributor

Description

Fixes zd#21694

Testing

PoC, newly added test

Checklist

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

Thanks to Kr0emer for the report.
@kareem-wolfssl kareem-wolfssl self-assigned this May 1, 2026
Copilot AI review requested due to automatic review settings May 1, 2026 23:06
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

Adds DSA public key/domain parameter validation to prevent signature verification with malformed parameters (e.g., g = 1, y = 1) and exposes the validation as a public API, with a new regression test.

Changes:

  • Add new public API wc_DsaCheckPubKey() for validating DSA domain parameters + public key.
  • Call wc_DsaCheckPubKey() from wc_DsaVerify_ex() prior to signature math.
  • Add an API test that constructs malformed keys (requires WOLFSSL_PUBLIC_MP) and asserts verify/validation rejection.

Reviewed changes

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

File Description
wolfssl/wolfcrypt/dsa.h Exposes wc_DsaCheckPubKey() as a public API.
wolfcrypt/src/dsa.c Implements key/parameter checks and enforces them in DSA verify.
tests/api/test_dsa.h Registers the new API test.
tests/api/test_dsa.c Adds regression coverage for malformed DSA params/pubkeys and verify rejection.

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

Comment thread wolfcrypt/src/dsa.c
Comment on lines +104 to +105
* - g^q mod p == 1 (g generates the order-q subgroup)
* - y^q mod p == 1 (y is in the order-q subgroup)
Comment thread wolfcrypt/src/dsa.c
Comment on lines +1169 to +1173
/* Validate domain parameters and public key before doing any
* signature math. */
ret = wc_DsaCheckPubKey(key);
if (ret != 0) {
break;
Comment thread wolfssl/wolfcrypt/dsa.h
@@ -95,6 +95,7 @@ WOLFSSL_API int wc_DsaKeyToDer(DsaKey* key, byte* output, word32 inLen);
WOLFSSL_API int wc_SetDsaPublicKey(byte* output, DsaKey* key,
int outLen, int with_header);
WOLFSSL_API int wc_DsaKeyToPublicDer(DsaKey* key, byte* output, word32 inLen);
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 2, 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