Skip to content

Use EVP_PKEY_check() for check_key() on OpenSSL 3.x#201

Draft
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-check-key-validation
Draft

Use EVP_PKEY_check() for check_key() on OpenSSL 3.x#201
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-check-key-validation

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

@toddr-bot toddr-bot commented May 27, 2026

What

Replace EVP_PKEY_private_check() with EVP_PKEY_check() in check_key() on OpenSSL 3.x, and clear the error queue after a failed check.

Why

EVP_PKEY_private_check() only validates CRT parameters and de ≡ 1 mod λ(n). The pre-3.x RSA_check_key() it replaced also verifies primality of p/q, n == pq, and other structural checks. OpenSSL's migration guide explicitly recommends EVP_PKEY_check() as the replacement for RSA_check_key(). Using the weaker function is a silent validation regression — keys with corrupt public components would pass check_key() on 3.x but fail on pre-3.x.

How

  • EVP_PKEY_private_check(pctx)EVP_PKEY_check(pctx) (one-line change in RSA.xs)
  • Added ERR_clear_error() after a failed check on both code paths to prevent stale errors from corrupting subsequent croakSsl() messages
  • Updated test comment referencing the old function name

Testing

Full test suite passes (667 tests). The existing t/check_param.t exercises check_key() on valid and invalid keys.

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 3 insertions(+), 2 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

EVP_PKEY_private_check() only validates CRT parameters and
d*e congruence.  RSA_check_key() (used on pre-3.x) additionally
checks primality of p/q and n==p*q.  OpenSSL's migration guide
explicitly recommends EVP_PKEY_check() as the replacement.

Also clear the error queue after a failed check to prevent stale
errors from corrupting subsequent croakSsl() messages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant