Skip to content

ext/standard: bcrypt-sha256 password hash - #24073

Open
Sjord wants to merge 11 commits into
php:masterfrom
Sjord:bcrypt_sha256
Open

Sjord wants to merge 11 commits into
php:masterfrom
Sjord:bcrypt_sha256

Conversation

@Sjord

@Sjord Sjord commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

During the discussion on the 72-byte limit of bcrypt, Tim suggested implementing passlib's bcrypt-sha256. That does a HMAC of the password before passing it to bcrypt, solving the 72-byte limit and also the null-byte problem.

This implements bcrypt-sha256 as an algorithm to pass to password_hash / _verify.

RFC: https://wiki.php.net/rfc/bcrypt_sha256

Comment thread ext/standard/php_password.h Resolved
Comment thread ext/standard/password.c Resolved
@Sjord

Sjord commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Ping @TimWolla @narfbg. I vibe-coded bcrypt sha256 support for password_hash / _verify.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should likely be marked as slow.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see this is not resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mark it as slow, but I changed the test to be faster. This test now takes approximately 0.2 seconds on my system.

There's one testcase that needs testing and is slow: the default cost of 12. I moved that to password_bcrypt_sha256_hash_slow.phpt and added a SKIPIF SKIP_SLOW_TESTS to that.

Comment thread ext/standard/password.c Resolved
Comment thread ext/standard/password.c Resolved
Comment thread ext/standard/password.c Resolved
Comment thread ext/standard/password.c Resolved
Comment thread ext/standard/password.c Resolved
Comment thread ext/standard/password.c Resolved
@Sjord
Sjord marked this pull request as ready for review October 3, 2026 14:38
@Sjord
Sjord requested review from bukka and kocsismate as code owners October 3, 2026 14:38
@Sjord Sjord changed the title bcrypt_sha256 ext/standard: bcrypt-sha256 password hash Oct 3, 2026
Comment thread ext/hash/php_hash_sha.h Resolved
@TimWolla TimWolla added the RFC label Oct 5, 2026
@divinity76

divinity76 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What is the benefits of HMAC here? Sounds unnecessary complexity,
compared to something like bcrypt(hex(sha256(password)), salt)

@Sjord

Sjord commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

What is the benefits of HMAC here?

It is explained in this issue: https://foss.heptapod.net/python-libs/passlib/-/work_items/114

Basically, some other site breach may leak sha256(password), and those hashes can then be checked against bcrypt(sha256(password)). Doing HMAC with the salt prevents this.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants