perf: cache is_private_key flag to avoid per-call BIGNUM alloc on 3.x#161
Merged
atoomic merged 1 commit intocpan-authors:mainfrom Apr 5, 2026
Merged
Conversation
…lloc On OpenSSL 3.x, _is_private() called EVP_PKEY_get_bn_param() which heap-allocates a full BIGNUM just to test non-nullness, then frees it. This happened on every sign/decrypt/private_encrypt/check_key call. Add is_private_key field to rsaData, detected once in make_rsa_obj() via a new _detect_private_key() helper. _is_private() now returns the cached flag directly — zero heap allocations on the hot path. Fixes cpan-authors#152 Co-Authored-By: Claude Sonnet 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.
Summary
On OpenSSL 3.x,
_is_private()calledEVP_PKEY_get_bn_param()on every invocation, which heap-allocates a full BIGNUM just to test non-nullness and immediately frees it. This hit everysign(),decrypt(),private_encrypt(), andcheck_key()call.Fixes #152
Changes
int is_private_keyfield torsaDatastruct_detect_private_key()helper called once frommake_rsa_obj()_is_private()now returns the cached flag — zero heap allocations on the hot pathTest plan
make test)is_private()is exercised int/rsa.t,t/check_param.t,t/key_lifecycle.t— all greenGenerated by Kōan /fix
Quality Report
Changes: 1 file changed, 16 insertions(+), 10 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline