Skip to content

feat(libSceLibreSsl): implement EVP_CIPHER_CTX_init, EVP_CIPHER_CTX_new and EVP_CIPHER_CTX_set_padding - #10488

Open
alvaroelpob wants to merge 4 commits into
boykopovar:mainfrom
alvaroelpob:feat/libscelibressl-evp-cipher-ctx
Open

alvaroelpob wants to merge 4 commits into
boykopovar:mainfrom
alvaroelpob:feat/libscelibressl-evp-cipher-ctx

Conversation

@alvaroelpob

@alvaroelpob alvaroelpob commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements EVP_CIPHER_CTX_init, EVP_CIPHER_CTX_new and EVP_CIPHER_CTX_set_padding in libSceLibreSsl, which threw and were declared without parameters.

The module is LibreSSL 2.5.4 (firmware 13.40 measurements in #8981). Signatures, layout and results follow that release's evp.h and evp_enc.c:

Export Behaviour
void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX*) zeroes the 168-byte context
EVP_CIPHER_CTX* EVP_CIPHER_CTX_new(void) calloc(1, 168), through the guest calloc as the module would through libc
int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX*, int pad) clears EVP_CIPH_NO_PADDING (0x100) in the 64-bit flags at 112 when pad is nonzero, sets it otherwise, and returns 1

The 168-byte size is the one measured for EVP_CIPHER_CTX_init in #8981. The layout (num at 88, flags at 112, final at 136) was checked with static_asserts and against offsetof from the 2.5.4 headers compiled on x86-64. LibreSSL dereferences a null context in init and set_padding without checking it, so that throws.

#9571 forward-declares its own cipher context type for CMAC. This PR uses its own file and struct name, and changes none of its exports.

The debt entry records the source and what is unverified, and the pending-export count drops from 357 to 354.

Tested

Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with BUILD_TESTING=ON on main 379b1dc. There is one commit per function, and each adds that function with its test block and debt update. Each was built and its guest_libressl_evp_cipher_ctx test and check_conventions.py run on its own.

Checklist

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Progress report (aaccd0b → 10f8980)

📈 System libraries: 45.98% (+0.02%, +3 implemented functions)

✅ 3 implemented
Library Name
libSceLibreSsl EVP_CIPHER_CTX_init_nid_postfix
libSceLibreSsl EVP_CIPHER_CTX_new_nid_postfix
libSceLibreSsl EVP_CIPHER_CTX_set_padding_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl 90/401 (22.44%) 93/401 (23.19%) +0.75 pp

@alvaroelpob
alvaroelpob marked this pull request as ready for review October 24, 2026 03:14
Copilot AI balanced review requested due to automatic review settings October 24, 2026 03:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions

github-actions Bot commented Oct 24, 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 10570 core/libs/prx/libSceLibreSsl/CMakeLists.txt L1
PR 11003 docs/dev/debt/libSceLibreSsl.md L9, L24-25
PR 12601 docs/dev/debt/libSceLibreSsl.md L9, L23-24
PR 12729 core/libs/prx/libSceLibreSsl/CMakeLists.txt L1, L150
core/libs/prx/libSceLibreSsl/include/Api.hpp L211
docs/dev/debt/libSceLibreSsl.md L9, L24
PR 12730 core/libs/prx/libSceLibreSsl/CMakeLists.txt L1, L150
core/libs/prx/libSceLibreSsl/include/Api.hpp L211
docs/dev/debt/libSceLibreSsl.md L9, L24
PR 12844 core/libs/prx/libSceLibreSsl/CMakeLists.txt L1, L150
core/libs/prx/libSceLibreSsl/include/Api.hpp L211
docs/dev/debt/libSceLibreSsl.md L9
PR 12850 docs/dev/debt/libSceLibreSsl.md L9

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 10508 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10571 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10878 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10915 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11128 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11129 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11138 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11143 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11146 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11151 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11174 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11175 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11176 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11359 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11466 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11553 docs/dev/debt/libSceLibreSsl.md

