Use EVP_PKEY_check() for check_key() on OpenSSL 3.x#201
Conversation
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>
|
@toddr-bot review: EVP_PKEY_pairwise_check() validates that the public and private components have the correct mathematical relationship to each other for the key given by ctx. EVP_PKEY_check() is an alias for the EVP_PKEY_pairwise_check() function. EVP_PKEY_private_check() validates the private component of the key given by ctx. EVP_PKEY_check and EVP_PKEY_private_check are not equivalent |
Not equivalent in general, but for RSA specifically
|
PR Review — Use EVP_PKEY_check() for check_key() on OpenSSL 3.xCorrect fix — Strengths:
No issues found. The reviewer comment from @timlegge is addressed in the reply below — the claim that Checklist
Automated review by Kōan (Claude · model claude-opus-4-6) |
What
Replace
EVP_PKEY_private_check()withEVP_PKEY_check()incheck_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.xRSA_check_key()it replaced also verifies primality of p/q, n == pq, and other structural checks. OpenSSL's migration guide explicitly recommendsEVP_PKEY_check()as the replacement forRSA_check_key(). Using the weaker function is a silent validation regression — keys with corrupt public components would passcheck_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)ERR_clear_error()after a failed check on both code paths to prevent stale errors from corrupting subsequentcroakSsl()messagesTesting
Full test suite passes (667 tests). The existing
t/check_param.texercisescheck_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