Skip to content

Validate key size in generate_key() before OpenSSL calls#178

Merged
toddr merged 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/validate-keygen-size
Apr 23, 2026
Merged

Validate key size in generate_key() before OpenSSL calls#178
toddr merged 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/validate-keygen-size

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

@toddr-bot toddr-bot commented Apr 23, 2026

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 of generate_key() in RSA.xs, before the BIGNUM allocation. Uses SvIV() to handle the signed Perl integer correctly — negative values are caught naturally by the < 512 comparison.

Testing

  • 5 new tests in t/keygen.t: negative (-1), zero, sub-minimum (256, 511), and boundary (512) key sizes
  • Full test suite passes (318+ tests across all test files)

🤖 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

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>
Copy link
Copy Markdown
Member

@timlegge timlegge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@timlegge timlegge marked this pull request as ready for review April 23, 2026 14:05
@toddr toddr merged commit 4f8fe34 into cpan-authors:main Apr 23, 2026
28 checks passed
@toddr-bot toddr-bot deleted the koan.toddr.bot/validate-keygen-size branch April 23, 2026 15:24
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.

3 participants