@github-actions github-actions Bot added build docs prx needs rebase Conflicts with main, rebase needed labels Oct 24, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 03cb3efab33b5daf4b3f51e8f4348750967a049f.

I checked the context size/field offsets and the three behaviors against the pinned LibreSSL 2.5.4 declarations and implementation: initialization clears the complete context, creation uses the guest calloc, and set_padding changes only EVP_CIPH_NO_PADDING while returning 1. The overlap with #9571 is in shared files; this diff leaves its CMAC exports untouched. I found no blocking correctness issue in the reviewed code.

The PR reports focused context tests and a 2005/2006 full CTest run, with the remaining failure also present on main; I did not reproduce those runs locally. Current convention, labels, eligibility, and report checks pass. Linux, Windows, register-context, relinker, write-watch, and ASan jobs are skipped.

@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-evp-cipher-ctx branch from 03cb3ef to 4f073fa Compare October 24, 2026 15:32
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main 1e740a2 (head 4f073fa) to resolve the conflict from #9033 on the shared CMakeLists.txt and debt-file lines. Full suite 2043/2044, with the same failure on main. Depends on drops #9033 and adds #9949.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 24, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 25, 2026
@EagleBearerYS

Copy link
Copy Markdown
Contributor

@alvaroelpob a heads-up: we've stacked the rest of the EVP cipher calls on your three commits, as draft #10834. It adds the Cipher/Encrypt/Decrypt Init_ex, Update and Final_ex calls, EVP_CIPHER_CTX_cleanup, _free and _ctrl, AES CFB8, CTR and GCM, and EVP_cleanup: 22 in all. Your commits are unchanged in it.

Since #9529 merged, this branch conflicts with main in libSceLibreSsl's CMakeLists.txt and its debt file. In case it saves you time, fix/10488-main-merge on our fork is your head with main merged in (5d92c06915):

  • both sides are kept: main's src/Error.cpp and guest_libressl_error next to your src/EvpCipherCtx.cpp and guest_libressl_evp_cipher_ctx;
  • the pending-exports count becomes 350, which is main's 353 less your 3;
  • the LibreSSL tests pass on GitHub's Linux and Windows runners, including both new test executables (run).

Take it, or resolve it your own way; that's entirely up to you.

@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-evp-cipher-ctx branch from 4f073fa to 6b1e364 Compare October 25, 2026 05:31
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main e7e3e9c, head 6b1e364, to resolve the conflict from #9529 on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 353 minus this PR's exports. #10706 now requires each export to be declared once in include/Api.hpp, so 6b1e364 moves these signatures and their structs there and drops the test's redeclarations. Full suite 2202/2203, with the same failure on main. Depends on drops the merged #9529. @EagleBearerYS thanks for the merge branch; I rebased instead, so #10834 will need to rebase onto this head, including the header commit.

@EagleBearerYS

Copy link
Copy Markdown
Contributor

@alvaroelpob Thanks for the rebase and the header commit; #10834 will rebase onto 6b1e364 and follow the same pattern for its exports.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 25, 2026
@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-evp-cipher-ctx branch from b188b78 to 3b0f1cd Compare October 25, 2026 18:51
@alvaroelpob

