feat(libSceLibreSsl3): implement the EVP AES-128-CCM cipher #16255
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16255"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Ducengarth on 2026-11-06T00:54:45Z.
What
Implement
EVP_aes_128_ccm(NID 896,uM9UnC8KFjY) inlibSceLibreSsl3, replacing its parameterless throwing placeholder inAdditionalExports.cpp. Source: LibreSSL 4.0.0 atce488b78, the revision the library's debt file already uses:evp/e_aes.c(aes_ccm_ctrl,aes_ccm_init_key,aes_ccm_cipher) andmodes/ccm128.c.CRYPTO_ccm128_*is ported byte for byte over the parent'sAES_set_encrypt_keyandAES_encrypt, in the same way libSceLibreSsl'sEvpAes.cppportsgcm128.c. mbedtls's CCM is not used, because it rejects 0xFF00 bytes of AAD or more and does not reproduceccm128.c's behaviour:EVP_CTRL_CCM_SET_LorSET_TAGchanges the nonce length or tag length the EVP layer passes, not the encoding.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) andEVP_CTRL_COPY(rebinds the key schedule pointer), with the same return values.ctx_size336, the LP64 size ofEVP_AES_CCM_CTX. It uses libSceLibreSsl's 88-byteEVP_CIPHER, so the existingEVP_CIPHER_key_lengthandEVP_CIPHER_iv_lengthwork on it.It runs inside libSceLibreSsl's
EVP_CipherInit_ex,EVP_*UpdateandEVP_*Final_ex, which libSceLibreSsl3 forwards. For CCM, 4.0.0'sEVP_*Updatepasses a zero-length update to the cipher, as 2.5.4 does, so the length-setting call works unchanged. One change there:EVP_CipherInit_exnow takes the cipher data fromcallocinstead ofmalloc. 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.4EVP_EncryptUpdate,EVP_EncryptFinal_exand encryptingEVP_Cipher*calls leave*outlunset and accept a nulloutl, 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_ccmandEVP_aes_256_ccmare 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_overlapreports 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:CMakeLists.txtand the debt file. #16249 also makes the samecallocchange, so whichever merges second resolves only the neighbouring lines.I will rebase this one as needed. 65 pull requests that conflict with
maincould not be compared by the tool. I scanned the diffs of all 1892 open pull requests foraes_128_ccm,ccm128and 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:0xFFFElength encoding.SET_IVLENorSET_L. Each message is also opened with a flipped tag bit, ciphertext and AAD, and the output must be zeroed.SET_IVLENwithINT_MINandINT_MAX.EVP_CTRL_COPY: a copied context still encrypts after the source is freed.EVP_CIPHER_key_lengthandEVP_CIPHER_iv_length.mallocfills memory with 0xFF so that thecallocdependence is checked.guest_libressl*andguest_crypto_memcmptests pass, including libSceLibreSsl's after thecallocchange.objdump -ponlibSceLibreSsl3.prxlistsEVP_aes_128_ccm_nid_postfixand nombedtls_*symbol.python3 tools/check_conventions.py --base upstream/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code