Skip to content

Validate EC_PUB_X/EC_PUB_Y on import by routine them through the X9.63 point import - #467

Open
gasbytes wants to merge 1 commit into
wolfSSL:masterfrom
gasbytes:wp_ecc_set_params_pub-fix
Open

Validate EC_PUB_X/EC_PUB_Y on import by routine them through the X9.63 point import#467
gasbytes wants to merge 1 commit into
wolfSSL:masterfrom
gasbytes:wp_ecc_set_params_pub-fix

Conversation

@gasbytes

@gasbytesgasbytes commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Route EC_PUB_x/EC_PUB_Y through wc_ecc_import_x963_ex, the same validated import the encoded public key path uses, so the point is checked to be onn the curve,
both ordinates are required together, and the projective z ordinate is set.

Also, added some 3 regression tests for the off-curve and X-without-Y cases to test the edge cases of this behaviour.

Fixes F-4694.

@gasbytesgasbytes self-assigned this Aug 13, 2026
CopilotAI lite review requested due to automatic review settings August 13, 2026 12:41
@gasbytes
gasbytes marked this pull request as ready for review August 13, 2026 12:44

CopilotAI left a comment

Copy link
Copy Markdown

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 ECC public key imports by validating raw EC_PUB_X/EC_PUB_Y coordinates via the same X9.63 point import path already used for encoded public keys, ensuring points are on-curve and that X/Y are provided together. It also adds regression tests to cover off-curve and incomplete-coordinate edge cases.

Changes:

  • Route EC_PUB_X/EC_PUB_Y imports through wc_ecc_import_x963_ex() by constructing an uncompressed X9.63 point, enforcing on-curve validation and proper point initialization.
  • Reject public key imports that provide only one ordinate (X without Y, or vice versa).
  • Add regression tests for off-curve XY import rejection, X-only rejection, and an ECDH derive check with an off-curve peer key.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

FileDescription
test/test_ecc.cAdds regression tests for off-curve and incomplete-coordinate public key imports, plus an ECDH-path guard test.
src/wp_ecc_kmgmt.cValidates EC_PUB_X/EC_PUB_Y imports by converting to an X9.63 point and importing via wc_ecc_import_x963_ex().

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment threadtest/test_ecc.c
@gasbytes
gasbytesforce-pushed the wp_ecc_set_params_pub-fix branch from 41a341d to 6c5beb7CompareAugust 13, 2026 13:23
@gasbytesgasbytes assigned padelsbach and unassigned gasbytesAug 13, 2026
Comment threadsrc/wp_ecc_kmgmt.c
ok = 0;
}
if (ok) {
/* wc_ecc_import_x963_ex only checks the point against the curve

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.

According to the logic in this comment, we should also apply the check below in wp_ecc_set_params_enc_pub_key. Maybe add a helper and call from both?

iiuc, WOLFSSL_VALIDATE_ECC_IMPORT is fairly new (or at least the checking is), so we want to keep this check for older wolfSSL versions.

Comment threadsrc/wp_ecc_kmgmt.c
int rc;
int origType;

rc = wc_ecc_import_x963_ex(point, 1 + (2 * (word32)size), &ecc->key,

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.

AI tells me this call can overwrite/zero existing fields within the ecc key, which is fine for import, but potentially dangerous when called from wp_ecc_set_params. Can you investigate?

Comment threadsrc/wp_ecc_kmgmt.c
/* wc_ecc_import_x963_ex only checks the point against the curve
* when wolfSSL is built with WOLFSSL_VALIDATE_ECC_IMPORT, so check
* it here instead of relying on the build options. */
origType = ecc->key.type;

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.

AI says ecc->key.type is always ECC_PUBLICKEY so the save+restore is not needed. But zooming out, do we need to check the key we just imported?

Comment threadsrc/wp_ecc_kmgmt.c
static const OSSL_PARAM wp_ecc_supported_settable_params[] = {
OSSL_PARAM_int(OSSL_PKEY_PARAM_USE_COFACTOR_ECDH, NULL),
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, NULL, 0),
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_EC_PUB_X, NULL, 0),

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.

Not directly related, but stumbled upon this block where X and Y are octet_strings. I think they should be OSSL_PARAM_BN

Sign up for freeto 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.

3 participants

@gasbytes@padelsbach