Skip to content

Add configurable OAEP hash algorithm#200

Draft
toddr-bot wants to merge 2 commits into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/oaep-hash-config
Draft

Add configurable OAEP hash algorithm#200
toddr-bot wants to merge 2 commits into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/oaep-hash-config

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

@toddr-bot toddr-bot commented May 26, 2026

What

Add use_sha{1,224,256,384,512}_oaep_hash() methods to configure the hash
algorithm 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

  • New oaepHashMode field in rsaData (default: NID_sha1 for backward compat)
  • On OpenSSL 3.x, rsa_crypt() configures EVP_PKEY_CTX_set_rsa_oaep_md and
    EVP_PKEY_CTX_set_rsa_mgf1_md with the selected hash
  • On pre-3.x, non-SHA1 OAEP croaks with a clear message (RSA_public_encrypt
    hardcodes SHA-1, no workaround)
  • check_max_message_length() computes OAEP overhead from the configured hash
    digest size instead of the hardcoded 42 bytes

Testing

  • 16 new tests in t/oaep_hash.t: SHA-1/256/512 round-trips, max-length
    boundary checks, hash mismatch detection, pre-3.x guard
  • Full test suite passes (all existing tests unaffected)

🤖 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

toddr-bot and others added 2 commits May 26, 2026 02:47
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants