Add PASSWORD_BCRYPT_WRAP View as Markdown

Under discussion
▴ 0 ▾ 0
community vote
Authors
Andrey Andreev, narf@devilix.net
Date
2026-10-29
Version
1.1
Implementation
https://github.com/php/php-src/pull/25040
Source
wiki.php.net/rfc/password_bcrypt_wrap

Vote

Add PASSWORD_BCRYPT_WRAP to password_hash() as outlined in the RFC? no votes
Yes · No · Abstain

Discussions on the mailing list

PASSWORD_DEFAULT value
by Vinicius Dias · 5 messages
[Discussion] Changing PASSWORD_DEFAULT to Argon2
by Andrey Andreev · 11 messages
[RFC] Add PASSWORD_BCRYPT_SHA256 to password_hash
by Sjoerd Langkemper · 12 messages
[RFC][Discussion] Add PASSWORD_BCRYPT_WRAP
by Andrey Andreev · 13 messages

RFC text

Copied from wiki.php.net, last synchronized Nov 2, 2026 15:46 UTC

Introduction

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:

  • Throw error for passwords longer than 72 bytes: RFC, php-internals thread
  • External dependencies for Argon2 being prohibitive for PASSWORD_DEFAULT: php-internals thread
  • Bcrypt is still considered best-in-class for interactive authentication, which maintains its strong position despite limitations: php-internals thread + thread link from previous point

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. Some are suboptimal in strength, others are handicapped by implementers' choices. Each has its critics, or at least enough imperfection to get the “another hash is better” reaction.

This RFC also proposes a prehashed-bcrypt construct, named “bcrypt-wrap”. This new algorithm not only entirely eliminates Bcrypt's input length and null byte limitations, but also:

  • Maximizes strength by optimal application of modern 64-bit hashing primitives from the SHA2 and SHA3 families.
  • Sidesteps all common mistakes made by other prehashed-bcrypt implementations.
  • Introduces strong binding between the prehash and Bcrypt, unique to the bcrypt-wrap protocol.
  • Is future-proof by not locking itself to a single prehash primitive.
  • Puts focus on interoperability through alignment with authoritative modern standards and formats.

The overall pattern is the same, the details are what make the difference.

Proposal

Add a new algorithm “bcrypt-wrap” (value of sole new constant PASSWORD_BCRYPT_WRAP), which has the following characteristics:

  • Inherits default cost from PASSWORD_BCRYPT_DEFAULT_COST.
  • Supports two prehash primitives, chosen through a prehash option: cshake256 (default) and sha512 (using HMAC construct).
  • Fully compliant with PHC Strings (PHCs). Every recommendation is treated as a hard requirement.

Examples

<?php
$password = "A really, really long passw\x0rd, that's over 72 bytes and also includes a null byte";
 
$hash = password_hash($password, PASSWORD_BCRYPT_WRAP);
echo $hash, "\n";
// $bcrypt-wrap$v=0$cost=12,prehash=cshake256$+Thtm389lrboo7t9btjPVw$t76sKAokMxK5jjH918oNiRRXu0WWxd0
 
var_dump(password_verify($password, $hash)); // bool(true)
var_dump(password_verify($password." + bcrypt would ignore this", $hash)); // bool(false)
 
var_dump(password_get_info($hash));
/*
array(3) {
  ["algo"]=>
  string(11) "bcrypt-wrap"
  ["algoName"]=>
  string(11) "bcrypt-wrap"
  ["options"]=>
  array(2) {
    ["cost"]=>
    int(12)
    ["prehash"]=>
    string(9) "cshake256"
  }
}
*/
 
$hash = password_hash($password, PASSWORD_BCRYPT_WRAP, ["cost" => 4, "prehash" => "sha512"]);
echo $hash, "\n";
// $bcrypt-wrap$v=0$cost=4,prehash=sha512$jjAqrmWi61kah3sXIk4uLQ$Lru7YmJuOYolnxjzxJzvew2h5S7QBSQ

