test(libSceLibreSsl3): pin the full RFC 8439 ChaCha20 ciphertext #16543

Merged
MarcZX10 merged 1 commit from upstream-pr/16543 into main 2026-11-10 09:37:27 +00:00
MarcZX10 commented 2026-11-07 02:54:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-07T02:54:34Z.


What

Implements EVP_chacha20, which was an i-only NotImplemented stub in libSceLibreSsl3 (AdditionalExports.cpp, NID 3tGgkjBQ82A).

  • The cipher lives in libSceLibreSsl (src/EvpChacha.cpp), next to the AES EVP ciphers, and is declared in include/Api.hpp.
  • libSceLibreSsl3 forwards 3tGgkjBQ82A to it; the stub and its declaration are removed.
  • The descriptor follows the vendored LibreSSL evp/e_chacha.c: NID 937, block size 1, 32-byte key, 16-byte IV, flags STREAM_CIPHER | CUSTOM_IV | ALWAYS_CALL_INIT, context size of ChaCha_ctx.
  • The IV layout is LibreSSL's, not the RFC 8439 one: a 64-bit block counter in bytes 0-7 and a 64-bit nonce in bytes 8-15. The keystream follows the vendored chacha/chacha-merged.c, including the counter carry and the reuse of a partial block's unused keystream.
  • No ChaCha20 primitive existed in the repository before; this is the only implementation.
  • EVP_chacha20_poly1305 is not part of this PR. The vendored LibreSSL has no EVP_CIPHER form of it (only the EVP_AEAD form), so its shape is not implemented here.

Commits:

  1. feat(libSceLibreSsl): add ChaCha20 key and IV setup
  2. feat(libSceLibreSsl): add the ChaCha20 keystream and stream update
  3. feat(libSceLibreSsl): implement the EVP_chacha20 cipher
  4. feat(libSceLibreSsl3): forward EVP_chacha20 to libSceLibreSsl
  5. test(libSceLibreSsl): pin EVP_chacha20 to RFC 8439 section 2.4.2
  6. test(libSceLibreSsl): cover the EVP_chacha20 counter carry and chunked updates
  7. docs(debt): drop EVP_chacha20 from the libSceLibreSsl3 unimplemented list
  8. docs(debt): record the EVP_chacha20 descriptor and keystream as unverified

Tested

Linux 6.1.0-54-amd64 x86_64, the default compiler of the archive build. Built in the throwaway archive build (run_tests.sh), with the HostCpu gate patched only in the archive copy.

Build: BUILD-EXIT 0

1/1 Test #3133: guest_libressl_evp_cipher_ctx ....   Passed    0.03 sec
100% tests passed, 0 tests failed out of 1

Targets built: guest_libressl_evp_cipher_ctx_tests and libSceLibreSsl3.

The test vectors:

  • RFC 8439 section 2.4.2 plaintext, key and ciphertext, with the RFC state written in LibreSSL's layout (counter 1, nonce 00:00:00:4a:00:00:00:00). The expected ciphertext was recomputed with an independent ChaCha20 implementation before it was pinned.
  • A counter-carry vector (counter 0xffffffff, second block crosses into word 13), and a 100 + 28 byte chunked update.

Not run against the unfixed code: the stub throws NotImplemented before the first assertion, so the new tests fail on main; this was reasoned, not executed. Not run on Windows, macOS, a console, or the title. The libSceLibreSsl3 forwarder is compiled and linked but no test calls it through the export; its only check is that the library builds. The debt entry lists the unverified parts (descriptor and keystream are not measured on a console).

The build ran on the tree before the last docs-only amend (the debt link was changed to an upstream URL); no code differs.

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:5197780558 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16543). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-07T02:54:34Z. --- ### What Implements `EVP_chacha20`, which was an `i`-only `NotImplemented` stub in libSceLibreSsl3 (`AdditionalExports.cpp`, NID `3tGgkjBQ82A`). - The cipher lives in libSceLibreSsl (`src/EvpChacha.cpp`), next to the AES EVP ciphers, and is declared in `include/Api.hpp`. - libSceLibreSsl3 forwards `3tGgkjBQ82A` to it; the stub and its declaration are removed. - The descriptor follows the vendored LibreSSL `evp/e_chacha.c`: NID 937, block size 1, 32-byte key, 16-byte IV, flags STREAM_CIPHER | CUSTOM_IV | ALWAYS_CALL_INIT, context size of `ChaCha_ctx`. - The IV layout is LibreSSL's, not the RFC 8439 one: a 64-bit block counter in bytes 0-7 and a 64-bit nonce in bytes 8-15. The keystream follows the vendored `chacha/chacha-merged.c`, including the counter carry and the reuse of a partial block's unused keystream. - No ChaCha20 primitive existed in the repository before; this is the only implementation. - `EVP_chacha20_poly1305` is not part of this PR. The vendored LibreSSL has no EVP_CIPHER form of it (only the EVP_AEAD form), so its shape is not implemented here. Commits: 1. `feat(libSceLibreSsl): add ChaCha20 key and IV setup` 2. `feat(libSceLibreSsl): add the ChaCha20 keystream and stream update` 3. `feat(libSceLibreSsl): implement the EVP_chacha20 cipher` 4. `feat(libSceLibreSsl3): forward EVP_chacha20 to libSceLibreSsl` 5. `test(libSceLibreSsl): pin EVP_chacha20 to RFC 8439 section 2.4.2` 6. `test(libSceLibreSsl): cover the EVP_chacha20 counter carry and chunked updates` 7. `docs(debt): drop EVP_chacha20 from the libSceLibreSsl3 unimplemented list` 8. `docs(debt): record the EVP_chacha20 descriptor and keystream as unverified` ### Tested Linux 6.1.0-54-amd64 x86_64, the default compiler of the archive build. Built in the throwaway archive build (`run_tests.sh`), with the HostCpu gate patched only in the archive copy. Build: `BUILD-EXIT 0` ``` 1/1 Test #3133: guest_libressl_evp_cipher_ctx .... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 ``` Targets built: `guest_libressl_evp_cipher_ctx_tests` and `libSceLibreSsl3`. The test vectors: - RFC 8439 section 2.4.2 plaintext, key and ciphertext, with the RFC state written in LibreSSL's layout (counter 1, nonce `00:00:00:4a:00:00:00:00`). The expected ciphertext was recomputed with an independent ChaCha20 implementation before it was pinned. - A counter-carry vector (counter 0xffffffff, second block crosses into word 13), and a 100 + 28 byte chunked update. Not run against the unfixed code: the stub throws `NotImplemented` before the first assertion, so the new tests fail on `main`; this was reasoned, not executed. Not run on Windows, macOS, a console, or the title. The libSceLibreSsl3 forwarder is compiled and linked but no test calls it through the export; its only check is that the library builds. The debt entry lists the unverified parts (descriptor and keystream are not measured on a console). The build ran on the tree before the last docs-only amend (the debt link was changed to an upstream URL); no code differs. ### Checklist - [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!16543
No description provided.