Skip to content

feat(libSceLibreSsl3): implement the EVP AES-128-CCM cipher - #16255

Merged
oneandonlydean merged 10 commits into
boykopovar:mainfrom
Ducengarth:feat/libressl3-aes-ccm
Nov 9, 2026
Merged

oneandonlydean merged 10 commits into
boykopovar:mainfrom
Ducengarth:feat/libressl3-aes-ccm

Conversation

@Ducengarth

@Ducengarth Ducengarth commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What

Implement EVP_aes_128_ccm (NID 896, uM9UnC8KFjY) in libSceLibreSsl3, replacing its parameterless throwing placeholder in AdditionalExports.cpp. Source: LibreSSL 4.0.0 at ce488b78, the revision the library's debt file already uses: evp/e_aes.c (aes_ccm_ctrl, aes_ccm_init_key, aes_ccm_cipher) and modes/ccm128.c.

  • CRYPTO_ccm128_* is ported byte for byte over the parent's AES_set_encrypt_key and AES_encrypt, in the same way libSceLibreSsl's EvpAes.cpp ports gcm128.c. mbedtls's CCM is not used, because it rejects 0xFF00 bytes of AAD or more and does not reproduce ccm128.c's behaviour:
    • L and M are encoded in the nonce flags byte when the key is set, so a later EVP_CTRL_CCM_SET_L or SET_TAG changes the nonce length or tag length the EVP layer passes, not the encoding.
    • A failed encrypt leaves the flags byte without M.
    • Only one AAD call per message is supported.
  • The EVP flow matches 4.0.0:
    • A null output with a null input sets the message length; a null output with an input is the AAD, and is rejected before the length.
    • A null input is the final call, which writes nothing.
    • A decrypt checks the tag in the update, zeroes the output when the tag is wrong, and leaves the final call failing, as in LibreSSL.
  • The controls are EVP_CTRL_INIT (L 8, M 12), AEAD_GET_IVLEN (15 - L), AEAD_SET_IVLEN, CCM_SET_L, CCM_SET_TAG (even, 4 to 16; a tag only when decrypting), CCM_GET_TAG (encrypt only, after the message) and EVP_CTRL_COPY (rebinds the key schedule pointer), with the same return values.
  • The cipher object copies LibreSSL's fields: block size 1, key length 16, IV length 12, flags 0x501477 and ctx_size 336, the LP64 size of EVP_AES_CCM_CTX. It uses libSceLibreSsl's 88-byte EVP_CIPHER, so the existing EVP_CIPHER_key_length and EVP_CIPHER_iv_length work on it.

It runs inside libSceLibreSsl's EVP_CipherInit_ex, EVP_*Update and EVP_*Final_ex, which libSceLibreSsl3 forwards. For CCM, 4.0.0's EVP_*Update passes a zero-length update to the cipher, as 2.5.4 does, so the length-setting call works unchanged. One change there: EVP_CipherInit_ex now takes the cipher data from calloc instead of malloc. LibreSSL 4.0.0 zeroes it, and an IV-only init before any key relies on that: with a zero flags byte, the length call fails as in LibreSSL instead of reading garbage. This is the same one-line change as in #16249. In 2.5.4 the contents were unspecified, so it is still valid for libSceLibreSsl's own ciphers.

Known gap, recorded in docs/dev/debt/libSceLibreSsl3.md: when the cipher fails, the forwarded 2.5.4 EVP_EncryptUpdate, EVP_EncryptFinal_ex and encrypting EVP_Cipher* calls leave *outl unset and accept a null outl, where 4.0.0 sets it to 0 first. The decrypt calls already match. A negative length returns 0 with the state untouched, as in 4.0.0.

EVP_aes_192_ccm and EVP_aes_256_ccm are not among libSceLibreSsl3's exports, so they are not added.

No title's trace or disassembly was used, and the export was not measured on a PS5.

pr_overlap reports no pull request with the same exports or new files. The "same exports" it lists (Allocate, Align, Calloc, Free, PosixAlign, Realign, Reallocate) are the test's file-local guest-heap callbacks, which other tests also define. The remaining hits are line conflicts:

I will rebase this one as needed. 65 pull requests that conflict with main could not be compared by the tool. I scanned the diffs of all 1892 open pull requests for aes_128_ccm, ccm128 and CCM helpers, and none adds them.

Tested

