Commit c56ad2a
perf: cache is_private_key flag in rsaData to avoid per-call BIGNUM alloc
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 #152
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 199d8f4 commit c56ad2a
1 file changed
Lines changed: 16 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
103 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
104 | 109 | | |
105 | | - | |
106 | | - | |
107 | | - | |
| 110 | + | |
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
111 | | - | |
112 | | - | |
113 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
114 | 120 | | |
115 | 121 | | |
116 | | - | |
117 | | - | |
| 122 | + | |
| 123 | + | |
118 | 124 | | |
119 | 125 | | |
120 | | - | |
121 | 126 | | |
122 | 127 | | |
123 | 128 | | |
| |||
132 | 137 | | |
133 | 138 | | |
134 | 139 | | |
| 140 | + | |
135 | 141 | | |
136 | 142 | | |
137 | 143 | | |
| |||
0 commit comments