Hi all,
I'd like to open the discussion on a new password hashing algorithm that I've been working on, named bcrypt-wrap.
RFC link: https://wiki.php.net/rfc/password_bcrypt_wrap Pull request: https://github.com/php/php-src/pull/25040 (just pushed it, CI still running)
P.S. Thanks to Sjoerd for honoring my request to delay his bcrypt-sha256 proposal while I finished this.
Cheers,
Andrey.
Quoted text · 6 lines
Hi all,
I'd like to open the discussion on a new password hashing algorithm that I've been working on, named bcrypt-wrap.
RFC link: https://wiki.php.net/rfc/password_bcrypt_wrap Pull request: https://github.com/php/php-src/pull/25040 (just pushed it, CI still running)
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. https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
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.
So what do we gain instead? Your RFC does not clearly state the benefits we gain at the cost of reduced security.
Regards,
Kamil Tekiela
Hi Kamil,
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:
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.
https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
That's not how I'm doing it. Not even close.
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.
Cheers,
Andrey.
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.
I attempted to do that in the previous discussion here, based on my own limited understanding: https://externals.io/message/132784#132850
Regards,
Hi Andrey,
Thanks for the carefully designed RFC. It seems like a useful addition.
Rowan Tommins
[IMSoP]
Hi
Quoted text · 4 lines
I'd like to open the discussion on a new password hashing algorithm that
I've been working on, named bcrypt-wrap.RFC link: https://wiki.php.net/rfc/password_bcrypt_wrap Pull request: https://github.com/php/php-src/pull/25040 (just pushed it, CI
still running)
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.
Best regards
Tim Düsterhus
- 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:
- PASSWORD_BCRYPT_WRAP https://wiki.php.net/rfc/password_bcrypt_wrap
- PASSWORD_BCRYPT_SHA256 https://wiki.php.net/rfc/bcrypt_sha256 (proposed by me)
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.
Regards,
Sjoerd Langkemper
Hi,
Thank you all for the feedback (on and off-list). I've updated the RFC and attempted to thoroughly address all of it, and also have a question:
For further disambiguation, would it help if prehash=sha512 was changed to prehash=hmacsha512 ? I'm increasingly leaning towards it.
On Sun, Nov 1, 2026 at 1:20 PM Sjoerd Langkemper sjoerd-php@linuxonly.nl wrote:
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.
Cheers,
Andrey.
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.
Regards,
Sjoerd Langkemper
Hello Andrey Andreev,
I'd like to open the discussion on a new password hashing algorithm that I've been working on, named bcrypt-wrap.
I have 8 comments.
=================
Begin of comments
=========
Comment 1
The RFC states:
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_DEFAULTconstant. - Let
PASSWORD_BCRYPT(and therefore also PASSWORD_DEFAULT) generate deprecation warnings. - And remove the
PASSWORD_DEFAULTconstant after at least 5 Php versions. ThePASSWORD_DEFAULThas 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: https://www.openbsd.org/papers/bcrypt-paper.pdf
=========
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 https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#bcrypt
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 https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf But a cSHAKE256 is nowhere found?
=========
Comment 6
The hmac-sha512 goes against OWASP recommendations, see https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pre-hashing-passwords-with-bcrypt
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.
Kind regards,
Mirco Babin
Hi Mirco,
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.
This goes against OWASP recommendations, see
https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#bcrypt
The bcrypt password hashing function should only be used for password storage in legacy systems where Argon2 and scrypt are not available.
OWASP recommends this because of Bcrypt's limitations, which bcrypt-wrap eliminates. This is also a point against your comments 1&2.
Where is cshake256 defined? I did find SHAKE256 at
https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf But a cSHAKE256 is nowhere found?
cSHAKE is defined by NIST SP800-185:
https://csrc.nist.gov/pubs/sp/800/185/final It is already linked by the RFC FAQ, though I probably could also add it to the references at the bottom:
https://wiki.php.net/rfc/password_bcrypt_wrap#what_even_is_cshake256_it_sounds_exotic
Quoted text · 5 lines
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_rawThe 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.
No, it's not a pepper by anyone's definition, precisely because it's not secret.
See also in the RFC FAQ:
https://wiki.php.net/rfc/password_bcrypt_wrap#why_no_pepper https://wiki.php.net/rfc/password_bcrypt_wrap#isn_t_this_vulnerable_to_shucking
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.
Cheers,
Andrey.
Hello Andrey Andreev,
=========
Comment 2
(Mirco Babin)
Quoted text · 6 lines
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.
=========
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?
=========
Comment 5
(Mirco Babin)
Where is cshake256 defined? I did find SHAKE256 at https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf But a cSHAKE256 is nowhere found?
(Andrey Andreev)
cSHAKE is defined by NIST SP800-185:
https://csrc.nist.gov/pubs/sp/800/185/final
(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: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.rfc2898derivebytes.pbkdf2
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)
Quoted text · 4 lines
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.
https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing https://github.com/firechip/cobs-conformance
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.
=================
End of comments
Kind regards,
Mirco Babin
Hi Mirco,
My question is misunderstood. Why does BCRYPT_WRAP not have a very first step 0 that validates thatpassword 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.)
Regards,
--
Rowan Tommins
[IMSoP]
Hello Rowan Tommins,
=========
Comment 2
(Mirco Babin)
My question is misunderstood. Why does BCRYPT_WRAP not have a very first step 0 that validates thatpassword is human typable, valid utf-8 and does not contain control characters?
(Rowan Tommins)
Why would it? Is there some security or usability standard you can point to that suggests that password input be limited in this way?
(Mirco Babin)
When a password can consist of bytes, it is no longer a password intended for human entry; instead, it functions more like an API key.
When the Bcrypt-2a revision was introduced, UTF-8 was apparently also made mandatory. However, I cannot find a primary source for this claim. A secondary source is:
https://javadoc.io/doc/at.favre.lib/bcrypt/latest/at/favre/lib/crypto/bcrypt/BCrypt.Version.html#VERSION_2A
=========
Comment 4
(Mirco Babin)
Why isn't this bugfixed then. So PASSWORD_ARGON2ID will become available out of the box?
(Rowan Tommins)
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.
So the decision can be made to make PASSWORD_ARGON2ID available everywhere. The decision of supporting a security standard versus introducing this non-standard self-invented-security-algorithm RFC that violates OWASP recommendations. I assume Php does not consider itself a LEGACY SYSTEM as OWASP calls it?
OWASP states:
https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#bcrypt
The bcrypt password hashing function should only be used for password storage in legacy systems where Argon2 and scrypt are not available.
============
Comment 7(b)
(Rowan Tommins)
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.
(Mirco Babin)
I'm going to provide an example. Consider a password being exactly 72 bytes, without 0x00-bytes.
The Bcrypt-plain scenario:
The input for the Bcrypt algorithm is exactly the 72-bytes-plain-password. There are 72*8 significant inputbits.
The Bcrypt-wrap scenario:
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.
The 72-bytes-plain-password is prehashed. The hash-function is of no importance, because Bcrypt-wrap states the prehash-ouput is always 54 bytes. Even though the 54 bytes are base64-encoded and expanded to 72 bytes, there are still only 548 significant inputbits after the base64-encoding. These 548 significant inputbits are input for Bcrypt.
Conclusion:
The bcrypt-plain is giving 728 significant inputbits to Bcrypt. The bcrypt-wrap-prehashed-password is giving 548 significant inputbits to Bcrypt. That is a deterioration of 18*8 bits, or 25%.
Kind regards,
Mirco Babin
Hi Mirco,
When a password can consist of bytes, it is no longer a password intended for human entry; instead, it functions more like an API key.
Whether you call it a "password" or a "secret" or whatever else, storing such values hashed seems reasonably useful. You could maybe argue that the "password_" prefix on the functions implies "human entry", and that the wrapper functions should always validate their input in some way;
that could be a separate proposal if you think it's justified, but it doesn't seem related to a single hashing algorithm.
When the Bcrypt-2a revision was introduced, UTF-8 was apparently also made mandatory. However, I cannot find a primary source for this claim. A secondary source is:
https://javadoc.io/doc/at.favre.lib/bcrypt/latest/at/favre/lib/crypto/bcrypt/BCrypt.Version.html#VERSION_2A
I've seen this in a few other places as well, but also haven't been able to find a primary source, and I'm not really clear what such a requirement means. In a language like Ruby where strings are tagged with an encoding, it might make sense to transparently normalise input to UTF-8. In a language like PHP where strings are untagged byte sequences, the most you can do is reject strings which are impossible in UTF-8, but can't prove that the string was intended as UTF-8.
Notably, "required to be UTF-8" does not place any restriction on which code points can be included in the string; so control characters including null bytes would still be accepted without some additional requirement.
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.
So the decision can be made to make PASSWORD_ARGON2ID available everywhere.
Yes, there is no law of physics which prevents it being made available in all builds. But there is a significant downside which means it is unlikely to happen in practice.
The bcrypt-plain is giving 728 significant inputbits to Bcrypt. The bcrypt-wrap-prehashed-password is giving 548 significant inputbits to Bcrypt. That is a deterioration of 18*8 bits, or 25%.
Is there a security property of the bcrypt algorithm that depends on this "significant inputbits" figure?
Certainly, it does not affect the number of possible outputs, because the output size is fixed at 23 bytes. If the algorithm is perfectly uniform, no two 23-byte inputs will produce the same output; but it is guaranteed by the Pigeonhole Principle that multiple inputs at any length larger than that will produce the same output.
In other words, both algorithms will reduce 2^576 possible 72-byte inputs to 2^184 possible 23-byte outputs; whether that reduction happens in one step, two, or more doesn't seem to have any mathematical significance.
Regards,
--
Rowan Tommins
[IMSoP]
Hello Rowan Tommins,
=========
Comment 2
(Mirco Babin)
When a password can consist of bytes, it is no longer a password intended for human entry; instead, it functions more like an API key.
(Rowan Tommins)
Whether you call it a "password" or a "secret" or whatever else, storing such values hashed seems reasonably useful. You could maybe argue that the "password_" prefix on the functions implies "human entry", and that the wrapper functions should always validate their input in some way; that could be a separate proposal if you think it's justified, but it doesn't seem related to a single hashing algorithm.
(Mirco Babin)
Bcrypt was clearly intended for "human entry" passwords. The abstract of the Bcrypt specification states it is about userchosen passwords. (BCrypt specification)
Many authentication schemes depend on secret passwords. Unfortunately the length and randomness of userchosen passwords remain fixed over time.
(Mirco Babin)
When the Bcrypt-2a revision was introduced, UTF-8 was apparently also made mandatory. However, I cannot find a primary source for this claim. A secondary source is:
https://javadoc.io/doc/at.favre.lib/bcrypt/latest/at/favre/lib/crypto/bcrypt/BCrypt.Version.html#VERSION_2A
(Rowan Tommins)
I've seen this in a few other places as well, but also haven't been able to find a primary source, and I'm not really clear what such a requirement means. In a language like Ruby where strings are tagged with an encoding, it might make sense to transparently normalise input to UTF-8. In a language like PHP where strings are untagged byte sequences, the most you can do is reject strings which are impossible in UTF-8, but can't prove that the string was intended as UTF-8.
(Mirco Babin)
If the contract of the function is that the $password parameter must be UTF-8, then that is the prove and the intention. All that is left then is the validation that it is utf-8.
(Rowan Tommins)
Notably, "required to be UTF-8" does not place any restriction on which code points can be included in the string; so control characters including null bytes would still be accepted without some additional requirement.
(Mirco Babin)
BCrypt already requires the absence of the 0x00 character.
=========
Comment 4
(Rowan Tommins)
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.
(Mirco Babin)
So the decision can be made to make PASSWORD_ARGON2ID available everywhere.
(Rowan Tommins)
Yes, there is no law of physics which prevents it being made available in all builds. But there is a significant downside which means it is unlikely to happen in practice.
(Mirco Babin)
The original RFC
https://wiki.php.net/rfc/argon2_password_hash_enhancements only states libargon2 as an implementation. On what platforms are Libsodium or Openssl used for PASSWORD_ARGON2ID?
Libargon2 looks not that big, see
https://github.com/P-H-C/phc-winner-argon2 ; I don't see any reason why this can not be embedded?
Also recently other libraries were incorporated in Php, e.g. 1)DOM HTML5 parsing and serialization
https://wiki.php.net/rfc/domdocument_html5_parser which embeds Lexbor https://github.com/lexbor/lexbor
2) Add RFC 3986 and WHATWG URL compliant API https://wiki.php.net/rfc/url_parsing_api which embeds Uriparser https://github.com/uriparser/uriparser/
3) The IR library at
https://github.com/dstogov/ir
It seems arbitrary to claim that libargon2 will not become part of PHP.
============
Comment 7(b)
(Mirco Babin)
The bcrypt-plain is giving 728 significant inputbits to Bcrypt. The bcrypt-wrap-prehashed-password is giving 548 significant inputbits to Bcrypt. That is a deterioration of 18*8 bits, or 25%.
(Rowan Tommins)
Is there a security property of the bcrypt algorithm that depends on this "significant inputbits" figure?
(Mirco Babin)
"significant inputbits" is my own term. I can rephrase that to: The bcrypt-plain is giving 2 ^ 72x8 bitcombinations to Bcrypt. The bcrypt-wrap-prehashed-password is giving 2 ^ 54x8 bitcombinations to Bcrypt. That is a deterioration of 2 ^ 18x8 bitcombinations, or 25%.
(Rowan Tommins)
Certainly, it does not affect the number of possible outputs, because the output size is fixed at 23 bytes. If the algorithm is perfectly uniform, no two 23-byte inputs will produce the same output; but it is guaranteed by the Pigeonhole Principle that multiple inputs at any length larger than that will produce the same output.
(Mirco Babin)
That is not fully correct. Bcrypt outputs a 24 bytes hash. That hash is encoded with Radix64 (or B64 as it is called in this RFC) to 32 Radix64-characters. Then the $2$ (or $2a$ or $2b$ or $2x$ or $2y$) modular crypt specification strips the last Radix64-character, giving only 31 Radix64-characters. Or 23 bytes and 2 leftover bits.
"If the algorithm is perfectly uniform" is going into assumptions with this non-standard self-invented-security-algorithm Bcrypt-Wrap. Security should not be an assumption, it should be a fact.
(Rowan Tommins)
In other words, both algorithms will reduce 2^576 possible 72-byte inputs to 2^184 possible 23-byte outputs; whether that reduction happens in one step, two, or more doesn't seem to have any mathematical significance.
(Mirco Babin)
"doesn't seem to have any mathematical significance" is another assumption with this non-standard self-invented-security-algorithm Bcrypt-Wrap. Security should not be an assumption, it should be a fact.
And what about side-channel effects, like timing or others? More assumptions will be raised etc. etc. etc. Self-designing and/or self-justifying a non-standard self-invented-security-algorithm is not the way to go for Php.
============
Conclusion
Php should provide standard security. Any derivative of the original Bcrypt revision 2a algorithm is self-invented, non-standard and should not be incorporated into Php. That excludes the Bcrypt-Wrap and the Bcrypt-SHA256 proposals. And includes PASSWORD_ARGON2ID favored by NIST and OWASP.
All of these non-standard self-invented-BCrypt-derivatives can be coded in userland. hash_algos() lists sha256, sha384, sha512 and others. hash_hmac() is available. hash_pbkdf2() is available. For the cSHAKE256 algorithm one can probably build upon https://github.com/danielburger1337/sha3-shake-php For unpadded-base64 use rtrim(base64_encode($bytes), '='). For Radix64 (or B64 as this RFC calls it), look at https://gist.github.com/MircoBabin/daee9ffa9d771bd6f3f0b2dcd9b3e7dc And if one wants to use the more space efficient COBS encoding, look at https://github.com/MircoBabin/Php-COBS-encoding
Userland can handle non-standard self-invented-security-algorithms, it is not a job for Php core. Just create a Composer installable library for this kind of self-rolled-security stuff.
If anything can be added to Php, it is
hash('shake128'), hash('shake256'), hash('cshake128') and hash('cshake256') as defined in:
https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf https://csrc.nist.gov/pubs/sp/800/185/final
Kind regards,
Mirco Babin
Hi Mirco,
The original RFC
https://wiki.php.net/rfc/argon2_password_hash_enhancements only states libargon2 as an implementation. On what platforms are Libsodium or Openssl used for PASSWORD_ARGON2ID?
The additional implementations were added later:
- libsodium by RFC: https://wiki.php.net/rfc/sodium.argon.hash
- openssl, as far as I can see, just by PR: https://github.com/php/php-src/pull/13635
It's not necessarily specific platforms, it's up to whoever builds PHP from source which implementation to use based on the libraries they have available. The choice is transparent to the user, because they all register the same hash identifier.
Libargon2 looks not that big, see
https://github.com/P-H-C/phc-winner-argon2 ; I don't see any reason why this can not be embedded?
Looking at the original PR when argon2 was first added, I see this comment from @jpauli
[https://github.com/php/php-src/pull/1997#issuecomment-231669727]:
I'm 👎 to bundle yet another lib, and to have to maintain it. This is a pain with libgd, libpcre and other libs we bundle, so please, rely on the OS distro.
Feel free to open a discussion on that topic, though; I'm not claiming to know the final outcome, just trying to explain the current situation.
"significant inputbits" is my own term. I can rephrase that to: The bcrypt-plain is giving 2 ^ 72x8 bitcombinations to Bcrypt. The bcrypt-wrap-prehashed-password is giving 2 ^ 54x8 bitcombinations to Bcrypt. That is a deterioration of 2 ^ 18x8 bitcombinations, or 25%.
However many ways you rephrase it, it's still a name you've made up, for a property that you can't explain the significance of.
I could count the number of if statements in two hashing algorithms, and say that one had "19% lower if-density" than the other, and it would be about as meaningful.
That is not fully correct. Bcrypt outputs a 24 bytes hash...
This an entirely pointless piece of pedantry. "23 bytes and 2 leftover bits" is still significantly lower than 54 bits, which is the only comparison that is relevant to the discussion.
"If the algorithm is perfectly uniform" is going into assumptions with this non-standard self-invented-security-algorithm Bcrypt-Wrap. Security should not be an assumption, it should be a fact.
That paragraph was not making any claims or assumptions, it was stating a mathematical limit. Let me rephrase:
Even if we imagine an algorithm that is perfectly uniform, then it is still guaranteed by the Pigeonhole Principle that the same "23 bytes and 2 leftover bits" will be produced by multiple inputs at any input length larger than that. An imperfect algorithm may have more collisions, but not fewer.
"doesn't seem to have any mathematical significance" is another assumption with this non-standard self-invented-security-algorithm Bcrypt-Wrap. Security should not be an assumption, it should be a fact.
Again, I made no claims or assumptions. You made the claim that the difference in "inputbits" was a "deterioration", so I asked you to back up that claim.
And what about side-channel effects, like timing or others? More assumptions will be raised etc. etc. etc. Self-designing and/or self-justifying a non-standard self-invented-security-algorithm is not the way to go for Php.
Finally, you make an actually reasonable point - there is a danger in non-experts creating security primitives.
Userland can handle non-standard self-invented-security-algorithms, it is not a job for Php core. Just create a Composer installable library for this kind of self-rolled-security stuff.
... and then you undermine yourself. Either people should be using these algorithms, and they should be easily available; or they should not be using them, wherever they're implemented.
If anything can be added to Php, it is
hash('shake128'), hash('shake256'), hash('cshake128') and hash('cshake256') as defined in:
https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf https://csrc.nist.gov/pubs/sp/800/185/final
That does indeed sound like it would be useful, with or without any use of them in the password hashing wrappers.
--
Rowan Tommins
[IMSoP]
Hi Mirco,
Quoted text · 12 lines
(Mirco Babin)
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:
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.
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: https://learn.microsoft.com/en-us/dotnet/api/system.security.- I am not looking cryptography.rfc2898derivebytes.pbkdf2 https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.rfc2898derivebytes.pbkdf2
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.
Quoted text · 7 lines
(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.
Cheers,
Andrey.
Hello Andrey Andreev,
=========
Comment 2
(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?
(Andrey Andreev)
I am against any character type validation and Bcrypt itself has issues related to character types.
(Mirco Babin)
What issues does Bcrypt have with character types? Where can these issues be found, where are they listed?
What are the reasons against character type validation? It seems to me that a password has to be human typeable? When a password can consist of bytes, it is no longer a password intended for human entry;
instead, it functions more like an API key.
Also in favor for validation:
When the Bcrypt-2a revision was introduced, UTF-8 was apparently also made mandatory. However, I cannot find a primary source for this claim. A secondary source is:
https://javadoc.io/doc/at.favre.lib/bcrypt/latest/at/favre/lib/crypto/bcrypt/BCrypt.Version.html#VERSION_2A
=========
Comment 5
(Andrey Andreev)
Quoted text · 4 lines
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.
(Mirco Babin)
This is a very strong argument against this non-standard self-invented-security-algorithm RFC and in favor of the NIST and OWASP favored security standard PASSWORD_ARGON2ID.
The last point is false. Because "bcrypt-wrap" is not a standard, doest not have a NIST specification, does not have a IETF specification, does not have an OpenBsd specification, one cannot say to a C#-programmer or LUA-programmer or security officer "just use bcrypt-wrap".
============
Comment 7(a)
(Mirco Babin)
Why is bcrypt-prehashing needed below 73 password-bytes? Bcrypt can handle 72 bytes just fine.
(Mirco Babin)
This is still unanswered. Why does BCRYPT_WRAP not do:
if (strlen($password) <= 72 && strpos($password, "\0") === false) {
// use PASSWORD_BCRYPT, it can handle this
} else {
// use PASSWORD_ARGON2ID
}
But then: why not use PASSWORD_ARGON2ID in all cases?
============
Comment 7(b)
(Mirco Babin)
Why is something being proposed, that deteriorates security?
(Andrey Andreev)
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
(Mirco Babin)
See my reply to Rowan Tommins at
https://news-web.php.net/php.internals/133126 The prehash-function does truncate the password to 54*8 significant inputbits for Bcrypt.
The RFC states:
A more space-efficient encoding was actually considered during the design, in part for elegancy and in part to diffuse arguments like this one. That's still an option if these fears persist. However, Base64 is a pragmatic choice that makes implementation less complex and portability easier, with reduced risk of mistakes.
This is not an argument against COBS or another more space-efficient encoding. The substantiation for the decision is, in fact, missing. Unpadded-base64 is also not very portable. Also a space-efficient algorithm (like COBS) really is not the complex part of the non-standard self-invented-security-algorithm presented in this RFC. Finding or implementing a reliable cSHAKE256 library is.
=========
Comment 8
(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.
(Andrey Andreev)
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.
(Mirco Babin)
Why is a 0x00-character then included in the example, if it is already very obvious that there are no character limitations?
If I have to stick to pure Bcrypt, why is this RFC then even proposing a non-standard self-invented-security-algorithm BCRYPT_WRAP?
Kind regards,
Mirco Babin
Hi,
Hi all,
I'd like to open the discussion on a new password hashing algorithm that I've been working on, named bcrypt-wrap.
RFC link: https://wiki.php.net/rfc/password_bcrypt_wrap Pull request: https://github.com/php/php-src/pull/25040 (just pushed it, CI still running)
I don't think we should be creating our own password hashing algorithm. This seems completely out of scope for PHP IMHO and I don't think the length "problem" is something that major that it needs this.
P.S. Thanks to Sjoerd for honoring my request to delay his bcrypt-sha256 proposal while I finished this.
If anything, I would support that bcrypt-sha256 which is at least used in passlib and seems much simpler.
Kind regards,
Jakub