P.S. Thanks to Sjoerd for honoring my request to delay his bcrypt-sha256 proposal while I finished this.
Cheers,
Andrey.
Hi Andrey,
I'm rather against it. Your proposed implementation decreases security
of bcrypt implementation for small and dubious gains. The input space
is decreased from 2^576 to 2^432, which is a magnitude of 2^144. Sure,
these are astronomical values, but it's a significant decrease
nonetheless.
Additionally, your implementation suffers from hash shucking. OWASP
explicitly warns about doing it the way you are doing it:
Just using pure SHA-512, ( i.e. bcrypt(base64(sha512($password))), $salt, $cost)) is a dangerous practice and is as secure as just using pure SHA-512.
You mention HMAC, but it's a bit vague and looking at the
implementation, I believe you use the public salt as a secret key.
This may obfuscate the hash, but as I understand it, it does not make
pre-hashing safe. In fact the blog which I assume you have looked at
before (Beyond Bcrypt - Dhole Moments) describes the
problems in detail:
You can avoid hash shucking by using HMAC with a static key–either universal for all deployments of your software, or unique per application.
It doesn’t really matter which you choose; all you really need from it is domain separation from naked hashes.
So what do we gain instead? Your RFC does not clearly state the
benefits we gain at the cost of reduced security.
I’m rather against it. Your proposed implementation decreases security
of bcrypt implementation for small and dubious gains. The input space
is decreased from 2^576 to 2^432, which is a magnitude of 2^144. Sure,
these are astronomical values, but it’s a significant decrease
nonetheless.
Sorry, but this is complete nonsense. A prehash doesn’t reduce Bcrypt’s security or input space, and the “dubious gains” are masking all of Bcrypt’s limitations on inputs.
Additionally, your implementation suffers from hash shucking. OWASP
explicitly warns about doing it the way you are doing it:
You mention HMAC, but it’s a bit vague and looking at the
implementation, I believe you use the public salt as a secret key.
This may obfuscate the hash, but as I understand it, it does not make
pre-hashing safe. In fact the blog which I assume you have looked at
before (https://soatok.blog/2024/11/27/beyond-bcrypt/) describes the
problems in detail:
You can avoid hash shucking by using HMAC with a static key–either universal for all deployments of your software, or unique per application.
It doesn’t really matter which you choose; all you really need from it is domain separation from naked hashes.
I’m happy to correct vagueness, especially if you can point to the unclear piece of text. However, you are wrong on multiple counts here, and the answer as to why is in those exact last words in the quote: domain separation from naked hashes.
Not only is there domain separation from naked hashes, there’s domain separation between the Bcrypt and prehash salts (and even further than that).
And while I have indeed read Soatok’s blog, the insinuation that it’s the basis of my work is both rude and false. I’d be more than familiar with password shucking with or without it, which is why I can tell you what he meant there by suggesting a static key: even a static key is good enough, not only a static key.
The salt being used that way adds more strength (which some would call overkill), not less. It being public has no effect on the purpose it serves either.
So what do we gain instead? Your RFC does not clearly state the
benefits we gain at the cost of reduced security.
Perhaps it was foolish of me to think that listing Bcrypt’s well-known issues in the very first sentence of the RFC introduction is enough to suggest that they’d be fixed. Maybe I could be more explicit about it, and maybe you could not so aggressively strawman too. Just to be crystal clear: there is no reduced security.
Thank you for the RFC and entertaining my questions in Discord. As promised, I want to put the points onto the list for public record:
- Can you please add a (pseudo) code description of your construction to the RFC? Prose is needlessly ambiguous as also evidenced by Kamil’s misunderstanding.
- The section on “bcrypt-sha256” is very vague in how your construction is better. Given that both bcrypt-sha256 and your bcrypt-wrap (with SHA-512) use a HMAC construction using the (BCrypt) salt as a key as the pre-hash, folks will rightfully wonder how the bcrypt-wrap construction is better than that of bcrypt-sha256 (other than using a different hash function) and should not be required to “reverse engineer” the differences.
On 29 October 2026 23:29:14 GMT, Andrey Andreev <narf@devilix.net> wrote:
I'm happy to correct vagueness, especially if you can point to the unclear
piece of text. However, you are wrong on multiple counts here, and the
answer as to why is in those exact last words in the quote: domain
separation from naked hashes.
Not only is there domain separation from naked hashes, there's domain
separation between the Bcrypt and prehash salts (and even further than
that).
Perhaps it would be useful to add to the RFC a non-technical explanation of how hash shucking works, and how adding salt or pepper at the right stage protects against it.
Supports two prehash primitives, chosen through a prehash option: cshake256 (default) and sha512 (using HMAC construct).
PASSWORD_BCRYPT_WRAP supports two prehash algorithms. The prehash can be supplied in a hash option. Another possible solution is to create two password_hash algorithms, e.g. PASSWORD_BCRYPT_CSHAKE and PASSWORD_BCRYPT_SHA512.
On Fri, Oct 30, 2026, at 09:36, Tim Düsterhus wrote:
The section on “bcrypt-sha256” is very vague in how your construction
is better. Given that both bcrypt-sha256 and your bcrypt-wrap (with
SHA-512) use a HMAC construction using the (BCrypt) salt as a key as the
pre-hash, folks will rightfully wonder how the bcrypt-wrap construction
is better than that of bcrypt-sha256 (other than using a different hash
function) and should not be required to “reverse engineer” the
differences.
Recently two new password hashes were proposed, both with the goal of solving bcrypt’s 72-byte limit and failure to handle null-bytes:
Both prehash the password before passing them to bcrypt.
BCRYPT_SHA256 uses the same algorithm as Python’s passlib. That provides interoperability with that library. It also means we cannot deviate from that algorithm without giving up that interoperability.
BCRYPT_SHA256 is simpler and adds less code to PHP.
BCRYPT_WRAP supports two prehashing algorithms.
Both use the salt as the key, but in a technically different way. BCRYPT_WRAP decodes the base64-encoded salt, BCRYPT_SHA256 normalizes the text version of the salt.
The text representation of the hash differs: BCRYPT_WRAP follows the PHC string format and is slightly longer than BCRYPT_SHA256.
I think both RFC with all three proposed prehashing methods are sufficiently secure. For security I see no reason to prefer one over the other.
Adding one new algorithm would be sufficient. Cryptographic agility within the hashing algorithm is not necesssary; users can move to another hashing algorithm such as Argon2. Both hash formats have a version field, making it possible to make backwards compatible changes.
It is unfortunate that we now have two RFCs that are so similar. Voting on them in isolation could result in an undesirable outcome.
It is unfortunate that we now have two RFCs that are so similar. Voting on them in isolation could result in an undesirable outcome.
I’d say that there’s a significant difference, but I’m not particularly happy about making it a contest either. I was already working on bcrypt-wrap as the bcrypt-sha256 suggestion appeared first on list and then as RFC within a few days.
It just turned out this way, hopefully we don’t have to look at it as mine against yours.
Bcrypt's 72-byte limit on passwords and issue with null bytes are
inviting many userspace workarounds, poor tradeoffs, security
vulnerabilities, UX issues, and considerable toil for developers.
Multiple attempts to solve these problems have so far failed:
Why not introduce a PASSWORD_BCRYPT_STRICT variant? Which:
- asserts the password is valid utf-8.
- asserts the password does not contain any ASCII-control-character
between 0 upto and including 31.
- asserts the password does not contain the ASCII-control-character
127.
- asserts there are no unicode control characters present. Such as,
but not limited to, U+202E Right-to-Left Override, U+2066
Left-to-Right Isolate, U+2069 Pop Directional Isolate, U+2060 Word
Joiner, U+00A0 ( ) No-Break-Space, U+FEFF Byte Order Mark.
- asserts the byte-length of the password is maximum 72 bytes.
- (might) asserts the minimum byte-length of the password is 8 bytes.
- claims the '$2z$' identifier. And leaves the '$2y$' identifier
alone.
- Explicitly does not change the PASSWORD_DEFAULT constant.
- Let PASSWORD_BCRYPT (and therefore also PASSWORD_DEFAULT) generate
deprecation warnings.
- And remove the PASSWORD_DEFAULT constant after at least 5 Php
versions. The PASSWORD_DEFAULT has no meaning, it should never been
there. Explicit selection of the algorithm is better.
=========
Comment 2
Why is the password not validated to be human typable? Repeating
comment 1:
- asserts the password is valid utf-8.
- asserts the password does not contain any ASCII-control-character
between 0 upto and including 31.
- asserts the password does not contain the ASCII-control-character
127.
- asserts there are no unicode control characters present. Such as,
but not limited to, U+202E Right-to-Left Override, U+2066
Left-to-Right Isolate, U+2069 Pop Directional Isolate, U+2060 Word
Joiner, U+00A0 ( ) No-Break-Space, U+FEFF Byte Order Mark.
=========
Comment 3
The RFC states:
There is (not PHP-specific) consensus that a wrapping,
prehashed-bcrypt construct is the solution (see FAQ), but no
particular choice for the prehash primitive has emerged as the de
facto standard.
Where is the prehashed-bcrypt consensus listed? Who consented? Did
the original Bcrypt author consent? Did OpenBsd, the owner of the
Bcrypt hashing algorithm, consent?
The Bcrypt specification can be found at:
=========
Comment 4
Why is bcrypt-password-prehashing needed if Php also supports
PASSWORD_ARGON2I and PASSWORD_ARGON2ID out of the box?
This goes against OWASP recommendations, see
The bcrypt password hashing function should only be used for
password storage in legacy systems where Argon2 and scrypt are not
available.
=========
Comment 5
The RFC states:
Supports two prehash primitives, chosen through a prehash option:
cshake256 (default) and sha512 (using HMAC construct).
Where is cshake256 defined? I did find SHAKE256 at
But a *c*SHAKE256 is nowhere found?
=========
Comment 6
The hmac-sha512 goes against OWASP recommendations, see
To summarize if bcrypt has to be used and the password should to be
pre-hashed you should do
bcrypt(base64(hmac-sha384(data:$password, key:$pepper)), $salt, $cost)
and store the pepper not in the database.
The RFC states:
HMAC-SHA512 output is truncated (yes, this is perfectly fine). The
salt is part of the key.
... and ...
prehash_salt = "bcrypt-wrap:" || version || ":" || salt_raw
The prehash_salt used in this RFC, is what OWASP calls pepper. The
prehash_salt is derived from the salt, and thus stored in the
database. Against OWASP recommendations.
Why is hmac-sha512 being proposed, if that goes *against OWASP*
recommendations?
=========
Comment 7
The RFC states:
Whichever prehash function is chosen, 54 bytes of binary output are
B64-encoded to fill the 72-byte space allowed by Bcrypt.
Why is bcrypt-prehashing needed below 73 password-bytes? Bcrypt can
handle 72 bytes just fine.
Also 54 binary output bytes of the prehash-function, would truncate
the password space to 54 bytes. More than 54 password-bytes is going
to introduce hash-collisions. Assuming the prehash function has no
collisions within the 54 byte range.
The Bcrypt algorithm truncates the password space beginning at 73
password-bytes to 72 bytes. So even the flawed Bcrypt algorithm is
superior to this invented algorithm.
Why is something being proposed, that deteriorates security?
=========
Comment 8
The RFC has no test-vectors. A re-implementation in e.g. C# can never
validate its correctness. Please add test-vectors. Also include
vectors that include smileys and other utf-8 symbols. Not just the
ASCII range.
=================
End of comments
When the cSHAKE256 algorithm is known, I will post more comments.
Sorry that I won’t be quoting your entire email, as it is too long.
I will quote-reply to the small bits where a misunderstanding is reasonably possible.
To your comments 1 & 2:
Because none of that would fly and I don’t agree with it. You’re free to bring up your suggestions as a separate proposal and see how it goes.
Because that would violate modern standards like NIST SP 800-63B-4 and OWASP ASVS 5 require supporting a length of 64 characters; Bcrypts limit is 72 bytes.
Why is bcrypt-password-prehashing needed if Php also supports
PASSWORD_ARGON2I and PASSWORD_ARGON2ID out of the box?
Because Argon2 is not actually supported out of the box, due to its external dependencies. This is already mentioned in the RFC Introduction, though perhaps easy to miss; I’ll try to remember adding it to the FAQ.
HMAC-SHA512 output is truncated (yes, this is perfectly fine). The
salt is part of the key.
… and …
prehash_salt = “bcrypt-wrap:” || version || “:” || salt_raw
The prehash_salt used in this RFC, is what OWASP calls pepper. The
prehash_salt is derived from the salt, and thus stored in the
database. Against OWASP recommendations.
The RFC has no test-vectors. A re-implementation in e.g. C# can never
validate its correctness. Please add test-vectors. Also include
vectors that include smileys and other utf-8 symbols. Not just the
ASCII range.
At this stage, this is a PHP RFC that may undergo changes, and may or may not gather enough support.
I’d be happy to work on a more formal specification at a later stage, but for the time being - the implementation PR is fully functional and includes many tests: https://github.com/php/php-src/pull/25040
The rest of your questions are already thoroughly and very explicitly answered in the RFC FAQ.
Why is the password not validated to be human typable? Repeating
comment 1:
- asserts the password is valid utf-8.
- asserts the password does not contain any ASCII-control-character
between 0 upto and including 31.
- asserts the password does not contain the ASCII-control-character
127.
- asserts there are no unicode control characters present. Such as,
but not limited to, U+202E Right-to-Left Override, U+2066
Left-to-Right Isolate, U+2069 Pop Directional Isolate, U+2060 Word
Joiner, U+00A0 ( ) No-Break-Space, U+FEFF Byte Order Mark.
(Andrey Andreev)
- Because that would violate modern standards like NIST SP 800-63B-4
and OWASP ASVS 5 require supporting a length of 64 characters;
Bcrypts limit is 72 *bytes*.
(Mirco Babin)
My question is misunderstood. Why does BCRYPT_WRAP not have a very
first step 0 that validates that *password* is human typable, valid
utf-8 and does not contain control characters? Password is input for
the prehash-function, so there is no 72 byte limit.
=========
Comment 4
(Mirco Babin)
Why is bcrypt-password-prehashing needed if Php also supports
PASSWORD_ARGON2I and PASSWORD_ARGON2ID out of the box?
(Andrey Andreev)
Because Argon2 is not actually supported out of the box, due to its
external dependencies. This is already mentioned in the RFC
Introduction, though perhaps easy to miss; I'll try to remember
adding it to the FAQ.
(Mirco Babin)
Why isn't this bugfixed then. So PASSWORD_ARGON2ID will become
available out of the box?
(Mirco Babin)
Thanks for the link. Why is PBKDF2-HMAC-SHA512 not used? The PBKDF2
algorithm is much more available in other languages, and enhances
interoperability. E.g. I could not find a cSHAKE256 implementation
for C#. While PBKDF2 is available out of the c# box see:
When a C# and PHP application share a database, with cSHAKE256 it
becomes difficult to seed an initial password from the C# application
into the shared PHP database.
=========
Comment 7
The RFC states:
Whichever prehash function is chosen, 54 bytes of binary output are
B64-encoded to fill the 72-byte space allowed by Bcrypt.
(Mirco Babin)
Why is bcrypt-prehashing needed below 73 password-bytes? Bcrypt can
handle 72 bytes just fine.
Also 54 binary output bytes of the prehash-function, would truncate
the password space to 54 bytes. More than 54 password-bytes is going
to introduce hash-collisions. Assuming the prehash function has no
collisions within the 54 byte range.
The Bcrypt algorithm truncates the password space beginning at 73
password-bytes to 72 bytes. So even the flawed Bcrypt algorithm is
superior to this invented algorithm.
Why is something being proposed, that deteriorates security?
(Mirco Babin)
This is not answered. Also using base64 for not having a 0-byte as
input for Bcrypt can be improved. Because this RFC *is* an invented
algorithm why not use Consistent Overhead Byte Stuffing (COBS)? That
would make the pre-hash function output 71 bytes, and COBS would
exactly add 1 byte and remove all 0-bytes from it. That 72 bytes,
not containing any 0-byte. would then be the
"password"-input for Bcrypt.
This would also eliminate the prehash HMAC-SHA512, because that
outputs 64 bytes, which is below 71 bytes.
=========
Comment 8
(Mirco Babin)
The RFC has no test-vectors. A re-implementation in e.g. C# can never
validate its correctness. Please add test-vectors. Also include
vectors that include smileys and other utf-8 symbols. Not just the
ASCII range.
(Mirco Babin)
The RFC as is still has no smileys in any example. Please add smileys
into the example in the Proposal section. Like:
$password = "A really, really long password, that's over 72 bytes
and also includes a nice smiley face ";
Also it is unwanted that $password contains a 0-byte. It is not human
typable, does not make any sense. It should not be allowed.
My question is misunderstood. Why does BCRYPT_WRAP not have a very
first step 0 that validates that*password* is human typable, valid
utf-8 and does not contain control characters?
Why would it? Is there some security or usability standard you can point to that suggests that password input be limited in this way?
Why isn't this bugfixed then. So PASSWORD_ARGON2ID will become
available out of the box?
It is not a "bug" to be "fixed"; it is a decision about what libraries are included in the source tree of PHP, and which are left as optional dependencies.
PHP can have Argon2 support via one of three external libraries: libargon2, libsodium, or openssl. Making it available in all builds means including a copy of one of those libraries directly in the source tree.
Also 54 binary output bytes of the prehash-function, would truncate
the password space to 54 bytes. More than 54 password-bytes is going
to introduce hash-collisions. Assuming the prehash function has no
collisions within the 54 byte range.
The Bcrypt algorithm truncates the password space beginning at 73
password-bytes to 72 bytes. So even the flawed Bcrypt algorithm is
superior to this invented algorithm.
This is a completely nonsensical comparison.
A standard bcrypt output contains 23 bytes of final hash data; that's "only" 2.5 x 10^55 possible outputs. A 54-byte pre-hash has 1.1 x 10^130 possible values.
(Additional comparison: the standard Argon2id output contains 32 bytes of final hash data, for 1.2 x 10^77 possible outputs.)
Why is the password not validated to be human typable? Repeating
comment 1:
asserts the password is valid utf-8.
asserts the password does not contain any ASCII-control-character
between 0 upto and including 31.
asserts the password does not contain the ASCII-control-character
asserts there are no unicode control characters present. Such as,
but not limited to, U+202E Right-to-Left Override, U+2066
Left-to-Right Isolate, U+2069 Pop Directional Isolate, U+2060 Word
Joiner, U+00A0 ( ) No-Break-Space, U+FEFF Byte Order Mark.
(Andrey Andreev)
Because that would violate modern standards like NIST SP 800-63B-4
and OWASP ASVS 5 require supporting a length of 64 characters;
Bcrypts limit is 72 bytes.
(Mirco Babin)
My question is misunderstood. Why does BCRYPT_WRAP not have a very
first step 0 that validates that password is human typable, valid
utf-8 and does not contain control characters? Password is input for
the prehash-function, so there is no 72 byte limit.
Your question was not misunderstood. Here’s my actual reply verbatim:
On Thu, Nov 5, 2026 at 8:13 PM Andrey Andreev <narf@devilix.net> wrote:
To your comments 1 & 2:
Because none of that would fly and I don’t agree with it. You’re free to bring up your suggestions as a separate proposal and see how it goes.
Because that would violate modern standards like NIST SP 800-63B-4 and OWASP ASVS 5 require supporting a length of 64 characters; Bcrypts limit is 72 bytes.
That was not meant as “1 & 2 respectively”, but as a general response to both your comments, since both talked about character validation with the strong implication of “character-validated Bcrypt” instead. These two things have a large overlap, especially as you mention Unicode characters, so I am treating them as a package. Let me rephrase more clearly:
I am against any character type validation and Bcrypt itself has issues related to character types.
When a C# and PHP application share a database, with cSHAKE256 it
becomes difficult to seed an initial password from the C# application
into the shared PHP database.
You can use PBKDF2 if you want – it’s already in ext/hash – but I’m not interested in it being a password_hash() option for a number of reasons:
It is neither memory-hard nor cache-hard. Argon2 won the PHC because it is memory-hard and NIST still favors that property, while cryptographers currently favor Bcrypt for being cache-hard. The only thing everyone agrees on is that PBKDF2 would be a downgrade.
It supports too many hash primitives, and its work factor (iterations) varies wildly both with each hash function and in how frequently it needs to be updated. Our current default Bcrypt cost of 12 is good for many years ahead, whereas we’d need to update PBKDF2 recommended settings all the time.
The previous point makes it very hard to maintain secure defaults both in terms of PHP support and as a broader recommendation. bcrypt-wrap is designed so that you can say “just use bcrypt-wrap” and not have to explain details.
As for C#'s lack of cSHAKE support - I’d recommend using BouncyCastle anyway; the .NET standard library support for modern crypto is notoriously bad.
(Mirco Babin)
Why is bcrypt-prehashing needed below 73 password-bytes? Bcrypt can
handle 72 bytes just fine.
Also 54 binary output bytes of the prehash-function, would truncate
the password space to 54 bytes. More than 54 password-bytes is going
to introduce hash-collisions. Assuming the prehash function has no
collisions within the 54 byte range.
The Bcrypt algorithm truncates the password space beginning at 73
password-bytes to 72 bytes. So even the flawed Bcrypt algorithm is
superior to this invented algorithm.
Why is something being proposed, that deteriorates security?
(Mirco Babin)
This is not answered. Also using base64 for not having a 0-byte as
input for Bcrypt can be improved. Because this RFC is an invented
algorithm why not use Consistent Overhead Byte Stuffing (COBS)? That
would make the pre-hash function output 71 bytes, and COBS would
exactly add 1 byte and remove all 0-bytes from it. That 72 bytes,
not containing any 0-byte. would then be the
“password”-input for Bcrypt.
As I said in my last reply, your remaining questions were already very directly answered in the RFC FAQ.
Not only was this not unanswered, it was the very first critique I received and there’s a full screen worth of text addressing it (even includes arguments against this new COBS suggestion): https://wiki.php.net/rfc/password_bcrypt_wrap#doesn_t_decreased_input_space_reduce_bcrypt_security
The RFC as is still has no smileys in any example. Please add smileys
into the example in the Proposal section. Like:
$password = “A really, really long password, that’s over 72 bytes
and also includes a nice smiley face ”;
Also it is unwanted that $password contains a 0-byte. It is not human
typable, does not make any sense. It should not be allowed.
If that’s what you want, stick to pure Bcrypt. I will not be adding smileys to the example at this time - it is already very obvious that there are no character limitations, and emoji are no more special than any multibyte character.