[php-src] PR #21175: Optimize hash_pbkdf2() by reusing HMAC contexts
| From: | gregharmon | Date: | Mon, 09 Feb 2026 03:12:48 +0000 |
| Subject: | [php-src] PR #21175: Optimize hash_pbkdf2() by reusing HMAC contexts | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-34864@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21175
Author: gregharmon
Fixes #9604.
Optimize
hash_pbkdf2() in ext/hash by reusing precomputed HMAC contexts
instead of rehashing key blocks each round.
## Changes
- Reuse precomputed HMAC inner/outer base contexts in PBKDF2 rounds.
- Add a copy-based HMAC round helper for the PBKDF2 path.
- Add SHA-256 PBKDF2 fast path + helper for fixed-size context-final rounds.
- Add regression vectors in ext/hash/tests/gh9604.phpt.
## Behavior
No API or semantic changes intended: validation, return formats, and output bytes are unchanged.
## Tests
- make test TESTS="ext/hash/tests/hash_pbkdf2_basic.phpt
ext/hash/tests/hash_pbkdf2_error.phpt ext/hash/tests/gh9604.phpt"
- make test TESTS="ext/hash/tests"
## Benchmark
Setup:
- hash_pbkdf2('sha256', 'password', 'salt', 200000, 64,
false)
- 9 timed runs/sample via hrtime(true), median reported
Observed on this machine:
- Before: 135.47 ms median
- After: 28.28 ms median-of-12 (sample medians 27.68–28.46 ms)
- Speedup: ~4.79x