feat(libSceLibreSsl3): implement HKDF #15472

Closed
puridanish284 wants to merge 1 commit from upstream-pr/15472 into main
puridanish284 commented 2026-11-03 14:10:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by puridanish284 on 2026-11-03T14:10:57Z.


What

Implements HKDF in libSceLibreSsl3 (NID uJ2ZXq4z3As), which was a parameterless throwing placeholder in AdditionalExports.cpp. The signature is LibreSSL's openssl/hkdf.h: int HKDF(uint8_t *out_key, size_t out_len, const EVP_MD *digest, const uint8_t *secret, size_t secret_len, const uint8_t *salt, size_t salt_len, const uint8_t *info, size_t info_len). The behaviour follows LibreSSL 4.0.0, the version libSceLibreSsl3 reports on firmware 13.40: hkdf.c and the HMAC of hmac.c. It is computed through libSceLibreSsl's existing HMAC_*:

  • a null salt is an empty HMAC key, and salt_len is converted to int as HMAC takes it;
  • an extract failure (a null digest, a negative int salt length) queues ERR_R_CRYPTO_LIB and returns 0 without writing;
  • more than 255 blocks: the first 255 are written, then EVP_R_TOO_LARGE is queued and 0 is returned;
  • a null output, secret or info with a nonzero length throws, where LibreSSL dereferences it.

docs/dev/debt/libSceLibreSsl3.md gets an HKDF entry for what is unverified. Older LibreSSL 3 releases use OpenBSD 7.0's hkdf.c, which rejects oversize output before writing; the console's allocation failures are not reproduced. The export also leaves the Additional exports table, which goes from 175 to 174 entries.

Tested

Ubuntu 24.04 x86-64, GCC 13.3, Release, BUILD_TESTING=ON, full build.

New guest_libressl3_hkdf test:

  • RFC 5869 A.1–A.3 (SHA-256);
  • SHA-384, SHA-512 and MD5 outputs cross-checked with Python's hmac;
  • null, empty and all-zero salts;
  • a salt longer than the block size, and salt_len above 2^32;
  • an empty secret, and zero-length output into a null buffer;
  • exactly 255 blocks (SHA-256 and MD5);
  • 256 blocks: partial output and EVP_R_TOO_LARGE;
  • a null digest and a negative int salt length: ERR_R_CRYPTO_LIB, output untouched;
  • null pointers with nonzero lengths throw;
  • no guest-heap block is left.

Reverting the null-salt handling, or checking the length before writing, makes the test fail.

The libSceLibreSsl3, guest_crypto_memcmp and public_headers tests pass on main and on this branch.

Full ctest with this branch: 2854 passed, 935 skipped (no Vulkan device) and 11 failed. The failures are guest_net_*, guest_socket_* and guest_tcp: they need IPv6, which the test machine lacks (socket(AF_INET6) gives EAFNOSUPPORT), and they don't link libSceLibreSsl3.

Windows, run by maskym on this head (comment): Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja; d84eb91642 merged alone into main 086c0686c8 builds clean, and guest_libressl3_hkdf passes 3 of 3 runs. Not run on a PS5.

