Re: [RFC][Discussion] Add PASSWORD_BCRYPT_WRAP

From: Date: Thu, 03 Dec 2026 16:03:17 +0000
Subject: Re: [RFC][Discussion] Add PASSWORD_BCRYPT_WRAP
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-133283@lists.php.net to get a copy of this message
Hello Rowan Tommins, >RFC link: https://wiki.php.net/rfc/password_bcrypt_wrap ========= 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 72*8 significant inputbits to Bcrypt. The > bcrypt-wrap-prehashed-password is giving 54*8 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

« previous php.internals (#133283) next »