Repository navigation
feat(libSceLibreSsl): implement the EVP message digest and HMAC functions - #9448
Conversation
Progress report (24238c4 → 7bc5f0e)📈 System libraries: 26.18% (+0.06%, +21 implemented functions) ✅ 21 implemented
Changed libraries (implemented exports)
|
|
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.
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.
|
MarcZX10
left a comment
There was a problem hiding this comment.
The test coverage is unusually thorough: digest/HMAC vectors include chunk boundaries and RFC 4231 cases, context layouts and reuse are checked, and Linux plus MinGW runs are reported. I found one failure-path defect in DigestInit: when malloc_nid_postfix returns null, it returns 0 after assigning context.digest = type, but leaves context.mdData null. A retry with the same digest skips allocation because context.digest == type and then calls type->init(&context) with null mdData; this can crash. Please leave the context retryable (or otherwise fail explicitly without publishing a partially initialized digest) and add coverage for allocator failure/retry if the test harness allows it.
The branch is also based on a6dcea927, 47 commits behind current main (110a18ba01); the described checks and overlap scan used the earlier base/open-PR snapshot. Please update/rebase and rerun conventions, overlap/debt and focused digest/HMAC tests on current main, preserving the declared #9025 dependency and the CMake/debt merge coordination with #9033/#9041/#9047. Hosted full Linux/Windows product jobs are skipped; the author-reported local Linux and Windows tests are useful but not hosted validation. I did not run local crypto tests.
2e7d7c9 to
f6b83d9
Compare
|
@MarcZX10 Thanks, fixed in f6b83d9.
|
|
Rebased onto main 4777cac (includes 110a18b), still stacked on #9025 at 52a439b. The conventions check passes, and guest_libressl_evp, guest_libressl_digest and patched_libraries pass on Linux and on Windows (MinGW-w64 GCC 15.2.0). I rescanned all 1237 open PRs: no other PR touches these 20 functions. The conflicts with #9033, #9041, #9047, #9446 and #9529 are still only the add_library/test block in the CMakeLists and the debt count line, the same places as #9025's; #9571 conflicts only in the debt file and #9535/#9536 not at all. The description is updated. |
f6b83d9 to
81733ad
Compare
81733ad to
2b3f66e
Compare
2b3f66e to
ca37404
Compare
|
@oneandonlydean
On 334de4d (Linux): Comment to post on #9448 (2026-10-31, after the rebase)Rebased on On 4a465be (Linux): |
334de4d to
4a465be
Compare
…ions EVP_md5, EVP_sha256, EVP_sha384, EVP_sha512, EVP_MD_size, the EVP_MD_CTX init/create/cleanup/destroy functions, EVP_DigestInit_ex, EVP_DigestUpdate, EVP_DigestFinal_ex, EVP_Digest and HMAC_CTX_init, HMAC_CTX_cleanup, HMAC_Init, HMAC_Init_ex, HMAC_Update, HMAC_Final and HMAC threw. They now behave as LibreSSL's digest.c and hmac.c, on the public EVP_MD, EVP_MD_CTX and HMAC_CTX layouts, and call through the EVP_MD function table, so a context the title copies or inspects and a digest table the title defines keep working. The module exports SSL_get0_param and X509_VERIFY_PARAM_set1_host (new in LibreSSL 2.7) and HMAC_CTX_init (gone in 3.5); between 2.7.2 and 3.4.1 these layouts and functions do not change. ENGINE and EVP_PKEY_CTX use, and calls LibreSSL would crash on, throw. When allocating the digest data fails, the context is left without a digest instead of with a digest and no data, so initialising it again allocates rather than running the digest's init on a null pointer. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
main now records LibreSSL 2.5.4 for the module, from the firmware 13.40 measurements, while the EVP/HMAC entry inferred 2.7 or later from the SSL_get0_param export. digest.c, hmac.c and the EVP_MD, EVP_MD_CTX and HMAC_CTX layouts behave the same from 2.5.4 to 3.4.1, so the entry now links the 2.5.4 sources and names both readings. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…n the public header The canonical include/Api.hpp still declared the 20 implemented EVP and HMAC exports with the unknown no-parameter signature. It now holds the EVP_MD, EVP_MD_CTX and HMAC_CTX layouts and the real signatures, and Evp.cpp and the guest test use it instead of local declarations. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
HMAC with a 64-byte key for SHA-256 and a 128-byte key for SHA-512 must copy the key unhashed, as LibreSSL 2.5.4's hmac.c only hashes keys longer than the block. The expected MACs, key lengths and flags (MD5 0, SHA-256/384/512 0xc) were produced by LibreSSL 2.5.4's own hmac.c, digest.c, m_sha1.c and m_md5.c. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ource Evp.cpp follows the control flow of LibreSSL 2.5.4's digest.c and hmac.c, so it starts with the copyright notices, licence conditions and disclaimers of both files, verbatim from commit 2e2c612066aa. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ontext paths The ENGINE arguments to EVP_DigestInit_ex, EVP_Digest and HMAC_Init_ex, a cleanup with an ENGINE set and an init with an EVP_PKEY_CTX set throw because that support is missing, not because the input is invalid. Asserting it would break once the support exists, so the test no longer checks these paths. The production guards and the debt entry stay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4a465be to
a505de4
Compare
|
@oneandonlydean could you make the merge decision for current head Your license-notice and implementation-limit assertion requests are present in the current source. MarcZX10's latest submitted review is APPROVED; there are no inline review threads or current conflicts. The current-head linked Windows Build 41306912241 succeeded. The later ten-PR batch 41347775299 includes this exact head and passed its full Linux/Windows product jobs, but failed overall on the x86_64/Rosetta I have only upstream READ permission. Please merge if no concrete blocker remains, or identify the remaining required change/run. If a fresh single-PR run is needed, the current-main command is |
|
@HQasper #9448 currently reports a merge conflict at |
|
@HQasper I prepared the conflict resolution so you can adopt it directly: commit The three conflicts preserve both EVP/HMAC and main's cipher-context source, declarations and tests; existing ERR and LibreSSL3 changes stay intact. The original EVP/HMAC implementation and fixture are unchanged. Linux x86-64/GCC 16.2.1 Release: 43 related SSL/SSL3/crypto tests and 65 public-header checks pass, along with conventions and targeted NID patching of the two freshly built providers. Two protocol tests that depend on the full-project If your branch is still at git fetch https://github.com/AZLisme/AnyPS5.git codex/parent9448-donor-20261102
git merge --ff-only FETCH_HEADPlease review/adopt this resolution and update the existing PR branch. @oneandonlydean, this addresses the current conflict blocking #9448 and its dependent #10960 once adopted; please merge after your remaining concrete checks/decision. I have not changed HQasper's branch or opened another PR. |
|
Hi HQasper, #9448 conflicted with main, and it is the remaining prerequisite for #10960, so we have fast-forwarded your branch to the merge AZLisme prepared: 7bc5f0e, a merge of your unchanged head a505de4 with main 98346b7. Thanks, AZLisme. We checked it before pushing. It changes only the three conflicted files. The CMake source list keeps both sides' files, Api.hpp keeps your EVP digest/HMAC structs and main's cipher context, and the pending-exports figure is 261, which matches the stub count in Export.cpp. It builds, and the affected tests pass on Linux. Your own commits are unchanged. |
|
@oneandonlydean the conflict repair you adopted at GitHub now reports CLEAN with all completed applicable checks successful; the agreed conflict repair is on the author's branch. Please merge #9448, or identify a concrete remaining issue. Its actual merge will unblock the final #10960 integration, which I will test against the landed source. My upstream permission remains READ, so I cannot perform the merge myself. |
What
All libSceLibreSsl exports outside the open PRs still throw. This implements the 20 EVP message digest and HMAC exports, which is what code built on LibreSSL normally calls instead of the raw
SHA256_*functions:EVP_md5,EVP_sha256,EVP_sha384,EVP_sha512,EVP_MD_size,EVP_MD_CTX_init,EVP_MD_CTX_create,EVP_MD_CTX_cleanup,EVP_MD_CTX_destroy,EVP_DigestInit_ex,EVP_DigestUpdate,EVP_DigestFinal_ex,EVP_Digest,HMAC_CTX_init,HMAC_CTX_cleanup,HMAC_Init,HMAC_Init_ex,HMAC_Update,HMAC_FinalandHMAC.mainalready cites forX509_verify_cert_error_stringidentify LibreSSL 2.5.4, while the module's export table also hasSSL_get0_paramandX509_VERIFY_PARAM_set1_host, which the Symbols.list of 2.5.4 and 2.6.3 lack and 2.7.2's has. It also hasHMAC_CTX_init/HMAC_CTX_cleanup, which 3.4.1 has and 3.5.2 dropped whenHMAC_CTXbecame opaque. The functions follow 2.5.4's digest.c and hmac.c, andsrc/Evp.cppstarts with the copyright notices, licence conditions and disclaimers of both files, verbatim from that commit. Up to 3.4.1,hmac.conly gains new functions,digest.conly changesmalloctocallocfor the digest data and drops a null check beforeENGINE_finish, and theEVP_MD,EVP_MD_CTXandHMAC_CTXstructures do not change, so the behaviour is the same for either reading.EVP_MD(120 bytes),EVP_MD_CTX(48) andHMAC_CTX(288) follow evp.h and hmac.h and are checked withstatic_asserton size and field offsets. Theunsigned longflags are a 64-bit field, so the layout also holds on Windows. A context the title allocates, copies or reads (for example through theHMAC_sizemacro, which readsctx->md) stays valid.include/Api.hppdeclared the 20 functions with the unknown no-parameter signature. It now holds the three layouts (EvpMd,EvpMdContext,HmacContext) and the real signatures, andEvp.cppand the test include it instead of local declarations, as was done for theERRand OCSP functions.ONESHOT,CLEANED,REUSEandNO_INITwork as indigest.c. Digest data is reused when a context is initialised again with the same digest, freed and replaced when the digest changes, zeroed afterEVP_DigestFinal_ex, and zeroed and freed byEVP_MD_CTX_cleanup, which then clears the context.EVP_DigestInit_exreturns 0 and leaves the context without a digest, update function or data, so calling it again allocates again. LibreSSL keeps the digest with null data there, and a retry with the same digest runs its init on a null pointer. The context copy insideHMAC_Init_exandHMAC_Finaldoes the same when its allocation fails.HMAC_Init_exhashes keys longer than the block size and stores a key of exactly the block size unhashed, ashmac.cdoes (block < len). It re-initialises with the stored key when called without key or digest, and returns 0 when the digest changes without a key, for a negative key length and when no digest was ever set.HMAC_UpdateandHMAC_Finalreturn 0 without a digest.HMAC_Initclears the context first when both key and digest are given.HMACwith a null output buffer returns a static buffer.HMAC_CTX_cleanupzeroes all 288 bytes.EVP_MDfunction table, so anEVP_MDthe title defines itself also works.EVP_MDtables carry LibreSSL's NIDs, public key types, flags (0 for MD5,EVP_MD_FLAG_PKEY_METHOD_SIGNATURE | EVP_MD_FLAG_DIGALGID_ABSENT= 0xc for SHA-256, SHA-384 and SHA-512), block sizes and context sizes fromm_md5.candm_sha1.c.signandverify(RSA_sign,RSA_verifyin LibreSSL) are null becauseRSA_signandRSA_verifystill throw.EVP_MD_CTX_createcontexts come from the guest heap (malloc,callocandfreeof libc), as LibreSSL uses the module's own libc.NotImplemented_nid_no_patch: anENGINEargument, and a context that holds anENGINEor anEVP_PKEY_CTX. Null contexts,EVP_DigestInit_exwithout a type on a context that already has a digest, and an update or final on a context without a digest throwstd::invalid_argument; LibreSSL does not check these and would crash.mainnow has the queue andLibreSslPutError_nid_no_patch, but no libSceLibreSsl export publishes to it yet; publishing LibreSSL's codes here (for exampleERR_R_MALLOC_FAILUREfromEVP_DigestInit_ex) is left for a follow-up and recorded in the debt entry.Export.cpp.Tested
Which head each run covers: everything under Linux is on the current head 4a465be (on
main0836dfd, 2026-10-31). The Windows run is on the earlier head b2583e3 and has not been repeated since.Linux (Ubuntu 24.04 container, GCC 13.3, Release,
BUILD_TESTING=ON; on 4a465be; earlier rounds on f6b83d9, 81733ad, 2b3f66e, ca37404, 5994190, b2583e3, 42d887d, b55c473, 0929356, 6f2687c, db69a66 and 334de4d):New
guest_libressl_evp: passed. For MD5, SHA-256, SHA-384 and SHA-512 it checks:EVP_MDfields (NID, public key type, size, flags, block and context size, required key types, function pointers), with flags 0 for MD5 and 0xc for SHA-256, SHA-384 and SHA-512;EVP_DigestInit_ex/Update/Final_exandEVP_Digeston the empty string,abcand a 1000-byte message, fed in chunks of 1, block - 1, block, block + 1 and 1000 bytes;key_lengthequals the block size and that the key is stored unhashed, plus the one-shotHMAC;HMAC_CTXfields (md,key_length, the key and its zero padding), re-initialisation without key and digest,HMAC_Init, and the one-shotHMACwith and without an output buffer;Finalandcleanup, the reuse of digest data, theNO_INITflag, a title-definedEVP_MD, a digest size over 64 returning 0, the HMAC refusals listed above and the invalid-argument throws (null contexts, an update or final without a digest,EVP_DigestInit_exwithout a type on a context that has one). TheENGINEandEVP_PKEY_CTXpaths are not asserted, as they throw only because that support is missing;ApplicationHeapRegister_nid_no_patchthat fails a chosen allocation and counts live blocks:EVP_DigestInit_exon a new context and when switching digest,EVP_MD_CTX_create,EVP_Digest,HMAC_Init_exfailing at each of its three allocations with a 4-byte and a 131-byte key, andHMAC. Each returns 0 or null, frees what it allocated and leaves no context with a digest but no data (an update or final on a context left without a digest throws), and the same call again gives the right digest or MAC. No block is left allocated at the end of the test.Expected values were computed with Python
hashlibandhmac; the SHA-2 HMAC values match RFC 4231. The block-size key MACs, the stored key length and key, and the flags of all four tables were also produced by LibreSSL 2.5.4's ownhmac.c,digest.c,m_sha1.c,m_md5.c,sha256.c,sha512.candmd5_dgst.c(commit 2e2c61206, built with a small host harness) and match. With the inner pad changed to 0x37, the key padding left out, theNO_INITearly return removed or the context clearing inHMAC_Initremoved, the test fails. It also fails when a key of exactly the block size is hashed (block <= len), whenEVP_MD_FLAG_DIGALGID_ABSENTis dropped from SHA-256 or set on MD5, and with the previousEVP_DigestInit_exorder (digest set before the allocation) or the previous context copy (digest kept when its allocation fails).All other libSceLibreSsl and libSceLibreSsl3 tests on
mainpassed:guest_libressl_digest,guest_libressl_des,guest_libressl_x509_errors,guest_libressl_runtime,guest_libressl_aes,guest_libressl_asn1,guest_libressl_asn1_allocator,guest_libressl_ex_data,guest_libressl_error,guest_libressl_ocsp,guest_libressl_stack,guest_libressl_ui,guest_libressl_rsa,guest_libressl_x509_store,guest_libressl_x509_store_allocator,guest_libressl_x509_store_context,guest_libressl_x509_lookup,guest_libressl_x509_lookup_allocator,guest_libressl_x509_verify_param,guest_libressl_x509_verify_param_allocator,guest_libressl_pkey_type,guest_libressl_cipher,guest_libressl_alert,guest_libressl_version,guest_libressl_crypto_locks,guest_libressl_object_text,guest_libressl_object_allocation,guest_libressl_protocol,guest_libressl_protocol_nid,guest_libressl3_digest,guest_libressl3_digest_context,guest_libressl3_asn1,guest_libressl3_cipher,guest_libressl3_key_reference,guest_libressl3_stack,guest_libressl3_x509_verify_paramandguest_crypto_memcmp(39/39 together withguest_libressl_evpandpatched_libraries). Their sources include the changedinclude/Api.hpp. The opt-inguest_libressl_oracle(ANYPS5_LIBRESSL_ORACLE) was not enabled; it compares the AES, digest, DES parity and error-string exports, not these functions.patched_libraries: passed.libSceLibreSsl.prxexports the same 394_nid_postfixnames as onmain.python3 tools/check_conventions.py --base upstream/main: passed.The mutants above (
block <= len, the SHA-256 flags, theEVP_DigestInit_exorder and theHMAC_Init_excontext copy) were rerun on 4a465be and each makesguest_libressl_evpfail.MinGW-w64 13.2 (
x86_64-w64-mingw32-g++-posix -std=gnu++20 -fsyntax-onlywith the UCRT defines) compiles every libSceLibreSsl and libSceLibreSsl3 source and LibreSSL test except the opt-in oracle test on 4a465be without errors.Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 (
x86_64-ucrt-posix-seh, r7, the toolchain of the CI Windows job), CMake 4.3.1, Ninja 1.13.2, Release,BUILD_TESTING=ON, configured as in CI (cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, submodules withgit submodule update --init --recursive --depth 1):On b2583e3 (2026-10-25):
libSceLibreSsl,libSceLibreSsl3, the LibreSSL test executables,guest_crypto_memcmp_testsandpatched_libraries_testsbuilt with no warning in any libSceLibreSsl file;Evp.cpp,Export.cppandGuestLibreSslEvp.cppalso compile without warnings with-Wall -Wextra.tools/check_test_registration.pypassed. The same 14 tests as on Linux passed. The unpatchedlibSceLibreSsl.prxexports the same 394_nid_postfixnames as the Linux build, including the 20, andguest_libressl_evp_tests.exeimports exactly these 20 from it. With a key of exactly the block size hashed (block <= len),guest_libressl_evpfails on Windows as well.Earlier rounds:
guest_libressl_evpand the digest tests passed on f6b83d9 and 81733ad.Not rerun on Windows since b2583e3. Since then the rebases (onto c7b4878, 750cf6c, 04fefeb, 3679074, 409fe64, d4de594 and 0836dfd) only changed the conflicting lines next to
main's new code inCMakeLists.txt,include/Api.hpp,Export.cpp(stubs next tomain'sOBJ_cleanupandOBJ_createchanges) and the debt file, plus the debt entry's wording aboutRSA_signandRSA_verify; the third review only prepended the licence comment toEvp.cppand removed five assertions fromGuestLibreSslEvp.cpp; the code in both is otherwise the same as on b2583e3. The MinGW-w64 syntax check above is the only Windows-toolchain check on 4a465be.Not tested: any title or homebrew (no title using libSceLibreSsl is known).
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)src/Evp.cppexists and usesEvpMdandEvpMdContext)Duplicate and overlap check
main0836dfd and all 1694 open pull requests (heads fetched on 2026-10-31, 20:31 UTC). No other open PR adds, changes or removes any of the 20 functions: the diffs of all open PRs were searched for theEVP_md5/sha256/sha384/sha512,EVP_MD_size,EVP_MD_CTX_*,EVP_Digest*andHMAC*names and forEvpMd,EvpMdContext,HmacContextandHmacMaxBlock. Onmain, the digest, DES, X509 error string, RAND/CRYPTO, AES, error queue, OCSP string, cipher, ASN.1, CRYPTO locking, version, TLS alert, stack, UI_METHOD, RSA, X509_STORE_CTX, EVP_PKEY_type, ex_data, object text, protocol selection, X509_STORE, X509_LOOKUP, X509_VERIFY_PARAM, B250-2 and OBJ_create work, the LibreSSL oracle test and the libSceLibreSsl3 forwarding, stack, cipher, digest-context and X509_VERIFY_PARAM work changed libSceLibreSsl since its export stubs were added; none of it touches these functions. libSceLibreSsl3 now forwards its copies of these exports to libSceLibreSsl by name, and its tests pass on this head.add_librarysource list and test block ofCMakeLists.txt, the declarations afterLibreSslX509StoreContextininclude/Api.hppand the debt count and neighbouring entries. Agreed order with its author: this PR lands first, feat(libSceLibreSsl): implement EC groups and keys for named curves #10395 records Depends on: feat(libSceLibreSsl): implement the EVP message digest and HMAC functions #9448 and rebases after it. Both heads merged locally with both sides kept (Evp.cppthenEc.cpp, both test blocks, both declaration blocks, count 263 = the stubs left) pass all 40 LibreSSL tests incl.guest_libressl_evpandguest_libressl_ecandcheck_conventions.pyon Linux.EvpMdandEvpMdContextfrom this PR and builds its mixed libSceLibreSsl/libSceLibreSsl3 test only whensrc/Evp.cppexists. Its current head conflicts withmainon its own; on its merge with b55c473 (an earlier head with the same code)guest_libressl3_evp,guest_libressl3_mixed_evpand the other libSceLibreSsl3 tests passed.main. 66 other open PRs change libSceLibreSsl or libSceLibreSsl3: 15 already conflict withmain(among them feat(libSceLibreSsl): implement the BN_ BIGNUM, BN_CTX, conversion, word, BN_mul and BN_mod_inverse functions #9446 and feat(libSceLibreSsl3): implement EVP digest contexts and SHA methods #10960) and 14 merge cleanly with this branch. The other 37 (among them feat(libSceLibreSsl): implement EC groups and keys for named curves #10395 and feat(libSceLibreSsl): implement the EVP cipher calls on the cipher context #10834) merge withmainbut conflict with this branch, nearly all in the debt count or neighbouring entries and most also in theCMakeLists.txtregistration lines or the declarations ininclude/Api.hpp; feat(libSceLibreSsl): implement the EVP cipher calls on the cipher context #10834, feat(libSceLibreSsl): implement EVP_PKEY_set1_RSA, EVP_PKEY_get1_RSA and EVP_PKEY_copy_parameters #11128, feat(libSceLibreSsl): implement SSL_CTX_set_alpn_protos and SSL_CTX_set1_groups_list #11176 and feat(libSceLibreSsl): free GENERAL_NAME and GENERAL_NAMES allocations #13760 also conflict inExport.cppnext to the stubs removed here. None of them implements one of the 20 (feat(libSceLibreSsl3): name 116 unknown additional exports from their NIDs #13831 only namesPKCS5_PBKDF2_HMACin libSceLibreSsl3); as the LibreSSL PRs do with each other, whichever merges later needs a small rebase.