Windows 11, MinGW-w64 GCC (WinLibs), Release build. No title or homebrew, and not built on Linux or macOS.

  • guest_libressl3_aes_ccm (new) passes. It drives the cipher through the forwarded EVP functions:
    • Vectors: NIST SP 800-38C examples C.1 to C.4, sealed and opened. C.4 has 65536 bytes of AAD, which exercises the 0xFFFE length encoding.
    • Random, against mbedtls's independent CCM: 400 messages over every L (2 to 8) and even M (4 to 16), AAD up to 0xFEFF bytes, ten 65535-byte messages with L = 2, and empty AAD and messages. The length is set with and without the explicit call, using SET_IVLEN or SET_L. Each message is also opened with a flipped tag bit, ciphertext and AAD, and the output must be zeroed.
    • Defaults: the 7-byte nonce and 12-byte tag of an unconfigured context.
    • Controls: every control's in-range and out-of-range return values, including SET_IVLEN with INT_MIN and INT_MAX.
    • Parameters fixed at the key: a tag length set after the key, and a longer or shorter nonce length set after the key.
    • Sequencing: no key and no IV, an IV only, AAD before the length, zero and negative lengths, a length mismatch, a second update, in-place encryption and decryption, and a decrypt without a tag.
    • Empty message, and a final call without an update.
    • EVP_CTRL_COPY: a copied context still encrypts after the source is freed.
    • Cipher object: the fields, read directly and through EVP_CIPHER_key_length and EVP_CIPHER_iv_length.
    • The test's guest malloc fills memory with 0xFF so that the calloc dependence is checked.
  • Of 16 deliberate bugs, the test catches 14. The other two are equivalent at guest sizes: they only differ for messages of 2^32 blocks or more.
  • All 102 guest_libressl* and guest_crypto_memcmp tests pass, including libSceLibreSsl's after the calloc change.
  • objdump -p on libSceLibreSsl3.prx lists EVP_aes_128_ccm_nid_postfix and no mbedtls_* symbol.
  • python3 tools/check_conventions.py --base upstream/main passes.

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

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Progress report (f0228ed → 9ce8e6f)

📈 System libraries: 33.31% (+0.01%, +4 implemented functions)

✅ 4 implemented
Library Name
libSceLibreSsl3 AesCcmCipher
libSceLibreSsl3 AesCcmControl
libSceLibreSsl3 AesCcmInitKey
libSceLibreSsl3 EVP_aes_128_ccm_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl3 115/290 (39.66%) 119/293 (40.61%) +0.96%

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 6, 2026
Implement EVP_aes_128_ccm after LibreSSL 4.0.0 e_aes.c and ccm128.c over
the parent AES: the L and M parameters fixed at key setup, the length,
AAD and tag calls through the EVP update and control interfaces, the
zeroed output after a bad tag and the context copy fixup. The forwarded
libSceLibreSsl EVP_CipherInit_ex now zeroes the cipher data as LibreSSL
4.0.0 does, which the IV-only path relies on. Record the unverified
console behaviour as debt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ducengarth
Ducengarth force-pushed the feat/libressl3-aes-ccm branch from bb0133f to c8a87e9 Compare November 6, 2026 01:25
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 6, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 6, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 6, 2026
Ducengarth and others added 2 commits November 7, 2026 02:15
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 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 1384 Allocate
PR 15622 Align
Allocate
PosixAlign
Realign
Reallocate
PR 15625 Align
Allocate
PosixAlign
Realign
Reallocate
PR 15627 Align
Allocate
PosixAlign
Realign
Reallocate
PR 15765 Align
Allocate
PosixAlign
Realign
Reallocate
PR 16541 AesCcmCipher
AesCcmControl
AesCcmInitKey
EVP_aes_128_ccm
libreSsl3Forward_EVP_aes_128_ccm_nid_no_patch
PR 16690 docs/dev/debt/libSceLibreSsl3.md L184-185
PR 16819 Align
Allocate
Calloc
Free
PosixAlign
Realign
Reallocate
PR 16971 Allocate
Reallocate

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 12315 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 14212 docs/dev/debt/libSceLibreSsl3.md
PR 14465 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 14890 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15163 core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15514 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15544 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15591 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15616 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15618 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15620 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15622 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15623 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15625 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15627 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15628 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15629 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15765 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 15831 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16529 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16535 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16543 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16586 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16588 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16589 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16689 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16742 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16819 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16918 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16926 core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16977 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16979 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 16996 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17124 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17235 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17236 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17237 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17238 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17240 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17241 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17242 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17243 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17246 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17249 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17250 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17528 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 17544 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 7, 2026
…/libressl3-aes-ccm

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 7, 2026
@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head f4c5ea1064, merged onto main 4ab649f4d8 (649b874b96, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_libressl3_aes_ccm passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 8, 2026
Ducengarth and others added 3 commits November 8, 2026 14:31
…/libressl3-aes-ccm

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…/libressl3-aes-ccm

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…/libressl3-aes-ccm

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oneandonlydean oneandonlydean self-assigned this Nov 9, 2026
Resolve the libSceLibreSsl3 CMakeLists.txt (keep the AES-CCM source and test next to the ChaCha ones from main) and recount the debt-doc "Additional exports" line from AdditionalExports.cpp on the merged tree.

Credit: Ducengarth (PR author).
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 9, 2026
@oneandonlydean
oneandonlydean merged commit e67e806 into boykopovar:main Nov 9, 2026
13 checks passed
@Ducengarth
Ducengarth deleted the feat/libressl3-aes-ccm branch November 26, 2026 19:27
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