Skip to content

fix(libSceLibreSsl3): accept the RSA digests of LibreSSL 4.0.0 check_padding_md - #25079

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
ToRaNek:fix/libressl3-rsa-padding-digests
Nov 21, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
ToRaNek:fix/libressl3-rsa-padding-digests

Conversation

@ToRaNek

@ToRaNek ToRaNek commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

What

EVP_PKEY_CTX_ctrl refused EVP_sha512_256() for an RSA key: EVP_PKEY_CTRL_MD returned 0 with RSA_R_INVALID_DIGEST. EVP_DigestSignInit, EVP_SignFinal and EVP_VerifyFinal go through the same check, so no RSA signature with SHA-512/256 could be made or verified, although this library exports that digest.

The cause: CheckPaddingDigest in PkeyContext.cpp carried the digest list of the bundled 3.4.1 submodule. LibreSSL 4.0.0, the reference of this library, has six more entries in check_padding_md:

		case NID_sha512_224:
		case NID_sha512_256:
		case NID_sha3_224:
		case NID_sha3_256:
		case NID_sha3_384:
		case NID_sha3_512:

Two changes:

  • CheckPaddingDigest accepts the 15 digest types of 4.0.0 (NIDs 1029 to 1034 added, values from obj_mac.num).
  • DigestIdentifier in RsaCrypto.cpp, the table PKCS#1 v1.5 signing takes the DigestInfo OID from, gets SHA-512/256: 2.16.840.1.101.3.4.2.6 (nist_hashalgs 6 in objects.txt).

What a title can reach today: only SHA-512/256. No export of this library returns a SHA-512/224 or SHA-3 digest method. Those five types are in the list because it is the list of the source; with PKCS#1 v1.5 padding they pass the control and then throw NotImplemented when signing, as any digest without an OID in the table does. The debt fragment says so.

EVP_PKEY_CTRL_RSA_MGF1_MD does not go through this list in the source and is not changed.

Tested

Windows 11, MinGW GCC 15.2. Not tested on a console.

Vectors. The RSA key is the one the test file already has. The message digest and two signatures were made with OpenSSL 3.2.4:

openssl dgst -sha512-256 -binary message.bin > sha512_256.dgst
openssl dgst -sha512-256 -sign key.pem -out sha512_256.sig message.bin
openssl pkeyutl -sign -inkey key.pem -pkeyopt digest:sha512-256 -pkeyopt rsa_padding_mode:pss -pkeyopt rsa_pss_saltlen:20 -in sha512_256.dgst -out sha512_256_pss20.sig

The test (guest_libressl3_pkey_context), two new functions:

  • the list: each of the 15 types is accepted by EVP_PKEY_CTRL_MD under PKCS#1 padding, by the switch to PSS, and by EVP_PKEY_CTRL_MD under PSS, with an empty queue; types 0, 3, 999, 1026, 1028 and 1035 are refused with RSA_R_INVALID_DIGEST under both paddings and leave the current digest unchanged; a hand-made method of type 1029 passes the control and then throws when it signs;
  • SHA-512/256 with PKCS#1 v1.5: the signature equals the OpenSSL one byte for byte; it verifies; a corrupted signature, another digest value and a 31-byte digest are refused; the SHA-256 signature is refused under SHA-512/256 and the other way round;
  • SHA-512/256 with PSS: sign then verify, the OpenSSL signature (salt 20) verifies, a corrupted one and a forced salt length of 32 are refused;
  • end to end: EVP_DigestSignInit / EVP_DigestSignFinal and EVP_SignFinal / EVP_VerifyFinal on the message, compared with the OpenSSL signature.

With the two source files from main the test fails at the first new check (type 1029 refused); with the change it passes.

Negative controls. 13 mutations, each rebuilt and run on its own, all make the test fail: each of the six new case lines removed, three NID constants changed, the OID entry removed, its last byte changed, the SHA-512 OID used instead, and the OID also given to type 1029.

python tools/check_conventions.py --base origin/main and python tools/debt_fold.py --check pass.

Overlap (python tools/pr_overlap.py --branch fix/libressl3-rsa-padding-digests):

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

…padding_md

CheckPaddingDigest carried the digest list of the bundled 3.4.1
submodule. LibreSSL 4.0.0 also accepts SHA-512/224, SHA-512/256 and the
four SHA-3 digests, so EVP_PKEY_CTX_ctrl refused EVP_sha512_256, which
this library exports, with RSA_R_INVALID_DIGEST.

The list now matches 4.0.0, and PKCS#1 v1.5 signatures get the
DigestInfo OID of SHA-512/256.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b8bd87c60c:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libressl3_pkey_context_tests built cleanly.
  • CTest (guest_libressl3_pkey_context):
    1/1 Test #4728: guest_libressl3_pkey_context .....   Passed    6.43 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibreSsl3/src/PkeyContext.cpp, core/libs/prx/libSceLibreSsl3/src/RsaCrypto.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4728: guest_libressl3_pkey_context .....Subprocess aborted***Exception:   3.47 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified NID mapping and constants for SHA-512/224, SHA-512/256, SHA3-224, SHA3-256, SHA3-384, SHA3-512 against LibreSSL 4.0.0 obj_mac.num and check_padding_md in PkeyContext.cpp
    • Verified ASN.1 DER DigestInfo OID prefix 2.16.840.1.101.3.4.2.6 ({0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x06}) for NID 1030 in RsaCrypto.cpp DigestIdentifier
    • Verified technical debt fragment docs/dev/debt/changes/fix-libressl3-rsa-padding-digests.md matches repository format and documents the five unsupported OIDs throwing NotImplemented_nid_no_patch
    • Verified comprehensive unit test coverage in core/libs/prx/libSceLibreSsl3/tests/PkeyContext.cpp covering PKCS#1 v1.5 and PSS signing, verification, negative digest rejection, and EVP_MD_CTX workflows

Looks Good To Me

@oneandonlydean
oneandonlydean merged commit a29a67f into boykopovar:main Nov 21, 2026
14 checks passed
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