Technical details

The output hash looks like so:

// Total output length varies between 93 and 97 characters, assuming 1-digit version
$bcrypt-wrap$v=0$cost=<bcrypt cost>,prehash=<cshake256|sha512>$<salt>$<hash>

v       = Version
cost    = Bcrypt cost, but not 0-padded
prehash = The underlying prehash primitive
salt    = B64-encoded salt, 22 bytes (technically expandable, as the prehash isn't limited by Bcrypt)
hash    = B64-encoded Bcrypt hash, 31 bytes

Most of that is self-explanatory even without reading the PHCs basics. Here are the non-obvious parts:

  • B64 is what PHCs calls standard, unpadded Base64. It is required by the format specification.
    • Bcrypt has its own Base64 dialect with different ordering. Internal translations are performed for alignment.
    • This supports portability. Even where that's not obvious, it prevents bugs caused by naive implementations.
    • The salt specifically needs it so, because it is used for the prehash step. Bcrypt famously discards the 128th bit, making it impossible to restore.
  • Whichever prehash function is chosen, 54 bytes of binary output are B64-encoded to fill the 72-byte space allowed by Bcrypt.
    • cSHAKE256 is an eXtendable Output Function (XOF), which means it natively supports variable-length outputs. The salt goes in its customization string.
    • HMAC-SHA512 output is truncated (yes, this is perfectly fine). The salt is part of the key.
  • Not denoting the Bcrypt variant is intentional.
    • The difference between 2b and PHP's 2y is historical and not functional. They are identical and 100% portable.
    • There's no point in supporting older variants, but a B64-encoded prehash entirely sidesteps even the bugs in 2a, 2x.
    • To the extent that a future new variant may ever be relevant, it should be bound to the numeric version present in this format.
  • There's a 1024 byte limit on the password, meant to prevent extreme misuse without any complaints.
  • Unlike seen in other hashes, the parameters use full names because PHCs recommends them to be human readable.
    • This is the least important part in the entire algorithm, but would also be set in stone. If there are meaningful objections, please do bring them up.

password_hash() pseudo-code:

password     = <user input>
version      = 0
bcrypt_cost  = <developer-chosen; existing PHP default>
prehash_func = <developer-chosen; default "cshake256">
prehash_size = 54 // yields 72 bytes base64 to fill bcrypt space
salt_raw     = random_bytes(16)

// Domain separation
prehash_salt = "bcrypt-wrap:" || version || ":" || salt_raw

if (prehash_func == "cshake256") {
    prehash_raw = cshake256(
        password,
        prehash_salt, // domain customization string
        prehash_size
    )
} else if (prehash_func == "sha512") {
    prehash_raw = hmac_sha512(
        password,
        prehash_salt // HMAC key
    )
    prehash_raw = truncate(prehash_raw, prehash_size)
} else {
    // failure
}

// crypt() and bcrypt quirks, salt_raw is used under the hood
bcrypt_hash  = crypt(
    unpadded_base64(prehash_raw), // password
    sprintf("$2y$%02u$%s", bcrypt_cost, bcrypt_base64(salt_raw))
)

output_hash  = sprintf(
    "$bcrypt-wrap$v=%u$cost=%u,prehash=%s$%s$%s",
    version,
    bcrypt_cost,
    prehash_func,
    unpadded_base64(salt_raw),
    base64_bcrypt_to_standard(substring(bcrypt_hash, -31))
)

password_verify() pseudo-code:

password     = <user input>
input_hash   = <retrieved from storage>
prehash_size = 54 // yields 72 bytes base64 to fill bcrypt space

validate_and_parse_hash(
    input_hash,
    version,      // out param
    bcrypt_cost,  // out param
    prehash_func, // out param
    salt_b64,     // out param
    hash_b64      // out param
)

salt_raw     = unpadded_base64_decode(salt_b64)
prehash_salt = "bcrypt-wrap:" || version || ":" || salt_raw

if (prehash_func == "cshake256") {
    prehash_raw = cshake256(
        password,
        prehash_salt, // domain customization string
        prehash_size
    )
} else if (prehash_func == "sha512") {
    prehash_raw = hmac_sha512(
        password,
        prehash_salt // HMAC key
    )
    prehash_raw = truncate(prehash_raw, prehash_size)
} else {
    // failure
}

hash_prefix   = sprintf(
    "$2y$%02u$%s",
    bcrypt_cost,
    base64_standard_to_bcrypt(salt_b64)
)

stringed_hash = sprintf(
    "%s%s",
    hash_prefix,
    base64_standard_to_bcrypt(hash_b64)
)

computed_hash = crypt(unpadded_base64(prehash_raw), hash_prefix)

valid = ts_strcmp(computed_hash, stringed_hash)

FAQ

Most of these are anticipated questions likely to be raised during discussion. If more come up, they'll be added at the bottom.

Isn't this rolling our own crypto? ™

No. This is a well-known pattern adjusted to modern standards. Every building block is standard, applied correctly, and has a meaningful purpose. As far as it is possible to know that mistakes are avoided, every choice made about the algorithm is backed by reputable public sources and not speculative. Since we are in the AI craze era, it needs to be said: no, none of this is invented by an LLM, and there are zero “hallucinations” involved.

Additionally, the target release version is PHP 8.7, more than a year away as of this first publication. That's plenty of time for peer review, including from outside experts.

Why have both cSHAKE256 and SHA-512?

The easy answer is Cryptographic agility. A secondary answer is that (in this context) the two are equal and no unbiased comparison today would have a clear winner. In absence of reasons other than someone's preference, it would be a mistake to lock onto one path.

cSHAKE256 is significantly more elegant and its adoption is rapidly increasing in Post-Quantum Cryptography, practically ensuring that it's here to stay. The bcrypt-wrap design actually evolved from a cshake256-bcrypt prototype. SHA-512 has a slight edge in terms of having been around for longer and users are more familiar with it. It has to be used as a HMAC and truncated, but this is a provably safe technique.

While a few vanity metrics could make a head-to-head comparison more quantitative, they are completely meaningless when wrapped by Bcrypt. The one number to care about is 256 bits of collision resistance provided by both functions. A common point of confusion might be the different numbers in the function names, which don't mean the same thing. In SHA-512, the number is the output size; in cSHAKE256, the number is the security strength.

Why is the prehash strength important?

This is a fair question, as the prehash merely patches up Bcrypt's limitations. In a pragmatic sense, it's not that important. A bigger number is not good for the sake of being bigger, and there is such a thing as too much security; otherwise we'd have cost 31 Bcrypt. However, defaulting to an acceptable minimum and opposing higher standards on a “not needed” basis is also irrational, particularly when the cost is negligible. All reasons for weaker hashes to even exist are based on computational speed, which would be a drop in the ocean of what Bcrypt does.

It is a matter of keeping up with standards, having solid grounds for trust, and (with PHP's poor reputation in mind) disarming critics.

Why is cSHAKE256 default?

In addition to already provided details, SHA-512 runs on historical momentum, while cSHAKE256 would be ahead if the same history was being shaped today. This choice is the cryptographic equivalent of parameterized SQL queries over escaped string interpolation.

HMACs are well-known for the part they play in security, but the way they are used in this pattern is a double clutch. First for what the “c” (customizable) in cSHAKE naturally provides against password shucking, and second to prevent length-extension attacks, which cSHAKE is immune to by design.

What even is cSHAKE256? It sounds exotic

It might sound that way because it's not an all-familiar “SHAnumber” name, except that's what the SHA in SHAKE stands for. This is a SHA3-family function standardized by NIST; a slightly modified SHA3-512.

Wait, SHA-512 and SHA3-512? Yes, this can be confusing. SHA-512 is from the SHA2 family, which superseded SHA1. SHA3 was introduced to replace SHA2 in case it gets broken, and so that we can have two alternatives that can't be simultaneously broken. It warrants saying that either can fail first, or be proven to be categorically better, so that's not a factor. This is merely a historical summary and a note that we're comparing SHA2 and SHA3, not standard vs exotic.

What about other hash primitives?

The format is extensible and two options must exist for cryptographic agility, but there is no intent to support many algorithms. Aside from technical merits, SHA-512 and cSHAKE256 were selected also for their wide availability. A meaningful third option of the same strength that could (and should) be added is BLAKE2b. The one bias that has played a role here is that SHA2 and SHA3 are already part of PHP core, and investing more effort before a conceptual proposal has approval makes little sense. If it gains traction though, consider BLAKE2b a realistic third that shouldn't be discounted (certainly not on the basis that we don't already have it; it is very popular in other ecosystems).

Overall though, a goal to have in mind is ensuring the algorithm is uniformly portable, without dropping one of its options. With two or three, that is easy to demand. If there were more, that would risk degrading interoperability.

This RFC exists in large part because Bcrypt is already in the standard library, while good alternatives to it require external dependencies. New additions that don't satisfy practical needs or can't meet the same criteria should be discouraged.

But OWASP recommends SHA-384?

In reference to OWASP Password Storage Cheat Sheet (archive link).

OWASP's considerations are not all about cryptographic strength. They have chosen the largest fixed-output hash that fits within 72 bytes after Base64 encoding, because their advice has to be idiomatic. It delivers practical security for the average developer in as many ecosystems as possible.

The recommendation doesn't apply to PHP, because it is PHP's role to make better things idiomatic. A side benefit to OWASP is also not having to argue about truncation. In the very same text where SHA-384 is endorsed, SHA-512 truncation is explicitly described as negligible. However, SHA-384 is a truncated SHA-512, with different initial values for the sole purpose of not producing a literal substring.

What's wrong with bcrypt-sha256?

This question is in reference to the recent RFC proposing a port of bcrypt-sha256 from Python's PassLib (archive).

bcrypt-sha256 is functionally solid, but inferior all around. It's one of those things that gets a default assumption of maturity, but in fact has many subtle deficiencies visible to a trained eye. Some may be seen as petty outside of cryptography circles, but nonetheless:

  • Most notably, SHA-256 in itself is a suboptimal choice:
    • 32-bit and computationally cheap to crunch on GPUs. 64-bit functions like SHA-512 and cSHAKE256 introduce a choke point on cracking rigs for free. The inverse argument about SHA-256 also sparing cost for defenders doesn't hold up in pairing with Bcrypt; the difference for defenders is negligible.
    • It may've made sense in 2013, as we were still rooting out MD5 and SHA1 usage back then (actually, both were still used a lot in new code). However, 64-bit functions are today's default.
  • It is based on the old Modular Crypt Format (MCF), which PassLib's original author has deprecated in favor of PHCs since 2016.
  • Because it stores Bcrypt's output “as is”, including the non-standard Base64 encoding, it is explicitly incompatible with PHCs.
  • Embedding the Bcrypt variant as a parameter (t=2b) is redundant and only adds confusion, since any string-safe encoded prehash eliminates the differences between 2a/2b/2x/2y variations. Similarly, “only” supporting 2b as of version 1.7.3 is functionally meaningless.
  • The cost parameter being encoded as r=<cost> for “rounds” is a similar misunderstanding. In Bcrypt, internal “rounds” grow exponentially with the cost. A cost of 4 results in 16 rounds, cost of 12 does 4096.
  • While fine today, PassLib had been vulnerable to shucking for many years, until version 1.7.3 in 2020.
  • As the “input space” question has already been raised separately (see its own section), the bcrypt-sha256's inner hash fills just 2^256 of the input to Bcrypt vs 2^432 utilized by bcrypt-wrap. This is still an illusion of a problem, but on the edge of the 256-bit ceiling, beyond which security concerns are not seen as serious. It just invites nitpicking and unfortunately people do avoid suboptimal algorithms for such reasons.

Something that had remained entirely unnoticed until version 1.1 of this RFC: PassLib maintenance itself had been in limbo for years, with the original author being unreachable until recently. Ownership of the package officially changed in late October 2026 (after the bcrypt-sha256 RFC and before this one). See https://github.com/pypi/support/issues/9290 and https://foss.heptapod.net/python-libs/passlib/-/work_items/187.

A lot of the above is because PassLib is simply stuck with a lot of legacy, and that's understandable, but PHP has no reason to inherit the same historical baggage and we have our own reputational problem of the same nature.

The petty nitpicks however also show a certain lack of expertise, which is a serious dent in the argument for copying an existing library on the basis of it being mature. Cryptographic implementations should be copied to avoid repeating mistakes, not to propagate them, and with the intent to benefit from good design choices that may not be obvious. PassLib's bcrypt-sha256 fails that test and is at best a “not insecure” option, mostly riding on availability bias.

bcrypt-wrap by comparison is stronger on all of the above-listed issues, easier to port by design (not for LoC, but avoiding error-prone techniques), and not being tied to a specific prehash primitive makes it future-proof as long as Bcrypt itself remains solid.

Why no pepper?

There actually was intent to build in a peppering mechanism. It just can't be done without either making it so oversimplified that it has no benefit over userspace code, or imposing significant architectural constraints on the application.

A pepper is a secret that is never stored in the database, but gets mixed into password hashes (alongside salts, not replacing them). The idea being that a database can be stolen, but not with the codebase and configuration alongside it, therefore preventing attackers from cracking password hashes because they don't have the application-layer secret.

That's all great, but a pepper comes with the same management problems as encryption keys. How do you store it? How do you rotate it? How do you not lose it? What if the security department demands it never leaves an HSM? Without accounting for all of these questions, adding a simple “pepper” element to the password_hash() options array would just be goading developers into using something they don't necessarily understand, and may lead to nasty situations. As bad as a bricked database if the pepper is lost. User-provided salt was rightfully retired for a lot less than that.

Why not bcrypt-sha512 and bcrypt-cshake256?

It's a single algorithm that works the same way regardless of the chosen prehash primitive. That may not seem like a big deal upfront, but it is significantly easier to maintain with bcrypt-wrap as a single package.

  • It makes changing parameter defaults and version upgrades less chaotic, in that they happen uniformly instead of nitpicking on a matrix.
  • The default prehash function specifically is less painful to change for both the PHP team and userspace developers:
    • We'll have little reason to debate whether an entirely different algorithm (like Argon2) is better, because bcrypt-wrap doesn't even need to be the PASSWORD_DEFAULT for a particular prehash to be set as preferred.
    • Userspace developers who choose bcrypt-wrap don't need to make an affirmative decision they don't necessarily understand.
    • In corporate environments with burdensome governance procedures, bcrypt-wrap can be approved upfront and not have each primitive be debated and inspected for safety each time.
  • There's litte room for fragmentation if ported to other languages.
  • The single identifier also provides disambiguation from other attempts to combine the same pairs of hashes.
  • It avoids introducing multiple PASSWORD_BCRYPT_* constants.

What's the evidence for consensus on the prehashed bcrypt pattern?

This question came in reference to the Introduction text. There's plenty of evidence, though in hindsight it not obvious in the PHP ecosystem:

  • OWASP Password Storage Cheatsheet has special mention of it.
  • PassLib's bcrypt-sha256 was already discussed, and although it could've been a lot better, most of its flaws exist because it is really old; it has stood the test of time.
  • Jeremi Gosney, cryptographer often cited as an authoritative source for Bcrypt being best for interactive authentication, also maintains a hmac-bcrypt library.
  • There are many userspace implementations in many languages. Most aren't noteworthy because they lack prominence, but they all land on the same pattern.
  • Even a PHP RFC from 2014 lists a similar suggestion as an alternative in case it failed (it never reached a vote).

If we are stuck with Bcrypt, which is part of the premise here, it's the only reasonable thing to do.

Isn't this vulnerable to shucking?

This concern may've been raised because of some ambiguity in the first draft of this RFC, but to answer it more directly: no.

Password shucking, or hash shucking, is a weakness that allows hash crackers to directly attack an inner hash layer instead of the full algorithm.

It is typically presented as a threat to “upgraded” old hashes, as breached databases and user correlation allows for layered hashes like bcrypt(sha256(password), salt, cost) to be cracked instantly in some cases. However, prior existence of weak hashes isn't necessarily a requirement. As long as the inner hash isn't domain-separated at least per database, it can be worthwhile for attackers to try shucking with yet uncracked plain hashes from unrelated breaches, even if your database never contained plain fast hashes.

The solution to this, using standard hash functions is to apply them as HMACs, with a key that is unique to your database: bcrypt(hmac-sha512(password, key), salt, cost) That key can be the salt itself (public, but unique per hash), pepper (global to app, but never stored in database), or even a hard-coded static string.

There are some possible points of confusion here:

  • HMACs are originally designed to be used with secret keys, which leads to belief that salts aren't appropriate because they are public. This is false, as the HMAC usage against shucking is purely for domain separation.
  • A pepper is technically the most secure option, because it is secret, and as such it's often presented as “the” solution by security-minded people. That can leave a false impression that it's the only way.
  • A static string is often recommended, as the simplest practical advice. This is just a pepper in disguise, but communicating it this way makes some sense on an individual basis, since each developer would choose a different value. If everybody used the same library with the same hard-coded string, that would no longer be true domain separation or any degree of secret. If made configurable, the pepper mechanic becomes obvious - see dedicated section on why it doesn't fit here.

bcrypt-wrap first applies a bcrypt-wrap:0: prefix to the random salt, then uses that prefixed salt as either the HMAC key with HMAC-SHA-512 or cSHAKE256's native domain customization parameter. This is a step beyond common defense against shucking, as it locks the inner hash to the outer bcrypt layer and a specific bcrypt-wrap version, making it impossible to attack independently.

Doesn't prehashing decrease bcrypt security?

Variations of this fear seem to be rooted on the too many incorrect ways in which hash layering has been done in the past.

  • Almost everyone has seen things like sha1(md5(password)), written years ago by developers who naively thought that more hashing automatically means better hashing. This was unfortunately so common that “don't double-hash” became a necessary mantra.
  • There is also the already mentioned shucking vulnerability. Because it is usually a mistake made in combination with true password-hashing algorithms, explanations of shucking typically use examples like bcrypt(sha512(password), salt, cost). That correctly notes the caveat that strong hashes aren't magically better and can still be used incorrectly.
  • Anthony Ferrara's Security Issue: Combining Bcrypt With Other Hash Functions post from 2015 talks about a threat specific to Bcrypt (null bytes, again). As the author of PHP's password hashing framework, his warning comes with a lot of authority.
  • Because PHP's ext/hash functions default to hex-encoded output, it is also easy to miss that a lot of the Bcrypt-specific warnings are related to the dangers of raw, unencoded prehashes. In cryptography and most other ecosystems, the default assumption is a raw binary array.

As the dangers are subtle and generic advice easy to remember, it is not hard to be left with the takeaway that all double-hashing is bad, doubly so with Bcrypt involved. Anthony's post explicitly describes The Fix though, referencing the Base64-encoded HMAC pattern used by Mozilla.

That is the exact same pattern used by bcrypt-wrap, with one minor difference - Mozilla's team opted for a pepper (just calling it a “local salt”) as the HMAC key, while bcrypt-wrap uses a domain-separated salt in the true sense of the term. Both approaches are valid, a pepper just isn't feasible for the goals of this RFC.

Doesn't decreased input space reduce bcrypt security?

Quote: [...] implementation decreases security of bcrypt [...] 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.

No. These numbers are meaningless and not just for being astronomical.

That to this day Bcrypt truncates any password at the null byte is a major flaw in this argument, because no algorithm intended to fully utilize this space can ignore the possibility of a null byte appearing at random positions. 1 in 5 of all uniformly random 576-bit inputs will contain a null byte. It is a usability nightmare specifically for anyone intent on getting close to 2^576, and has proven to be a security footgun for anyone else.

The 2^576 number is inherited from the maximum key size of Bcrypt's underlying Blowfish cipher. There are many reasons why this comes with a lot of caveats, but most importantly a cryptographic key is not the same thing as a password. Bcrypt is explicitly a password-hashing algorithm, which means it was designed for use with printable characters, capping the “target” input space to at most 2^474. This is useful in the modern world for Unicode characters, but is in itself a happy coincidence. At the time of Bcrypt's creation (circa 1997-1999) everybody was using 7bit ASCII (~2^237). 8bit character passwords weren't a thing for a long time, as evident by the 2x variant 8th bit bug remaining undiscovered until 2011. A claim that such a large input space is part of Bcrypt's security considerations doesn't hold up, and this is actually the least important reason why.

So why is 2^576 theoretically possible then? Primarily, it makes no sense to artificially restrict the already mentioned inheritance from Blowfish. In fact, we have the opposite issue with information density, since even the longest passwords created by humans contain a lot less entropy per byte. To get anywhere close to 2^474 would require pushing the strongest password generators to their limits, and this is a modern era ceiling, not what Bcrypt was originally designed for. The prehash step in bcrypt-wrap works around the information density problem by allowing much longer passwords.

Most notably though, 2^576 is Bcrypt's internal state size, and this is the important part - a cryptographic algorithm's internal state doesn't work like a bucket completely filled from 0 to SIZE_MAX. The algorithm's constants, multiple 32-bit boxes that the input is funneled through, binding to a 128-bit salt, and mathematical operations being performed restrict the number of unique states realistically closer to half that size! Actual security strength is further affected by other factors, including the 184-bit output; less than a third of 576.

Does that mean the input space is entirely irrelevant? No, of course not, but as long as the prehash is sufficiently large, there is zero drop in security stemming from this factor. It is also not a relevant bottleneck though, as the low information density in user passwords is the real problem, well-worth the perceived tradeoff to allow for long passphrases.

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.

Backward Incompatible Changes

None.

Proposed PHP Version(s)

PHP 8.7.

RFC Impact

To the Ecosystem

Developers no longer have to make a tradeoff between working around Bcrypt's limitations or potentially unavailable extensions. Code dealing with this tradeoff can be phased-out, which has the second-order effect of reduced risks in security-critical code, even beyond password handling. A lot of end users get a free security upgrade without realizing it.

To Existing Extensions

ext/standard will now depend on ext/hash, but this is a non-issue since RFC: Always available hash extension. ext/hash ABI is affected, since it needs to expose low-level functionality for use by ext/standard/password.c

To SAPIs

None.

Open Issues

None yet.

Future Scope

Potentially become the PASSWORD_DEFAULT in a later major PHP release.

Voting Choices

Primary Vote requiring a 2/3 majority to accept the RFC:

Vote: Add PASSWORD_BCRYPT_WRAP to password_hash() as outlined in the RFC? — Yes: 0 · No: 0 · Abstain: 0 (closed)

Patches and Tests

https://github.com/php/php-src/pull/25040

Implementation

After the RFC is implemented, this section should contain:

  1. PHP version(s) it was merged into
  2. Link to the git commit(s)
  3. Link to the PHP manual entry for the feature

References

Rejected Features

None.

Changelog

  • 2026-11-02: Addressed initial feedback: added algorithm pseudo-code, clearer rationale, and counter-points to common fears.
  • 2026-10-29: Initial version.