Skip to content

feat(libSceLibreSsl): implement DES_set_key, DES_ecb_encrypt and DES_set_odd_parity - #9047

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
VakzOs:feat/libressl-des
Oct 23, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
VakzOs:feat/libressl-des

Conversation

@VakzOs

@VakzOs VakzOs commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

What

Implements three libSceLibreSsl exports that were throwing NotImplemented: DES_set_key, DES_ecb_encrypt and DES_set_odd_parity.

  • The DES block cipher and the odd-parity helper come from mbedtls (mbedtls_des_*, mbedtls_des_key_set_parity), which is already a submodule built for libSceSsl, so no cipher code is added; libSceLibreSsl now links mbedcrypto
  • DES_set_key follows LibreSSL's des_key.c with DES_check_key off, its default (the variable is not in the PS5 export inventory): no parity or weak-key check, returns 0
  • DES_ecb_encrypt encrypts for any nonzero enc, as LibreSSL's DES_encrypt1 does

Gap, recorded in the debt entry: the 128-byte DES_key_schedule stores the 8-byte key followed by zeros instead of LibreSSL's precomputed subkeys, and the subkeys are derived on each DES_ecb_encrypt call. Null pointers throw where LibreSSL faults. The pending-exports count goes from 399 to 396.

The new core/libs/prx/libSceLibreSsl/CMakeLists.txt overlaps with the one added by #9025, #9033 and #9041; whichever is merged later only needs to merge the test and mbedcrypto lines.

Tested

Linux (Ubuntu, GCC), full build: guest_libressl_des checks the classic vectors (133457799BBCDFF1 / 0123456789ABCDEF → 85E813540F0AB405, 0E329232EA6D0D73 / 8787878787878787 → 0) and the SP 800-17 vector 0101010101010101 / 8000000000000000 → 95F8A5E5DD31D900, both directions, in-place decryption, a nonzero enc other than 1, all 256 parity bytes, the unchecked weak and bad-parity keys, and null pointers. The test fails when encryption and decryption are swapped. libSceLibreSsl.prx patches its NIDs. tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py cannot reach the GitHub API from my environment; I checked every open PR branch by hand right before opening: only #8747 (the declarations) touches 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

🤖 Generated with Claude Code

@VakzOs VakzOs changed the title feat(libSceLibreSsl): implement DES_set_key, DES_ecb_encrypt and DES_… feat(libSceLibreSsl): implement DES_set_key, DES_ecb_encrypt and DES_set_odd_parity Oct 21, 2026
@clairtonmichel

Copy link
Copy Markdown

Tested on AMD Ryzen 7 9800X3D and AMD Radeon RX 7900 XTX (Fedora Linux, Mesa 26.2.5):

  • Built cleanly with zero errors.
  • Ran the guest_libressl_des test suite: 100% passed successfully (1/1 green in 0.01s).
  • DES block cipher exports (DES_set_key, DES_ecb_encrypt, and DES_set_odd_parity) behave correctly. Ready to merge!

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 9870 docs/dev/debt/libSceLibreSsl.md L5-6
PR 9949 core/libs/prx/libSceLibreSsl/CMakeLists.txt L1-2, L15
docs/dev/debt/libSceLibreSsl.md L5-6
PR 10005 docs/dev/debt/libSceLibreSsl.md L5-6
PR 10065 docs/dev/debt/libSceLibreSsl.md L5-6
PR 10071 docs/dev/debt/libSceLibreSsl.md L5-6
PR 10078 core/libs/prx/libSceLibreSsl/CMakeLists.txt L15
core/libs/prx/libSceLibreSsl/Export.cpp L4
docs/dev/debt/libSceLibreSsl.md L5-6

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 9033 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
docs/dev/debt/libSceLibreSsl.md
PR 9041 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
docs/dev/debt/libSceLibreSsl.md
PR 9446 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
docs/dev/debt/libSceLibreSsl.md
PR 9448 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
docs/dev/debt/libSceLibreSsl.md
PR 9745 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
docs/dev/debt/libSceLibreSsl.md
PR 9942 core/libs/prx/libSceLibreSsl/Export.cpp
docs/dev/debt/libSceLibreSsl.md
PR 9970 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
docs/dev/debt/libSceLibreSsl.md

…set_odd_parity

The DES block cipher and the parity helper come from mbedtls, which is
already a submodule; DES_set_key follows LibreSSL with DES_check_key
off and stores the key in the schedule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FzhWRMauD3ouc8kSxT2NnT
@VakzOs

VakzOs commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main after #9025 landed. The only conflicts were the shared files: core/libs/prx/libSceLibreSsl/CMakeLists.txt now keeps Digest.cpp and the digest test from #9025 and adds the mbedcrypto link and the DES test; docs/dev/debt/libSceLibreSsl.md keeps both entries and the pending count goes from 377 to 374 (Export.cpp has 374 NotImplemented stubs). guest_libressl_des and guest_libressl_digest pass, libSceLibreSsl.prx patches its NIDs, tools/check_conventions.py --base origin/main passes and the branch merges cleanly into main. If another LibreSsl PR lands first, I’ll rebase again.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@VakzOs the exact-head CI on this PR fails guest_libressl_des on Windows (Linux passes):

terminate called after throwing an instance of 'std::invalid_argument'
  what():  DES_set_key_nid_postfix: invalid argument

The arguments are not the problem: the test passes nullptr to DES_set_key_nid_postfix on purpose and catches the std::invalid_argument (the RequireThrows lines at the end of main). The exception has to unwind through the sysv_abi frame of the library, and the test executable is not set up for that on Windows. In core/libs/prx/libSceLibreSsl/CMakeLists.txt, the digest test next to it links libc and calls configure_windows_unwind(...); the new DES test does neither. The other tests that catch exceptions from these calls do both (201 of the 211 that catch exceptions use configure_windows_unwind), so I expect this is the whole difference, but I cannot run Windows here.

Could you make the DES test match the digest one?

-    target_link_libraries(guest_libressl_des_tests PRIVATE libSceLibreSsl)
+    target_link_libraries(guest_libressl_des_tests PRIVATE libSceLibreSsl libc)
+    configure_windows_unwind(guest_libressl_des_tests)

The test code and the library do not need to change. Since the PR allows edits from maintainers, I can also push that change on top of 3778e9fc98 after about 24 hours if you prefer, and then run CI on the new head.

The DES test catches std::invalid_argument thrown through the library's
sysv_abi frames; like the digest test, it now links libc and calls
configure_windows_unwind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FzhWRMauD3ouc8kSxT2NnT
@VakzOs

VakzOs commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Thanks, you’re right: the DES test was missing the Windows unwind setup the digest test has. Pushed 3fe7217 with exactly your change (libc link plus configure_windows_unwind(guest_libressl_des_tests)); the library and the test code are unchanged. guest_libressl_des and guest_libressl_digest pass on Linux; I can’t run Windows here, so the next CI run will confirm.

@oneandonlydean
oneandonlydean merged commit 812ed15 into boykopovar:main Oct 23, 2026
2 checks passed
@VakzOs
VakzOs deleted the feat/libressl-des branch October 23, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants