Add configurable OAEP hash algorithm#200
Draft
toddr-bot wants to merge 2 commits into
Draft
Conversation
OAEP padding was hardcoded to use SHA-1 for both the label hash and
MGF1 mask generation. Modern compliance standards (NIST SP 800-56B)
and many APIs now require OAEP with SHA-256 or stronger.
Add use_sha{1,224,256,384,512}_oaep_hash() methods that configure the
OAEP hash independently of the signature hash. On OpenSSL 3.x, the
selected hash is passed to EVP_PKEY_CTX via set_rsa_oaep_md and
set_rsa_mgf1_md. On pre-3.x, only SHA-1 is supported (RSA_public_encrypt
hardcodes it); attempting non-SHA1 OAEP croaks with a clear message.
The max plaintext length check now uses the configured OAEP hash
digest size instead of the hardcoded SHA-1 overhead (42 bytes).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The OAEP overhead is 2*hash_length+2, not a fixed 42 bytes. Document the formula and give examples for SHA-1/SHA-256/SHA-512. 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
Add
use_sha{1,224,256,384,512}_oaep_hash()methods to configure the hashalgorithm used for OAEP padding, independent of the signature hash.
Why
OAEP was hardcoded to SHA-1 for both the label hash and MGF1. Modern
compliance standards (NIST SP 800-56B Rev. 2) and APIs increasingly
require OAEP with SHA-256 or stronger. Users had no way to satisfy
these requirements without dropping to raw OpenSSL.
How
oaepHashModefield inrsaData(default:NID_sha1for backward compat)rsa_crypt()configuresEVP_PKEY_CTX_set_rsa_oaep_mdandEVP_PKEY_CTX_set_rsa_mgf1_mdwith the selected hashhardcodes SHA-1, no workaround)
check_max_message_length()computes OAEP overhead from the configured hashdigest size instead of the hardcoded 42 bytes
Testing
t/oaep_hash.t: SHA-1/256/512 round-trips, max-lengthboundary checks, hash mismatch detection, pre-3.x guard
🤖 Generated with Claude Code
Quality Report
Changes: 3 files changed, 203 insertions(+), 2 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline