Skip to content

php-in-php: hash_pbkdf2() — native VmHash path without host \\hash_pbkdf2() (ext/hash/hash_pbkdf2.c, bootstrap) #6186

Closed

Description

@PurHur

Category

php-in-php / bootstrap

Problem

hash_pbkdf2() VM implementation delegates to host Zend \hash_pbkdf2() (ext/standard/VmHash.php line 35). That blocks self-host/AOT paths where host ext/hash is absent and violates PHP-in-PHP: PBKDF2 semantics belong in ext/ + existing VmHashNative FFI, not permanent host delegation.

Enum-case operand TypeError parity is tracked separately (#5972); this issue is the native implementation + host delegation removal.

php-src reference

  • ext/hash/hash_pbkdf2.c — PHP_FUNCTION(hash_pbkdf2) HMAC-based PBKDF2
  • ext/hash/php_hash.h — algorithm dispatch

Repro (bootstrap)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
grep -n "hash_pbkdf2" ext/standard/VmHash.php
php bin/vm.php -r "echo hash_pbkdf2(\"sha256\", \"pass\", \"salt\", 1, 8);\n";"
'

Today VmHash::hashPbkdf2() contains return \hash_pbkdf2(...).

Scope (this repo)

  • Implement PBKDF2 in ext/standard/VmHashNative.php (or sibling) using existing OpenSSL/libsodium FFI patterns from VmHashNative
  • Wire ext/standard/hash_pbkdf2.php VM path to native helper
  • JIT/AOT: lower through VmHashNative / delete any C-only shortcut tables
  • Delete host \hash_pbkdf2() call from VmHash.php
  • Lines removed from C: none expected (no new runtime/*.c); shrink host dependency surface

Done when

  • hash_pbkdf2('sha256', 'pass', 'salt', 1, 8) returns deterministic digest matching Zend on VM
  • No \hash_pbkdf2( host calls remain under ext/standard/VmHash.php
  • test/compliance/cases/stdlib/hash_pbkdf2_basic.phpt green on VM
  • JIT/AOT smoke when lowering lands (script/capability-matrix.php notes updated)
  • make bootstrap-inventory-check still green (ext/hash on spine path)

Related: #5972 (enum operands), #4790 / #5989 (VmHashNative / hash_crypto.c deletion), #3773 (original parity).

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 5, 2026
  2. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#6186: native hash_pbkdf2 in VmHashNative, remove host \hash_pbkdf2() delegation from VmHash.php).

  3. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    Merged via PR #7550.

    What changed

    • VmHashNative::hashPbkdf2() + pbkdf2F() — native PBKDF2 via existing HMAC digests (php-src ext/hash/hash_pbkdf2.c)
    • VmHash::hashPbkdf2() no longer calls host \hash_pbkdf2()
    • JIT hex truncation aligned with php-src when explicit $length is passed

    Verification
    ```bash
    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php bin/vm.php -r "echo hash_pbkdf2("sha256", "pass", "salt", 1, 8);"
    php bin/jit.php -r "echo hash_pbkdf2("sha256", "pass", "salt", 1, 8);"
    ./vendor/bin/phpunit --filter "hash_pbkdf2|VmHashNativeTest"
    '
    ```
    VM + JIT repro → 65acafe9655d154e; compliance PHPTs + unit tests green (14/15; AOT fixture still hits pre-existing compile segfault exit 139).

    C runtime: 0 lines added; host ext/hash VM delegation removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions