Skip to content

feat(libSceLibreSsl3): implement HMAC_CTX_new and HMAC_CTX_free - #3

Open
Jawschamp wants to merge 1 commit into
preview-base/libressl3-hmac-ctxfrom
feat/libressl3-hmac-ctx
Open

Jawschamp wants to merge 1 commit into
preview-base/libressl3-hmac-ctxfrom
feat/libressl3-hmac-ctx

Conversation

@Jawschamp

Copy link
Copy Markdown
Owner

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 176 to 174 additional exports (50 to 48 named) and loses their two table rows.

  • HMAC_CTX_new returns a zeroed 304-byte block from the guest heap, the sizeof(HMAC_CTX) of LibreSSL 3.8.4 (HMAC_MAX_MD_CBLOCK 144, 48-byte EVP_MD_CTX members), or null if the allocation fails, as calloc followed by HMAC_CTX_init does in hmac.c.
  • HMAC_CTX_free(NULL) returns. A context in the state HMAC_CTX_new left it (its first 152 bytes zero, which covers the pointer and the three contexts of the 3.8.4 layout and of 40-byte ones) is released. Any other context throws NotImplemented_nid_no_patch, since releasing it is HMAC_CTX_cleanup, which needs EVP_MD_CTX_cleanup and the digest callbacks that main does not have.
  • Not implemented, because main has no digest infrastructure and doing them here would duplicate feat(libSceLibreSsl): implement the EVP message digest and HMAC functions boykopovar/AnyPS5#9448 and feat(libSceLibreSsl3): implement EVP digest contexts and SHA methods boykopovar/AnyPS5#10960: PKCS5_PBKDF2_HMAC (needs HMAC_Init_ex, HMAC_Update, HMAC_Final and a digest object), EVP_MD_block_size (the EVP_MD layout differs between LibreSSL 2.5.4, which the legacy provider uses, and 3.8.4: block_size is at offset 100 in one and 64 in the other, and nothing on main creates an EVP_MD) and EVP_sha512_256. They stay throwing placeholders.

The behaviour is not measured on a PS5; the debt file entry states this and the layout caveat.

New guest test guest_libressl3_hmac_context (registered in the library's CMakeLists.txt) checks the calloc(1, 304) allocation and its zeroed contents, release through the guest free, the null free, a failed allocation, and that a context with any of its first 152 bytes set throws without being freed while a context with only its key area set is released.

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.

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

Allocate the zeroed HMAC_CTX block from the guest heap and release a
context that no HMAC call has used, as LibreSSL 3.8.4 does. A used context
throws, as releasing it needs the digest cleanup that main lacks. A guest
test covers the allocation, the null free and the allocation failure.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Progress report (6d0fc32 → 8d3666a)

📈 System libraries: 26.33% (+0.0029%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceLibreSsl3 HMAC_CTX_new_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl3 15/270 (5.56%) 16/270 (5.93%) +0.37%

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.

1 participant