alvaroelpob commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased on main ae7d592 (after #9949; head 9a3cb4e) to resolve the conflicts on the shared CMakeLists.txt and debt-file lines; no change to this PR's functions. Full ctest -j16 2275/2276, agc_driver_multisample_retirement fails the same way on main. Depends on drops the merged #9949, #10005, #10071 and #10484.

@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-evp-cipher-ctx branch from 3b0f1cd to 9a3cb4e Compare October 25, 2026 20:08
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 25, 2026
@BunnyFl

BunnyFl commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

@alvaroelpob firmware 13.42's libSceLibreSsl.sprx agrees with these three. I ran its own code in an emulator (Unicorn), and natively for the AVX init; four runs each gave identical results.

  • EVP_CIPHER_CTX_new makes one 0xa8-byte (168) calloc, and EVP_CIPHER_CTX_init clears exactly bytes 0-167.
  • EVP_CIPHER_CTX_set_padding works on the 64-bit flags at 112: pad 0 sets 0x100, a nonzero pad (1, 7) clears it, no other byte changes, and it returns 1 in every case (tried with flags 0, 0x100 and all ones).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main 2dbe9b9 (after #9745, #9870 and #11111; head f9a8c85) to resolve the conflicts on the shared CMakeLists.txt and debt-file lines; no change to this PR's functions. Full ctest -j16 2370/2371, agc_driver_multisample_retirement fails the same way on main.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 26, 2026
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main 88795ed (after #10248; head 9420353) to resolve the conflicts on the shared debt-file lines; no change to this PR's functions. Full ctest -j16 2383/2384, agc_driver_multisample_retirement fails the same way on main.

@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-evp-cipher-ctx branch from f9a8c85 to 9420353 Compare October 26, 2026 18:03
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 26, 2026
@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-evp-cipher-ctx branch from 9420353 to 4ec014c Compare October 26, 2026 22:08
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main c7b4878 (after #10373, #10376 and #10449; head 4ec014c) to resolve the conflicts on the shared CMakeLists.txt, Api.hpp and debt-file lines; no change to this PR's functions. Full ctest -j16 2394/2395, agc_driver_multisample_retirement fails the same way on main.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 26, 2026
@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-evp-cipher-ctx branch from 4ec014c to 9cc28a3 Compare October 27, 2026 12:00
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 27, 2026
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main 8ff4baf (head 9cc28a3) to resolve the conflict from #10398 on the shared CMakeLists.txt and debt-file lines. #10398 made the same 319 to 318 edit as this branch, so the merge lost one decrement; 9cc28a3 sets the count to 315, the exports that still throw. Depends on is now #9448, #9571, #10078, #10395, #10418, #10447, #10448, #10450, #10477, #10478, #10481, #10482, #10483, #10485, #10486. Full suite 2543/2544, with agc_driver_multisample_retirement failing on main too; conventions pass.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 27, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@alvaroelpob this no longer merges cleanly with current main (e52fd83): core/libs/prx/libSceLibreSsl/CMakeLists.txt, include/Api.hpp and docs/dev/debt/libSceLibreSsl.md conflict with #10447, #11340 and #11261, which landed since. The conflicts are in shared lists only, so keeping both sides should do. Could you rebase or merge main and push? Nothing else changes from the earlier review.

@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-evp-cipher-ctx branch from 9cc28a3 to 834bb1f Compare October 28, 2026 11:28
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main 3a40945 (head 834bb1f) after #10447, #11340 and #11261; the conflicts were only in the shared CMakeLists.txt, include/Api.hpp and debt-file lists, and both sides are kept. No change to this PR's functions. Pending-export line recounted against main: 310 (313 minus the 3 this PR implements). Full ctest -j16 2693/2693 (main 2692/2692); conventions pass.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 28, 2026
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main 4c7d275 (after #11105 and #11189; head 10f8980). The conflicts were only in the shared CMakeLists.txt, Export.cpp, include/Api.hpp and debt-file lines; both sides are kept and there is no change to this PR's functions. Pending-export line recounted against the stubs left in Export.cpp: 296. Full ctest -j16 2867/2868, with guest_freebsd_clocks failing on main too (2866/2867); conventions pass.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-check — changes requested\n\nThe new report is useful: it says the implementation functions were preserved through the merge and the full test suite has the same single known failure as its tested main, with conventions passing. However, the tested integration point is 4c7d275; current upstream main is aaccd0b, and this PR head is 44 commits behind it.\n\nPlease update onto current main, preserve the implementation and debt-count changes, recount the pending exports against the resulting Export.cpp, and rerun the relevant LibreSSL tests plus conventions on the exact updated head. The earlier approval was for the prior head and does not cover this stale integration point. I did not rerun these checks locally.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 29, 2026

This branch has not been deployed

No deployments
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.

6 participants