python3 tools/check_conventions.py --base main passes. Not tested on a console or with 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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01QJYUYbAgEHAevbodPCGuDz

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5138677076 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15472). Originally posted by [puridanish284](https://github.com/puridanish284) on 2026-11-03T14:10:57Z. --- ### What Implements `HKDF` in libSceLibreSsl3 (NID `uJ2ZXq4z3As`), which was a parameterless throwing placeholder in `AdditionalExports.cpp`. The signature is LibreSSL's `openssl/hkdf.h`: `int HKDF(uint8_t *out_key, size_t out_len, const EVP_MD *digest, const uint8_t *secret, size_t secret_len, const uint8_t *salt, size_t salt_len, const uint8_t *info, size_t info_len)`. The behaviour follows LibreSSL 4.0.0, the version libSceLibreSsl3 reports on firmware 13.40: [hkdf.c](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/hkdf/hkdf.c) and the `HMAC` of [hmac.c](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/hmac/hmac.c). It is computed through libSceLibreSsl's existing `HMAC_*`: - a null salt is an empty HMAC key, and `salt_len` is converted to `int` as `HMAC` takes it; - an extract failure (a null digest, a negative `int` salt length) queues `ERR_R_CRYPTO_LIB` and returns 0 without writing; - more than 255 blocks: the first 255 are written, then `EVP_R_TOO_LARGE` is queued and 0 is returned; - a null output, secret or info with a nonzero length throws, where LibreSSL dereferences it. `docs/dev/debt/libSceLibreSsl3.md` gets an HKDF entry for what is unverified. Older LibreSSL 3 releases use [OpenBSD 7.0's hkdf.c](https://github.com/libressl/openbsd/blob/078b3d1df8ca2011c1605cd40418c58fa0f5b143/src/lib/libcrypto/hkdf/hkdf.c), which rejects oversize output before writing; the console's allocation failures are not reproduced. The export also leaves the Additional exports table, which goes from 175 to 174 entries. ### 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. --> Ubuntu 24.04 x86-64, GCC 13.3, Release, `BUILD_TESTING=ON`, full build. New `guest_libressl3_hkdf` test: - RFC 5869 A.1–A.3 (SHA-256); - SHA-384, SHA-512 and MD5 outputs cross-checked with Python's `hmac`; - null, empty and all-zero salts; - a salt longer than the block size, and `salt_len` above 2^32; - an empty secret, and zero-length output into a null buffer; - exactly 255 blocks (SHA-256 and MD5); - 256 blocks: partial output and `EVP_R_TOO_LARGE`; - a null digest and a negative `int` salt length: `ERR_R_CRYPTO_LIB`, output untouched; - null pointers with nonzero lengths throw; - no guest-heap block is left. Reverting the null-salt handling, or checking the length before writing, makes the test fail. The libSceLibreSsl3, `guest_crypto_memcmp` and `public_headers` tests pass on `main` and on this branch. Full `ctest` with this branch: 2854 passed, 935 skipped (no Vulkan device) and 11 failed. The failures are `guest_net_*`, `guest_socket_*` and `guest_tcp`: they need IPv6, which the test machine lacks (`socket(AF_INET6)` gives `EAFNOSUPPORT`), and they don't link libSceLibreSsl3. Windows, run by maskym on this head ([comment](https://github.com/boykopovar/AnyPS5/pull/15472#issuecomment-6614761106)): Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (`x86_64-ucrt-posix-seh`, r6), Release, `BUILD_TESTING=ON`, Ninja; `d84eb91642` merged alone into `main` `086c0686c8` builds clean, and `guest_libressl3_hkdf` passes 3 of 3 runs. Not run on a PS5. `python3 tools/check_conventions.py --base main` passes. Not tested on a console or with 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QJYUYbAgEHAevbodPCGuDz
MarcZX10 commented 2026-11-03 14:25:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T14:25:05Z.

Review: COMMENTED


Reviewed — no blocking findings

At head d84eb91642525413dbc17f3520f1fb0de5bea0f7, I found no source-level blocker; I could not independently verify the reported C++ build and tests against this exact SHA.

What I ran

I reviewed all six changed files at head d84eb91642525413dbc17f3520f1fb0de5bea0f7 against base 4f41f4c375f5abb487dbd184fbc150f31994d762. The exact-head preview against that base was clean. Environment: Debian Linux x86_64, Python 3.11.2, Git 2.39.5; GCC 12.2.0 was available but not used.

git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...d84eb91642525413dbc17f3520f1fb0de5bea0f7
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15472
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head d84eb91642525413dbc17f3520f1fb0de5bea0f7 --title 'feat(libSceLibreSsl3): implement HKDF' --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15472-d84eb9164252/pr-body.md
python3 /marc/AnyPS5/tools/pr_abi_audit.py --repo /tmp/anyps5-review-15472 --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head d84eb91642525413dbc17f3520f1fb0de5bea0f7 --json
python3 /marc/AnyPS5/tools/pr_test_quality.py --root /tmp/anyps5-review-15472 --json core/libs/prx/libSceLibreSsl3/tests/Hkdf.cpp
python3 tools/check_test_registration.py --scripts
gh pr checks 15472 --repo boykopovar/AnyPS5

Results

Check Result Note
Diff and conventions passed No whitespace or convention findings.
ABI audit passed 277 symbols examined; no findings.
C++ test registration passed The CMake target and CTest entry are present.
Test-quality heuristic failed It flagged a possible registration issue; inspection confirmed this is a false positive.
Hosted checks passed Conventions, intake and labels passed on this head.
Build and C++ tests not run The author reports a full build and tests; I did not reproduce them.
Precheck table and unedited outputs

Precheck report for the exact head:

Check Status Command / reason
build_and_compile not_applicable The precheck deliberately does not configure, build, or compile AnyPS5.
diff_check passed git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...d84eb91642525413dbc17f3520f1fb0de5bea0f7
conventions_and_pr_template passed Exact-head tools/check_conventions.py command above.
changed_export_abi_audit failed Helper absent from isolated snapshot; rerun directly below.
python_syntax not_applicable No changed Python implementation files.
related_python_unit_tests not_applicable No changed tools module with a sibling test suite.
python_test_registration not_applicable No changed Python test files.
live_dependency_and_mergeability_check passed Exact-head preview clean against the current base.
build_dependent_cpp_tests not_applicable C++ test requires a build; the precheck does not build.
test_quality_heuristics failed Helper absent from isolated snapshot; rerun directly below.
negative_controls not_applicable No changed Python test module supports the precheck's base-source control.

git diff --check produced no output and exited successfully.

check_conventions.py:

All conventions checks passed.

Direct ABI audit:

passed symbols= 277 findings= 0

The test-quality heuristic output was:

{
  "findings": [
    {
      "path": "core/libs/prx/libSceLibreSsl3/tests/Hkdf.cpp",
      "line": 1,
      "kind": "possible-unregistered-cpp-test",
      "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
    }
  ],
  "negative_control_candidates": [],
  "limits": [
    "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.",
    "A test that passes against base is not by itself proof that the PR test is inadequate.",
    "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error."
  ]
}

The CMake file registers guest_libressl3_hkdf_tests with add_test_executable and add_test(NAME guest_libressl3_hkdf ...); the heuristic misses the ${CMAKE_CURRENT_SOURCE_DIR} path prefix.

Python test-registration audit:

254 test script(s), each run by an add_test or a workflow

Hosted checks:

conventions	pass	24s	https://github.com/boykopovar/AnyPS5/actions/runs/41651170843/job/125969403839
intake	pass	24s	https://github.com/boykopovar/AnyPS5/actions/runs/41651170902/job/125969403879
labels	pass	6s	https://github.com/boykopovar/AnyPS5/actions/runs/41651170789/job/125969407733

Negative control

Assertion Change to code under test Did the test fail?
Null-salt handling and the 255-block output limit The author says reverting null-salt handling or rejecting oversized output before writing makes the test fail. Reported by the author; not independently run here.

Findings

Blocking

None found in the source review.

Non-blocking

The PR description reports a full build and 2,854 passing CTest cases, with 935 skipped and 11 failures attributed to unavailable IPv6. The report does not name the tested commit SHA or include raw build/test logs, so I cannot confirm that evidence applies to this exact head. I am withholding approval until the build/test result can be tied to this head; this is an evidence gap, not a source defect found in this review.

Sources

Not verified

I did not compile the new implementation or execute guest_libressl3_hkdf. The full build/CTest report and its IPv6 failure attribution are author-reported; I did not inspect raw logs. No PS5 console or title was tested.

To get this to a good state

Please identify the tested SHA and attach or link the build and CTest output for it. If it is d84eb91642525413dbc17f3520f1fb0de5bea0f7, I will recheck that evidence on this head; if the tested head differs, I will run the same no-build checks against the new head before reassessing.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5753842254 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15472#pullrequestreview-5753842254). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-03T14:25:05Z. **Review:** COMMENTED --- # Reviewed — no blocking findings At head `d84eb91642525413dbc17f3520f1fb0de5bea0f7`, I found no source-level blocker; I could not independently verify the reported C++ build and tests against this exact SHA. ## What I ran I reviewed all six changed files at head `d84eb91642525413dbc17f3520f1fb0de5bea0f7` against base `4f41f4c375f5abb487dbd184fbc150f31994d762`. The exact-head preview against that base was clean. Environment: Debian Linux x86_64, Python 3.11.2, Git 2.39.5; GCC 12.2.0 was available but not used. ```sh git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...d84eb91642525413dbc17f3520f1fb0de5bea0f7 python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15472 python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head d84eb91642525413dbc17f3520f1fb0de5bea0f7 --title 'feat(libSceLibreSsl3): implement HKDF' --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15472-d84eb9164252/pr-body.md python3 /marc/AnyPS5/tools/pr_abi_audit.py --repo /tmp/anyps5-review-15472 --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head d84eb91642525413dbc17f3520f1fb0de5bea0f7 --json python3 /marc/AnyPS5/tools/pr_test_quality.py --root /tmp/anyps5-review-15472 --json core/libs/prx/libSceLibreSsl3/tests/Hkdf.cpp python3 tools/check_test_registration.py --scripts gh pr checks 15472 --repo boykopovar/AnyPS5 ``` ## Results | Check | Result | Note | |---|---|---| | Diff and conventions | passed | No whitespace or convention findings. | | ABI audit | passed | 277 symbols examined; no findings. | | C++ test registration | passed | The CMake target and CTest entry are present. | | Test-quality heuristic | failed | It flagged a possible registration issue; inspection confirmed this is a false positive. | | Hosted checks | passed | Conventions, intake and labels passed on this head. | | Build and C++ tests | not run | The author reports a full build and tests; I did not reproduce them. | <details> <summary>Precheck table and unedited outputs</summary> Precheck report for the exact head: | Check | Status | Command / reason | |---|---|---| | build_and_compile | not_applicable | The precheck deliberately does not configure, build, or compile AnyPS5. | | diff_check | passed | `git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...d84eb91642525413dbc17f3520f1fb0de5bea0f7` | | conventions_and_pr_template | passed | Exact-head `tools/check_conventions.py` command above. | | changed_export_abi_audit | failed | Helper absent from isolated snapshot; rerun directly below. | | python_syntax | not_applicable | No changed Python implementation files. | | related_python_unit_tests | not_applicable | No changed tools module with a sibling test suite. | | python_test_registration | not_applicable | No changed Python test files. | | live_dependency_and_mergeability_check | passed | Exact-head preview clean against the current base. | | build_dependent_cpp_tests | not_applicable | C++ test requires a build; the precheck does not build. | | test_quality_heuristics | failed | Helper absent from isolated snapshot; rerun directly below. | | negative_controls | not_applicable | No changed Python test module supports the precheck's base-source control. | `git diff --check` produced no output and exited successfully. `check_conventions.py`: ```text All conventions checks passed. ``` Direct ABI audit: ```text passed symbols= 277 findings= 0 ``` The test-quality heuristic output was: ```json { "findings": [ { "path": "core/libs/prx/libSceLibreSsl3/tests/Hkdf.cpp", "line": 1, "kind": "possible-unregistered-cpp-test", "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage." } ], "negative_control_candidates": [], "limits": [ "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.", "A test that passes against base is not by itself proof that the PR test is inadequate.", "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error." ] } ``` The CMake file registers `guest_libressl3_hkdf_tests` with `add_test_executable` and `add_test(NAME guest_libressl3_hkdf ...)`; the heuristic misses the `${CMAKE_CURRENT_SOURCE_DIR}` path prefix. Python test-registration audit: ```text 254 test script(s), each run by an add_test or a workflow ``` Hosted checks: ```text conventions pass 24s https://github.com/boykopovar/AnyPS5/actions/runs/41651170843/job/125969403839 intake pass 24s https://github.com/boykopovar/AnyPS5/actions/runs/41651170902/job/125969403879 labels pass 6s https://github.com/boykopovar/AnyPS5/actions/runs/41651170789/job/125969407733 ``` </details> ## Negative control | Assertion | Change to code under test | Did the test fail? | |---|---|---| | Null-salt handling and the 255-block output limit | The author says reverting null-salt handling or rejecting oversized output before writing makes the test fail. | Reported by the author; not independently run here. | ## Findings ### Blocking None found in the source review. ### Non-blocking The PR description reports a full build and 2,854 passing CTest cases, with 935 skipped and 11 failures attributed to unavailable IPv6. The report does not name the tested commit SHA or include raw build/test logs, so I cannot confirm that evidence applies to this exact head. I am withholding approval until the build/test result can be tied to this head; this is an evidence gap, not a source defect found in this review. ## Sources - [HKDF implementation at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/d84eb91642525413dbc17f3520f1fb0de5bea0f7/core/libs/prx/libSceLibreSsl3/src/Hkdf.cpp#L23-L96) - [HKDF CTest registration at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/d84eb91642525413dbc17f3520f1fb0de5bea0f7/core/libs/prx/libSceLibreSsl3/CMakeLists.txt#L86-L94) - [HKDF vectors and boundary assertions at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/d84eb91642525413dbc17f3520f1fb0de5bea0f7/core/libs/prx/libSceLibreSsl3/tests/Hkdf.cpp#L122-L192) - [LibreSSL 4.0.0 HKDF reference, pinned to `ce488b78e0bd994780569df718596b9776ff681a`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/hkdf/hkdf.c#L29-L123) - [Existing HMAC implementation used by the PR, pinned to base `4f41f4c375f5abb487dbd184fbc150f31994d762`](https://github.com/boykopovar/AnyPS5/blob/4f41f4c375f5abb487dbd184fbc150f31994d762/core/libs/prx/libSceLibreSsl/src/Evp.cpp#L378-L428) ## Not verified I did not compile the new implementation or execute `guest_libressl3_hkdf`. The full build/CTest report and its IPv6 failure attribution are author-reported; I did not inspect raw logs. No PS5 console or title was tested. ## To get this to a good state Please identify the tested SHA and attach or link the build and CTest output for it. If it is `d84eb91642525413dbc17f3520f1fb0de5bea0f7`, I will recheck that evidence on this head; if the tested head differs, I will run the same no-build checks against the new head before reassessing.

Pull request closed

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!15472
No description provided.