Skip to content

php-in-php: hash_equals/hash_hmac_algos PHP LLVM (#7189 phase 1) - #7480

Merged
PurHur merged 1 commit into
masterfrom
agent/runtime-php-hash-crypto-7189
Jun 7, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/runtime-php-hash-crypto-7189

Conversation

@PurHur

@PurHur PurHur commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

Phase 1 of #7189 — migrate __compiler_hash_equals and __compiler_hash_hmac_algos from hand-written C to PHPLLVM emitters (StringHashEquals.php, StringHashHmacAlgos.php). Digest bodies (__compiler_hash*, PBKDF2) remain in hash_crypto_jit_runtime.c for a follow-up VmHashNative IR port.

C runtime shrink: 38 lines removed from lib/JIT/Builtin/hash_crypto_jit_runtime.c (800 → 762).

PHP path

Symbol PHP implementation
__compiler_hash_equals lib/JIT/Builtin/StringHashEquals.php (mirrors VmHash::equals())
__compiler_hash_hmac_algos lib/JIT/Builtin/StringHashHmacAlgos.php (mirrors VmHash::hmacAlgos())

Wired from StringHashCryptoJit::implement() before MCJIT bitcode link.

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && cd /compiler
vendor/bin/phpunit test/unit/JIT/StringHashCryptoRuntimeStandaloneTest.php
vendor/bin/phpunit test/unit/HashEqualsBuiltinTest.php
vendor/bin/phpunit test/compliance/JITTest.php --filter "hash_equals|hash_hmac"
php bin/jit.php -r "var_export(hash_equals(\"abc\", \"abc\")); echo PHP_EOL; var_export(count(hash_hmac_algos())); echo PHP_EOL; echo hash(\"sha256\", \"x\"), PHP_EOL;"'

Output:

OK (1 test, 13 assertions)
OK (2 tests, 5 assertions)
OK (4 tests, 4 assertions)
true
3
2d711642b726b04401627ca9fbac32f5c8530fb1903cc4db02258717921a4881

Follow-up (#7189 phase 2)

Port sha256/sha1/md5/HMAC/PBKDF2 digest loops from VmHashNative.php into StringHashCryptoNativeJit.php PHPLLVM Builder emission (~762 C lines remaining), then delete hash_crypto_jit_runtime.c from Linker.

Part of #7189 — does not close the issue.

Made with Cursor

…phase 1)

Move timing-safe compare and HMAC algo list off hash_crypto_jit_runtime.c
into StringHashEquals and StringHashHmacAlgos PHPLLVM emitters; digest
functions remain in C pending full VmHashNative IR port.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant