Validate key size in generate_key() before OpenSSL calls#178
Merged
toddr merged 1 commit intocpan-authors:mainfrom Apr 23, 2026
Merged
Conversation
Reject negative, zero, and sub-512-bit key sizes with a clear croak message instead of letting OpenSSL produce cryptic errors or hang. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds input validation for the key size parameter in
generate_key(), rejecting values below 512 bits before any OpenSSL calls.Why
Passing negative, zero, or very small key sizes to
generate_key()produces cryptic OpenSSL errors or can cause hangs, depending on the OpenSSL version. A pre-check with a clear error message is the standard defensive pattern (same approach already used for the exponent parameter).How
Single
croak()guard at the top ofgenerate_key()in RSA.xs, before the BIGNUM allocation. UsesSvIV()to handle the signed Perl integer correctly — negative values are caught naturally by the< 512comparison.Testing
t/keygen.t: negative (-1), zero, sub-minimum (256, 511), and boundary (512) key sizes🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 21 insertions(+), 1 deletion(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline