feat(libSceLibreSsl3): implement HMAC_CTX_new and HMAC_CTX_free #15514

Merged
Jawschamp merged 2 commits from upstream-pr/15514 into main 2026-11-09 17:42:20 +00:00
Jawschamp commented 2026-11-03 17:09:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Jawschamp on 2026-11-03T17:09:58Z.


What

Implements HMAC_CTX_new and HMAC_CTX_free (libSceLibreSsl3 NIDs LcxutSyn11o and YAxGqtnKQFY), which threw NotImplemented_nid_no_patch as parameterless placeholders. Their declarations in include/Api.hpp become void* HMAC_CTX_new() and void HMAC_CTX_free(void* context), and the placeholders leave AdditionalExports.cpp; docs/dev/debt/libSceLibreSsl3.md goes from 175 to 173 additional exports (165 to 163 named) and loses their two table rows.

  • HMAC_CTX_new returns a zeroed block of sizeof(HmacContext) (288 bytes) from the guest heap and initialises it with HMAC_CTX_init, or returns null if the allocation fails. HmacContext is the layout that main's libSceLibreSsl HMAC_CTX_init, HMAC_CTX_cleanup, HMAC_Init_ex, HMAC_Update and HMAC_Final (forwarded by libSceLibreSsl3) operate on.
  • HMAC_CTX_free(NULL) returns. Any other context goes through HMAC_CTX_cleanup, which releases the digest contexts and clears the block, and the block is then released with the guest free.
  • The console's own HMAC_CTX size and its HMAC_CTX_new allocation are not measured; the debt file entry says so. The context is only valid as an opaque pointer passed to the HMAC exports.
  • Not changed: PKCS5_PBKDF2_HMAC, EVP_MD_block_size and EVP_sha512_256 stay throwing placeholders, to keep one topic per PR.

New guest test guest_libressl3_hmac_context (registered in the library's CMakeLists.txt) checks that HMAC_CTX_new calls the guest calloc once with sizeof(HmacContext) and returns a distinct non-null block, that a failed allocation returns null, that HMAC_CTX_free(NULL) releases nothing, that HMAC_CTX_new, HMAC_Init_ex (HMAC-SHA256, 20-byte key 0x0b), chunked HMAC_Update, HMAC_Final and HMAC_CTX_free reproduce the RFC 4231 test case 1 digest, again after re-initialising with a null key and digest, and that freeing a keyed, partly updated context releases every guest-heap block.

Tested

Linux x86_64, GCC 14.2 (g++ extracted from Debian trixie packages), -DBUILD_TESTING=ON, full configure with all submodules. Hardware and titles: not tested.

  • Built libSceLibreSsl3 and the LibreSSL and LibreSSL3 test executables. ctest -R "libressl|crypto_memcmp" passes all 53 tests, guest_libressl3_hmac_context in under 0.01 s.
  • core/libs/tests/test_public_headers.py --audit-only passes (one declaration per export). tools/check_conventions.py --base origin/main and tools/check_test_registration.py pass.
  • tools/pr_overlap.py --branch fix/libressl3-hmac-ctx-v2 finds no open PR with the same exports or new files. It reports textual overlap in the count line of docs/dev/debt/libSceLibreSsl3.md with #14465, #14889, #14890, #14992, #15031, #15045, #15119, #15289, #15303, #15406, #15449 and #15472 (also CMakeLists.txt line 7 for #14890, and AdditionalExports.cpp and CMakeLists.txt hunks for #15472), and could not compare #10461, #10631, #11146, #12754, #12928, #13486, #14212, #14483, #14499 and #14612 because they conflict with main; their diffs do not add HMAC_CTX_new or HMAC_CTX_free.
  • Not run: the rest of the suite, Windows and the PS5 behaviour of these exports.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5141418826 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15514). Originally posted by [Jawschamp](https://github.com/Jawschamp) on 2026-11-03T17:09:58Z. --- ### What Implements `HMAC_CTX_new` and `HMAC_CTX_free` (libSceLibreSsl3 NIDs `LcxutSyn11o` and `YAxGqtnKQFY`), which threw `NotImplemented_nid_no_patch` as parameterless placeholders. Their declarations in `include/Api.hpp` become `void* HMAC_CTX_new()` and `void HMAC_CTX_free(void* context)`, and the placeholders leave `AdditionalExports.cpp`; `docs/dev/debt/libSceLibreSsl3.md` goes from 175 to 173 additional exports (165 to 163 named) and loses their two table rows. - `HMAC_CTX_new` returns a zeroed block of `sizeof(HmacContext)` (288 bytes) from the guest heap and initialises it with `HMAC_CTX_init`, or returns null if the allocation fails. `HmacContext` is the layout that main's libSceLibreSsl `HMAC_CTX_init`, `HMAC_CTX_cleanup`, `HMAC_Init_ex`, `HMAC_Update` and `HMAC_Final` (forwarded by libSceLibreSsl3) operate on. - `HMAC_CTX_free(NULL)` returns. Any other context goes through `HMAC_CTX_cleanup`, which releases the digest contexts and clears the block, and the block is then released with the guest `free`. - The console's own `HMAC_CTX` size and its `HMAC_CTX_new` allocation are not measured; the debt file entry says so. The context is only valid as an opaque pointer passed to the HMAC exports. - Not changed: `PKCS5_PBKDF2_HMAC`, `EVP_MD_block_size` and `EVP_sha512_256` stay throwing placeholders, to keep one topic per PR. New guest test `guest_libressl3_hmac_context` (registered in the library's `CMakeLists.txt`) checks that `HMAC_CTX_new` calls the guest `calloc` once with `sizeof(HmacContext)` and returns a distinct non-null block, that a failed allocation returns null, that `HMAC_CTX_free(NULL)` releases nothing, that `HMAC_CTX_new`, `HMAC_Init_ex` (HMAC-SHA256, 20-byte key `0x0b`), chunked `HMAC_Update`, `HMAC_Final` and `HMAC_CTX_free` reproduce the RFC 4231 test case 1 digest, again after re-initialising with a null key and digest, and that freeing a keyed, partly updated context releases every guest-heap block. ### 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, GCC 14.2 (g++ extracted from Debian trixie packages), `-DBUILD_TESTING=ON`, full configure with all submodules. Hardware and titles: not tested. - Built `libSceLibreSsl3` and the LibreSSL and LibreSSL3 test executables. `ctest -R "libressl|crypto_memcmp"` passes all 53 tests, `guest_libressl3_hmac_context` in under 0.01 s. - `core/libs/tests/test_public_headers.py --audit-only` passes (one declaration per export). `tools/check_conventions.py --base origin/main` and `tools/check_test_registration.py` pass. - `tools/pr_overlap.py --branch fix/libressl3-hmac-ctx-v2` finds no open PR with the same exports or new files. It reports textual overlap in the count line of `docs/dev/debt/libSceLibreSsl3.md` with #14465, #14889, #14890, #14992, #15031, #15045, #15119, #15289, #15303, #15406, #15449 and #15472 (also `CMakeLists.txt` line 7 for #14890, and `AdditionalExports.cpp` and `CMakeLists.txt` hunks for #15472), and could not compare #10461, #10631, #11146, #12754, #12928, #13486, #14212, #14483, #14499 and #14612 because they conflict with `main`; their diffs do not add `HMAC_CTX_new` or `HMAC_CTX_free`. - Not run: the rest of the suite, Windows and the PS5 behaviour of these exports. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!15514
No description provided.