-
Notifications
You must be signed in to change notification settings - Fork 8k
Optimize hash_pbkdf2() by reusing HMAC contexts #21175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
TimWolla
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is security-sensitive code: Can you please split the individual optimizations into separate commits for ease of review?
- Migration from float to integer operations to calculate the digest lengths.
- HMAC context reuse
- SHA-256 special case
- CommonCrypto SHA-256 special case
- Possibly other individually useful migration steps that I missed
|
Follow-up with exact commit references for easier navigation:
And |
daa2d0f to
1e94d0b
Compare
TimWolla
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for splitting the commits. Some more superficial review. I'll need to take a deeper look at the logic when it isn't almost midnight.
Fixes #9604.
Optimize
hash_pbkdf2()inext/hashby reusing precomputed HMAC contexts instead of rehashing key blocks each round.Changes
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)hrtime(true), median reportedObserved on this machine:
135.47 msmedian28.28 msmedian-of-12 (sample medians27.68–28.46 ms)~4.79x