feat(libSceLibreSsl3): implement PKCS5_PBKDF2_HMAC #15622

Merged
alvaroelpob merged 6 commits from upstream-pr/15622 into main 2026-11-10 09:07:46 +00:00
alvaroelpob commented 2026-11-03 22:11:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-11-03T22:11:39Z.


What

Implements PKCS5_PBKDF2_HMAC in libSceLibreSsl3: RFC 8018 PBKDF2 over libSceLibreSsl's HMAC, with the argument handling of LibreSSL 4.0.0 evp_pbe.c: a null digest queues EVP_R_MESSAGE_DIGEST_IS_NULL and returns 0, a password length of -1 means strlen, a null password or a negative length makes the HMAC key setup fail, so it returns 0, and a key length of 0 then returns 1. Inputs LibreSSL would overrun throw, checked in the same order.

Tested

Linux x86-64 (WSL2), Release: the full build passes and ctest --test-dir build -j16 passes 3829 of 3829 tests, including the new guest_libressl3_pbkdf2, at head 7c4c98f872. The test reads the null-digest error back with ERR_get_error and fails against the previous head. python3 tools/check_conventions.py --base upstream/main passes. Not run on a console or in a title.

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
  • 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: #12945, #14366, #14889, #14890, #14992, #15031, #15045, #15119, #15289, #15303, #15472, #15514, #15544, #15591, #15599, #15616, #15618, #15620
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5145290420 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15622). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-11-03T22:11:39Z. --- ### What Implements `PKCS5_PBKDF2_HMAC` in libSceLibreSsl3: RFC 8018 PBKDF2 over libSceLibreSsl's HMAC, with the argument handling of LibreSSL 4.0.0 [`evp_pbe.c`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/evp/evp_pbe.c#L329-L401): a null digest queues `EVP_R_MESSAGE_DIGEST_IS_NULL` and returns 0, a password length of -1 means `strlen`, a null password or a negative length makes the HMAC key setup fail, so it returns 0, and a key length of 0 then returns 1. Inputs LibreSSL would overrun throw, checked in the same order. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux x86-64 (WSL2), Release: the full build passes and `ctest --test-dir build -j16` passes 3829 of 3829 tests, including the new `guest_libressl3_pbkdf2`, at head 7c4c98f872. The test reads the null-digest error back with `ERR_get_error` and fails against the previous head. `python3 tools/check_conventions.py --base upstream/main` passes. Not run on a console or in a title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #12945, #14366, #14889, #14890, #14992, #15031, #15045, #15119, #15289, #15303, #15472, #15514, #15544, #15591, #15599, #15616, #15618, #15620 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
BunnyFl commented 2026-11-04 11:49:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T11:49:06Z.

Review: APPROVED


@alvaroelpob thanks for folding both differences in. At 7c4c98f872 the function follows LibreSSL 4.0.0 at the commit you cite:

  • Null digest: EVP_MD_size reports EVP_R_MESSAGE_DIGEST_IS_NULL and returns -1 for a null digest (evp_digest.c L478-L485), and PKCS5_PBKDF2_HMAC then returns 0 (evp_pbe.c L338-L340). The code you queue matches: reason 159 (EVP_R_MESSAGE_DIGEST_IS_NULL, evp.h line 1251), library 6 (ERR_LIB_EVP, err.h line 153), function 0xfff as the *error macros use.
  • Order: the HMAC key setup comes before anything else is looked at, and a key length of 0 never enters the while (tkeylen) loop (L349-L353). The host-safety throws now come only after both.

What I ran: head 7c4c98f872 merged onto main b11c7bf84f, Windows 11, WinLibs GCC, Release:

  • guest_libressl3_pbkdf2 and public_headers pass (2 of 2);
  • negative control, Pbkdf2.cpp from the previous head c3bcda3c3f with the new test kept: guest_libressl3_pbkdf2 fails;
  • mutation, the LibreSslPutError_nid_no_patch call removed: the test fails;
  • mutation, if (keyLength == 0) return 1; moved after the salt check: the test fails;
  • tools/check_conventions.py --base upstream/main on the head: all checks passed;
  • tools/pr_overlap.py --branch: besides #15624, no open PR adds PKCS5_PBKDF2_HMAC. I searched the open PRs and checked the diffs of #10960, #12315, #15163 and #15544, which share files without a comparison. #15514 leaves it as a placeholder.

Approving.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5767707735 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15622#pullrequestreview-5767707735). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-04T11:49:06Z. **Review:** APPROVED --- @alvaroelpob thanks for folding both differences in. At `7c4c98f872` the function follows LibreSSL 4.0.0 at the commit you cite: - **Null digest:** `EVP_MD_size` reports `EVP_R_MESSAGE_DIGEST_IS_NULL` and returns -1 for a null digest ([`evp_digest.c` L478-L485](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/evp/evp_digest.c#L478-L485)), and `PKCS5_PBKDF2_HMAC` then returns 0 ([`evp_pbe.c` L338-L340](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/evp/evp_pbe.c#L338-L340)). The code you queue matches: reason 159 (`EVP_R_MESSAGE_DIGEST_IS_NULL`, `evp.h` line 1251), library 6 (`ERR_LIB_EVP`, `err.h` line 153), function `0xfff` as the `*error` macros use. - **Order:** the HMAC key setup comes before anything else is looked at, and a key length of 0 never enters the `while (tkeylen)` loop ([L349-L353](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/evp/evp_pbe.c#L349-L353)). The host-safety throws now come only after both. **What I ran:** head `7c4c98f872` merged onto `main` `b11c7bf84f`, Windows 11, WinLibs GCC, Release: - `guest_libressl3_pbkdf2` and `public_headers` pass (2 of 2); - negative control, `Pbkdf2.cpp` from the previous head `c3bcda3c3f` with the new test kept: `guest_libressl3_pbkdf2` fails; - mutation, the `LibreSslPutError_nid_no_patch` call removed: the test fails; - mutation, `if (keyLength == 0) return 1;` moved after the salt check: the test fails; - `tools/check_conventions.py --base upstream/main` on the head: all checks passed; - `tools/pr_overlap.py --branch`: besides #15624, no open PR adds `PKCS5_PBKDF2_HMAC`. I searched the open PRs and checked the diffs of #10960, #12315, #15163 and #15544, which share files without a comparison. #15514 leaves it as a placeholder. Approving.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!15622
No description provided.