# crypt() BC issue

- Thread: https://staging.externals.io/message/75570
- Original archive: https://news-web.php.net/php.internals/75570
- Started by Yasuo Ohgaki on 2014-07-16T00:46:54+00:00
- Messages: 32
- RFC: Throw error for passwords longer than 72 bytes in password_hash() with bcrypt (Inactive) — https://staging.externals.io/rfc/bcrypt_max_password_length.md
- Page 1 of 2: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://staging.externals.io/message/75570.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://staging.externals.io/search.md?q={query} · RFCs at https://staging.externals.io/rfc.md · JSON API at https://staging.externals.io/api · documentation at https://staging.externals.io/llms.txt

---

## #75570 — Yasuo Ohgaki — 2014-07-16T00:46:54+00:00

URL: https://staging.externals.io/message/75570#75570

Hi all,

 `crypt()` has BC issue with older systems.

https://bugs.php.net/bug.php?id=62372&edit=1

The reason rounds became 1000 from 10 is hardcoded lower limit for newer
PHPs.
Generally speaking, developer should never use less than 1000 rounds and
better to have
at least few thousands rounds or more, tens of thousands or more is
recommended.

I would like to make this bug report 'wont fix', since migration is
possible.

 - Developer may use larger rounds and store updated hash when
   user is authenticated with old PHP.
 - Developer may ask users to reset password if password hash has
   to fewer rounds than 1000 (i.e. outdated hash) with new PHP.

Any comments?

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #75571 — Andrea Faulds — 2014-07-16T01:12:34+00:00

URL: https://staging.externals.io/message/75570#75571 · In reply to: #75570

> - Developer may use larger rounds and store updated hash when
>   user is authenticated with old PHP.
> - Developer may ask users to reset password if password hash has
>   to fewer rounds than 1000 (i.e. outdated hash) with new PHP.

Wait, doesn’t that mean you’re unable to verify passwords now?
--
Andrea Faulds
http://ajf.me/

---

## #75572 — Yasuo Ohgaki — 2014-07-16T01:45:24+00:00

URL: https://staging.externals.io/message/75570#75572 · In reply to: #75571

Hi Andrea,



> > […]
>
> Wait, doesn’t that mean you’re unable to verify passwords now?


It means old PHP users may need preparation for their apps to
migrate newer PHP.

If developer upgrades PHP blindly, they may see a lots of failed logins.

This change was done while ago, so it would not worth the effort to relax
the requirement now. IMHO.

We may add optional flag to relax the limitation, though.
I don't mind modifying `crypt()` or adding migration INI setting.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #75573 — Andrea Faulds — 2014-07-16T01:47:45+00:00

URL: https://staging.externals.io/message/75570#75573 · In reply to: #75572

> This change was done while ago, so it would not worth the effort to relax
> the requirement now. IMHO.
> 
> We may add optional flag to relax the limitation, though.
> I don't mind modifying `crypt()` or adding migration INI setting.

Yeah, that’s my thoughts as well. We changed it for a reason, but to avoid breaking things, perhaps a migratory INI setting (which we’d eventually remove) is for the best.
--
Andrea Faulds
http://ajf.me/

---

## #75575 — Yasuo Ohgaki — 2014-07-16T01:54:47+00:00

URL: https://staging.externals.io/message/75570#75575 · In reply to: #75573

Hi Andrea,



> > […]
>
> Yeah, that’s my thoughts as well. We changed it for a reason, but to avoid
> breaking things, perhaps a migratory INI setting (which we’d eventually
> remove) is for the best.


OK. I'll write a new RFC to add migration INI for this unless
there aren't any more comments.

 - Add bool crypt_migration INI that is default to OFF for PHP 5.4 and up.
 - master will not have this INI.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #75619 — Sara Golemon — 2014-07-16T23:53:07+00:00

URL: https://staging.externals.io/message/75570#75619 · In reply to: #75570

> `crypt()` has BC issue with older systems.
>
> https://bugs.php.net/bug.php?id=62372&edit=1
>
> The reason rounds became 1000 from 10 is hardcoded lower limit for newer
> PHPs.
> Generally speaking, developer should never use less than 1000 rounds and
> better to have
> at least few thousands rounds or more, tens of thousands or more is
> recommended.
>
> I would like to make this bug report 'wont fix', since migration is
> possible.
>
>  - Developer may use larger rounds and store updated hash when
>    user is authenticated with old PHP.
>  - Developer may ask users to reset password if password hash has
>    to fewer rounds than 1000 (i.e. outdated hash) with new PHP.
>
At the risk of perhaps missing the point, wouldn't it be more useful
to encourage users in some way (perhaps through documentation only) to
use `password_hash()`/password_verify() instead?  It was designed with
migration paths in mind.

Apps which are currently using `crypt()` for their own password systems
(the ones you would have migrate to `crypt()` + 1000 rounds) should be
pointed at the right solution, not placated with an "okay for now, but
may need to be migrated again later" route.

As far as I'm aware, the only reason for not marking `crypt()`
 `E_DEPRECATED` right now is for compatibility with external systems, and
as far as those go, changing a default won't effect anything.

-Sara

---

## #75623 — Yasuo Ohgaki — 2014-07-17T01:06:40+00:00

URL: https://staging.externals.io/message/75570#75623 · In reply to: #75619

Hi Sara,



> At the risk of perhaps missing the point, wouldn't it be more useful
> to encourage users in some way (perhaps through documentation only) to
> use `password_hash()`/password_verify() instead?  It was designed with
> migration paths in mind.
>

I'll add them.


>  Apps which are currently using `crypt()` for their own password systems
> (the ones you would have migrate to `crypt()` + 1000 rounds) should be
> pointed at the right solution, not placated with an "okay for now, but
> may need to be migrated again later" route.
>
> As far as I'm aware, the only reason for not marking `crypt()`
> `E_DEPRECATED` right now is for compatibility with external systems, and
> as far as those go, changing a default won't effect anything.
>

Instead of relaxing `crypt()`, how about relax `password_verify()`?

<?php
$h='$6$rounds=10$qNElXs2yMnL2.GNS3kiM7DqmGbFLdQfIwu2691aJgT3xgJazPLtw7RPKz3Dp8RIc4b5fmJ7qvlq/mPN8a.rE40';
$p='salasana';
$c=crypt($p,$h);
echo "HASH:  $h\n";
echo "CRYPT: $c\n";
if ($c == $h) {
  echo "MATCH OK\n";
} else {
  echo "NO MATCH\n";
}

var_dump(password_verify($p, $h)); // Fails since `password_verify()` is
 `crypt()` wrapper

$h2='$6$rounds=1000$qNElXs2yMnL2.GNS$/q7trYkbKkoJernsumbObt2IysdXGRx/ytFaG0HBC97rHHhYRQvUcyEuRHP6h5yj8V.fH7XKEw5hjofVmYONw1';

var_dump(password_verify($p, $h2)); // Success since it has 1000 rounds
?>

Current `password_verify()` is using the same hard coded 1000 rounds
limitation, but
it could be relaxed. This would be the best solution.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #75625 — Tjerk Meesters — 2014-07-17T02:09:12+00:00

URL: https://staging.externals.io/message/75570#75625 · In reply to: #75623

Hi,




> Hi Sara,
>
> 
>
> > […]
>
> I'll add them.
>
>
> > […]
>
> Instead of relaxing `crypt()`, how about relax `password_verify()`?
>
> <?php
>
> $h='$6$rounds=10$qNElXs2yMnL2.GNS3kiM7DqmGbFLdQfIwu2691aJgT3xgJazPLtw7RPKz3Dp8RIc4b5fmJ7qvlq/mPN8a.rE40';
> $p='salasana';
> $c=crypt($p,$h);
> echo "HASH:  $h\n";
> echo "CRYPT: $c\n";
> if ($c == $h) {
>   echo "MATCH OK\n";
> } else {
>   echo "NO MATCH\n";
> }
>
> var_dump(password_verify($p, $h)); // Fails since `password_verify()` is
> `crypt()` wrapper
>
>
> $h2='$6$rounds=1000$qNElXs2yMnL2.GNS$/q7trYkbKkoJernsumbObt2IysdXGRx/ytFaG0HBC97rHHhYRQvUcyEuRHP6h5yj8V.fH7XKEw5hjofVmYONw1';
>
> var_dump(password_verify($p, $h2)); // Success since it has 1000 rounds
> ?>
>
> Current `password_verify()` is using the same hard coded 1000 rounds
> limitation, but
> it could be relaxed. This would be the best solution.
>

Why should `password_verify()` work on a hash that wasn't generated with
`password_hash()`? The fact that it uses `crypt()` internally should not
leak outside of its API, imho.


>
> Regards,
>
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net
>



-- 
--
Tjerk

---

## #75627 — Yasuo Ohgaki — 2014-07-17T02:25:06+00:00

URL: https://staging.externals.io/message/75570#75627 · In reply to: #75625

Hi Tjerk,

On Thu, Jul 17, 2014 at 11:09 AM, Tjerk Meesters <tjerk.meesters@gmail.com>
wrote:

> Why should `password_verify()` work on a hash that wasn't generated with
> `password_hash()`? The fact that it uses `crypt()` internally should not
> leak outside of its API, imho.


password_*() is designed as `crypt()` wrapper and this fact is documented
since it was released.

Obsolete password hash is easy to verify with `password_needs_rehash()`.
Developers can check password database easily with `password_needs_rehash()`.
i.e. They don't have to parse password hash to detect obsolete hash.

Therefore, using password_*() for `crypt()` generated passwords makes sense.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #75640 — Tjerk Meesters — 2014-07-17T06:16:38+00:00

URL: https://staging.externals.io/message/75570#75640 · In reply to: #75627

> Hi Tjerk,
>
> On Thu, Jul 17, 2014 at 11:09 AM, Tjerk Meesters <tjerk.meesters@gmail.com
> > […]
>
> > […]
>
>
> password_*() is designed as `crypt()` wrapper and this fact is documented
> since it was released.
>
> Obsolete password hash is easy to verify with `password_needs_rehash()`.
> Developers can check password database easily with `password_needs_rehash()`.
>

The documentation states that the `hash` argument to both
`password_needs_rehash()` and `password_verify()` is:

    hash - A hash created by `password_hash()`.

Passing a value from your own `crypt()` implementation may work, but that
shouldn't be relied upon. I certainly wouldn't classify it as a problem
that should be fixed in the password api.

i.e. They don't have to parse password hash to detect obsolete hash.
>
> Therefore, using password_*() for `crypt()` generated passwords makes sense.
>
> Regards,
>
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net
>



-- 
--
Tjerk

---

## #75665 — Yasuo Ohgaki — 2014-07-17T10:31:53+00:00

URL: https://staging.externals.io/message/75570#75665 · In reply to: #75640

Hi Tjerk,

On Thu, Jul 17, 2014 at 3:16 PM, Tjerk Meesters <tjerk.meesters@gmail.com>
wrote:

> 
>
> > […]
>
> The documentation states that the `hash` argument to both
> `password_needs_rehash()` and `password_verify()` is:
>
>     hash - A hash created by `password_hash()`.
>
> Passing a value from your own `crypt()` implementation may work, but that
> shouldn't be relied upon. I certainly wouldn't classify it as a problem
> that should be fixed in the password api
>

It's easier to change `crypt()` behavior, since  password_*() is `crypt()`
wrapper.
Are we going to relax the `crypt()` restriction permanently? It's ok for me.
Users
are better to use password_*() anyway. We must remove 72 bytes restriction
in password_*() ASAP, though. i.e. blowfish truncates password longer than
72
bytes.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #75671 — Adam Harvey — 2014-07-17T17:50:29+00:00

URL: https://staging.externals.io/message/75570#75671 · In reply to: #75640

> 
>
> > […]
>
> The documentation states that the `hash` argument to both
> `password_needs_rehash()` and `password_verify()` is:
>
>     hash - A hash created by `password_hash()`.

Whoa. Don't put too much stock in that — I think I made that up out of
whole cloth while trying to get _something_ into the manual for one of
the early alpha releases of 5.5, and it wasn't intended as a
restrictive statement.

> Passing a value from your own `crypt()` implementation may work, but that
> shouldn't be relied upon. I certainly wouldn't classify it as a problem
> that should be fixed in the password api.

The original RFC specified that both `crypt()` and `password_hash()`
hashes were accepted here, and that's probably what the documentation
should say too.

Adam

---

## #75674 — Anthony Ferrara — 2014-07-17T19:38:23+00:00

URL: https://staging.externals.io/message/75570#75674 · In reply to: #75671

All,

Look at the issue, there's a line in there that is the crux of the issue:

> So problem isn't only in ROUNDS_MIN.

In fact, the overall algorithm changed.

Look at a quick example: http://3v4l.org/Eov3o

From 5.3.2+ (when we pulled in our own implementation of crypt-sha256
and crypt-sha512, and crypt-blowfish):

using salt:
string(31) "$6$rounds=1000$abcdefghijklmnop"
gives hash:
string(118) "$6$rounds=1000$abcdefghijklmnop$SgL/Atu7DClkX0qBUuG6FS2bRf2XmLFWY9b8pRttPEj9ZSh4MKE5bKlz4WAKomLuWI.YQ5oIPLO2L.0OioAeW/"

great.
But in 4.3.0 - 5.2.17:
the same salt gives:
string(99) "$6$rounds=10$EdPD9pXG2vAIeeyG2E/9Mzey2mA/qZgIBAbccXWtrNiymhFYXNK4r2gphMi4KOksXRubHnBWGVh/p2pP2D3R.."

Which is shorter. Also note that the rounds went from the defined 1000, to 10.

Things get far weirder: http://3v4l.org/KZoIv

$h1='$6$rounds=1$abcdefghijklmnop';
$h2='$6$abcdefghijklmnop';
gives us (on 4.3.0 - 5.2.17):
string(102) "$6$rounds=1000$$6TFP.7u1vZP5A9fccvmUPteI8f29BLhgfqL1XEQqcrvqTSKKw5SBa2qw1sOwLEQ41Dhl1u/Jbi2hRHRYCdxuv0"
string(99) "$6$abcdefghi$4Dv/xQG4euniWsyrRHGUrNqM9CFl5Pg9EI88OgO4tIzuV952JnT09wVxrzUP9l/dr0wP3YSs1Ufz1qJpifLAA0"

Note that these are different all around from the other results from
the same version range.

Basically, the version of crypt being linked to is either buggy (not
likely) or our documentation of it is (likely). And our implementation
(since 5.3.2) conforms to our documentation instead of the old
behavior.

Considering 5.3.2 was released 4 years ago, and 5.2 has been EOL for
3.5 years, I don't think there's anything that can be done about this.
If it was a simple limit that needed changing, a polyfill would be
easy (took me 10 minutes:
https://gist.github.com/ircmaxell/ac0710ce044504f65cf0 ). But seeing
the entire algorithm is different, much harder.

I think this should be documented, and then called a day. I don't see
anything else that could reasonably be done (changing `crypt()` at this
point is out of the question IMHO).

>  - Add bool crypt_migration INI that is default to OFF for PHP 5.4 and up.
>  - master will not have this INI.

Please don't. As I showed above, it's already long past that point.
And we don't need new ini settings.

And what that ini setting would control is not the minimum iteration
flag (as that's not the only problem), but which version of libcrypt
we're binding to (our internal one, or an external one). Which means
that the overall behavior *will* change. And unless you do it
perfectly, it could effect all of crypts algorithms (potentially
impacting password_hash, etc).

We internalized the algorithms in 5.3.2 at least partially because the
system provided libraries were inconsistent at best (hence why many
but not all 5.2 systems don't support bcrypt, it depended on the build
of libcrypt you linked against).

Please don't make us re-live this inconsistency... Especially when it
won't really solve the problem.






Regarding `password_verify()` accepting `crypt()`, I consider it an
implementation detail that it works. I know the RFC specifies it, but
it specifies it not as a conceptual fact (that it will always be no
more than a reason to be there), but more as an explanation for what
it's currently doing. I would not rely on that fact. It may work
today. It may work tomorrow, but it shouldn't be documented as such
(as it's the complement of `password_hash()`, not the complement of
 `crypt()`).

> As far as I'm aware, the only reason for not marking `crypt()`
> `E_DEPRECATED` right now is for compatibility with external systems, and
> as far as those go, changing a default won't effect anything.

I want to reinforce that point, because it's spot on the money:

I think crypt should live on. password_hash should be the way new
systems are built, sure. But as you mention external systems, crypt
should be a standard way of interacting with them (heck, that's what
the lib was designed for). It shouldn't be a "if you're not using
 `password_hash()`, you're doing it wrong". It's "password_hash() should
solve the majority of use-cases, but if you have a different need,
there are other options".

My $0.02

Anthony


> 
> > […]
>
> Whoa. Don't put too much stock in that — I think I made that up out of
> whole cloth while trying to get _something_ into the manual for one of
> the early alpha releases of 5.5, and it wasn't intended as a
> restrictive statement.
>
> > […]
>
> The original RFC specified that both `crypt()` and `password_hash()`
> hashes were accepted here, and that's probably what the documentation
> should say too.
>
> Adam

---

## #75676 — Yasuo Ohgaki — 2014-07-17T21:12:14+00:00

URL: https://staging.externals.io/message/75570#75676 · In reply to: #75674

Hi all,

On Fri, Jul 18, 2014 at 4:38 AM, Anthony Ferrara <ircmaxell@gmail.com>
wrote:

> We internalized the algorithms in 5.3.2 at least partially because the
> system provided libraries were inconsistent at best (hence why many
> but not all 5.2 systems don't support bcrypt, it depended on the build
> of libcrypt you linked against).
>
> Please don't make us re-live this inconsistency... Especially when it
> won't really solve the problem.
>

OK for me. I suggested to close the bug as 'wont fix' in first place.


> Regarding `password_verify()` accepting `crypt()`, I consider it an
> implementation detail that it works. I know the RFC specifies it, but
> it specifies it not as a conceptual fact (that it will always be no
> more than a reason to be there), but more as an explanation for what
> it's currently doing. I would not rely on that fact. It may work
> today. It may work tomorrow, but it shouldn't be documented as such
> (as it's the complement of `password_hash()`, not the complement of
> `crypt()`).
>
> > […]
>
> I want to reinforce that point, because it's spot on the money:
>
> I think crypt should live on. password_hash should be the way new
> systems are built, sure. But as you mention external systems, crypt
> should be a standard way of interacting with them (heck, that's what
> the lib was designed for). It shouldn't be a "if you're not using
> `password_hash()`, you're doing it wrong". It's "password_hash() should
> solve the majority of use-cases, but if you have a different need,
> there are other options".
>

I agree. `crypt()` should be available as normal function.

Anthony, do you have suggestion for removing 72 char restriction of
PASSWORD_BCRYPT?

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #75677 — Anthony Ferrara — 2014-07-17T21:56:52+00:00

URL: https://staging.externals.io/message/75570#75677 · In reply to: #75676

Yasuo

> Anthony, do you have suggestion for removing 72 char restriction of
> PASSWORD_BCRYPT?

My suggestion is to leave it there (it's no longer bcrypt if you do
something to remove it). Here's a deeper explanation:
http://stackoverflow.com/a/16597402/338665

Once scrypt (or yescrypt, or whatever comes out of PHC) gets crypt(3)
bindings, then we can implement that and pull it into the password
API.

Until then, implementing anything else is a step backwards
(crypt-sha256/512 is weaker than bcrypt, as is PBKDF2+sha512). So
since the 72 character restrict has little if any practical effect
(see my answer above), it's not worth making a practical weakening
(measurably harming everyone) of the overall algorithm for no reason.

My assertion is that, for the average developer, they are far more
likely to screw something up than actually improve security. The
documentation should be updated (and was, but instead of fixing a
misleading line, someone simply removed it, making the overall
statement more misleading).

Could we pre-hash internally ourselves? Sure. But at that point it's
no longer bcrypt (but our own hybrid) which was not what we were
after.

My stance here is that `password_hash()` should use standard algorithms
and formats **only**. The last thing we should be doing is inventing
crypto ourselves. Even if it "seems safe". Even if it "seems better".

Let's stick with the current implementation, make the "72 character
warning" a lot less scary, and move on. Once there are crypt(3)
bindings to a more secure algorithm (again, scrypt or yescrypt, or
whatever), then move to it....

Anthony

---

## #75692 — Yasuo Ohgaki — 2014-07-19T01:59:24+00:00

URL: https://staging.externals.io/message/75570#75692 · In reply to: #75677

Hi Anthony,

On Fri, Jul 18, 2014 at 6:56 AM, Anthony Ferrara <ircmaxell@gmail.com>
wrote:

> > […]
>
> My suggestion is to leave it there (it's no longer bcrypt if you do
> something to remove it). Here's a deeper explanation:
> http://stackoverflow.com/a/16597402/338665
>
> Once scrypt (or yescrypt, or whatever comes out of PHC) gets crypt(3)
> bindings, then we can implement that and pull it into the password
> API.
>

Sounds good to me.


>
> Until then, implementing anything else is a step backwards
> (crypt-sha256/512 is weaker than bcrypt, as is PBKDF2+sha512). So
> since the 72 character restrict has little if any practical effect
> (see my answer above), it's not worth making a practical weakening
> (measurably harming everyone) of the overall algorithm for no reason.
>
> My assertion is that, for the average developer, they are far more
> likely to screw something up than actually improve security. The
> documentation should be updated (and was, but instead of fixing a
> misleading line, someone simply removed it, making the overall
> statement more misleading).
>
> Could we pre-hash internally ourselves? Sure. But at that point it's
> no longer bcrypt (but our own hybrid) which was not what we were
> after.
>

I'll suggest users to use SHA512 raw output as password to
remove 72 chars limitation if it is needed.

<?php
// Use sha512's raw(binary) output
$h = password_hash(hash('sha512', 'my long password', true),
PASSWORD_DEFAULT);

// Verify
$r = password_verify(hash('sha512', 'my long password', true), $h);

var_dump($r); // `TRUE` 
?>


>
> My stance here is that `password_hash()` should use standard algorithms
> and formats **only**. The last thing we should be doing is inventing
> crypto ourselves. Even if it "seems safe". Even if it "seems better".
>

I agree.


> Let's stick with the current implementation, make the "72 character
> warning" a lot less scary, and move on. Once there are crypt(3)
> bindings to a more secure algorithm (again, scrypt or yescrypt, or
> whatever), then move to it....


Raising `E_NOTICE` for too long password for `PASSWORD_BCRYPT` 
makes sense. I'll add it later.

https://bugs.php.net/bug.php?id=67653

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #75693 — Yasuo Ohgaki — 2014-07-19T02:15:01+00:00

URL: https://staging.externals.io/message/75570#75693 · In reply to: #75570

Hi all,



> `crypt()` has BC issue with older systems.
>
> https://bugs.php.net/bug.php?id=62372&edit=1
>
> The reason rounds became 1000 from 10 is hardcoded lower limit for newer
> PHPs.
> Generally speaking, developer should never use less than 1000 rounds and
> better to have
> at least few thousands rounds or more, tens of thousands or more is
> recommended.
>
> I would like to make this bug report 'wont fix', since migration is
> possible.
>
>  - Developer may use larger rounds and store updated hash when
>    user is authenticated with old PHP.
>  - Developer may ask users to reset password if password hash has
>    to fewer rounds than 1000 (i.e. outdated hash) with new PHP.
>
> Any comments?
>

I'm not going to touch `crypt()`, but `password_hash()` behavior that truncates
byte larger than 72
silently is not good.

I made a bug report for this to add E_NOTICE.
https://bugs.php.net/bug.php?id=67653

Any comments? If not, I'll add `E_NOTICE` in a few days.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #75694 — Nikita Popov — 2014-07-19T05:46:22+00:00

URL: https://staging.externals.io/message/75570#75694 · In reply to: #75693

> Hi all,
>
> 
>
> > […]
>
> I'm not going to touch `crypt()`, but `password_hash()` behavior that truncates
> byte larger than 72
> silently is not good.
>
> I made a bug report for this to add E_NOTICE.
> https://bugs.php.net/bug.php?id=67653
>
> Any comments? If not, I'll add `E_NOTICE` in a few days.
>

I'm against adding this notice to password_hash. This will require all
applications to ensure that passwords are shorter than 72 chars. I don't
think that's a good idea.

Nikita

---

## #75695 — Yasuo Ohgaki — 2014-07-19T08:44:14+00:00

URL: https://staging.externals.io/message/75570#75695 · In reply to: #75694

Hi Nikita,



> I'm against adding this notice to password_hash. This will require all
> applications to ensure that passwords are shorter than 72 chars. I don't
> think that's a good idea.


Generally speaking, it would not be serious issue. 72 bytes constant prefix
would
not be used most likely.

However, bug like this in "authentication" code must be detected  and
fixed.
If password should be truncated, it should be truncated by app developers
explicitly and
notified users that their password had been truncated.  IMHO.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #75696 — Andrey Andreev — 2014-07-19T11:50:25+00:00

URL: https://staging.externals.io/message/75570#75696 · In reply to: #75695

>
> Hi Nikita,
>
> On Sat, Jul 19, 2014 at 2:46 PM, Nikita Popov <nikita.ppv@gmail.com>
wrote:
>
> > […]
>
>
> Generally speaking, it would not be serious issue. 72 bytes constant
prefix
> would
> not be used most likely.
>
> However, bug like this in "authentication" code must be detected  and
> fixed.
> If password should be truncated, it should be truncated by app developers
> explicitly and
> notified users that their password had been truncated.  IMHO.
>
> Regards,
>
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net

Hi,

There's already a notice about this in the `password_hash()` docs, one that
almost looks like is designed to scare users, which is bad. Throwing an
 `E_NOTICE` will cause more problems than it would supposedly solve.

Application developers should just state this limitation on their
registration/password change pages, anything else is pointless.

Cheers,
Andrey.

---

## #75697 — Anthony Ferrara — 2014-07-19T15:27:40+00:00

URL: https://staging.externals.io/message/75570#75697 · In reply to: #75692

Yasuo

> I'll suggest users to use SHA512 raw output as password to
> remove 72 chars limitation if it is needed.

Then you either misunderstood what I was saying, or completely ignored it.

> Raising `E_NOTICE` for too long password for `PASSWORD_BCRYPT` 
> makes sense. I'll add it later.
>
> https://bugs.php.net/bug.php?id=67653

Please, don't change anything without first proposing an RFC so that
sufficient discussion can occur. Literally every single person in this
thread has disagreed with you, yet you want to go ahead and make
changes. It's not saying that you are wrong, but that discussion needs
to happen before any changes to security sensitive code and
documentation.

Also, Deprecating `crypt()` without first discussing it (and having an
RFC to vote on) is not cool (and has been reverted):
http://svn.php.net/viewvc/phpdoc/en/trunk/reference/strings/functions/crypt.xml?r1=333973&r2=334296



> Generally speaking, it would not be serious issue. 72 bytes constant prefix
> would
> not be used most likely.

Correct. So if it's not a serious issue, why are we talking about
adding serious warnings to documentation pages (big red boxes), and
notices and pre-hashing?

> However, bug like this in "authentication" code must be detected  and
> fixed.

It's not a bug. It's by design. You could argue if it's a good design
or not, but it's very much by design.

> If password should be truncated, it should be truncated by app developers
> explicitly and
> notified users that their password had been truncated.  IMHO.

We disagree. So rather than just committing changes, why not draft up
an RFC with your suggestions, which can be discussed and voted upon?




> There's already a notice about this in the `password_hash()` docs, one that
> almost looks like is designed to scare users, which is bad. Throwing an
> `E_NOTICE` will cause more problems than it would supposedly solve.

I agree 100%. It's on my list of things to do to "clean up" that
warning, to word it to be less scary. And I agree 100% on the notice
side as well.

> Application developers should just state this limitation on their
> registration/password change pages, anything else is pointless.

I don't think so. If the end user enters a 72 character+ password, the
chances of a collision because of the truncation are so small that
it's not worth worrying about.

However, it's worth documenting, as what you don't want is people
inventing their own crypto by prefixing their own secret:

    password_hash(hash('sha512', SECRET_KEY) . $password, PASSWORD_DEFAULT)

Which would then always produce the same hash (since the sha512 hash
is 128 bytes long, truncation would happen too early).

We should be educating people to avoid their own crypto. That was the
entire point of the password_hash APIs. Make it so simple that it's
difficult to screw up. Yet people will always find a way. The only way
to solve that problem is education. And adding big red boxes isn't
education. It's fear.

Anthony

---

## #75700 — Yasuo Ohgaki — 2014-07-20T00:33:53+00:00

URL: https://staging.externals.io/message/75570#75700 · In reply to: #75697

Hi Anthony,

On Sun, Jul 20, 2014 at 12:27 AM, Anthony Ferrara <ircmaxell@gmail.com>
wrote:

> > […]
>
> Then you either misunderstood what I was saying, or completely ignored it.
>

SHA512 raw output may truncate bytes from 72 to 64 in return of limitless
password
length. Do you suggest developers not to workaround 72 bytes limitation by
themselves
like this?

SHA512 raw results could weaken password length longer than 64. However,
allowed
chars for passwords are limited almost always. It would not be an issue to
worry much.

> Raising `E_NOTICE` for too long password for `PASSWORD_BCRYPT` 
> > […]
>
> Please, don't change anything without first proposing an RFC so that
> sufficient discussion can occur. Literally every single person in this
> thread has disagreed with you, yet you want to go ahead and make
> changes. It's not saying that you are wrong, but that discussion needs
> to happen before any changes to security sensitive code and
> documentation.
>
> Also, Deprecating `crypt()` without first discussing it (and having an
> RFC to vote on) is not cool (and has been reverted):
>
> http://svn.php.net/viewvc/phpdoc/en/trunk/reference/strings/functions/crypt.xml?r1=333973&r2=334296
>
>
>
> > […]
> prefix
> > […]
>
> Correct. So if it's not a serious issue, why are we talking about
> adding serious warnings to documentation pages (big red boxes), and
> notices and pre-hashing?
>
> > […]
>
> It's not a bug. It's by design. You could argue if it's a good design
> or not, but it's very much by design.
>

I'm not saying that 72 bytes length limit is a blowfish bug.
I'm saying it's a _user_ code bug that blindly accepts password exceeds its
limit.


>
> > […]
>
> We disagree. So rather than just committing changes, why not draft up
> an RFC with your suggestions, which can be discussed and voted upon?
>

I think you misunderstood me.
What I'm going to change is adding `E_NOTICE` for password longer than 72
bytes.
It's just a simple input validation.


> > […]
> that
> > […]
>
> I agree 100%. It's on my list of things to do to "clean up" that
> warning, to word it to be less scary. And I agree 100% on the notice
> side as well.


> > […]
>
> I don't think so. If the end user enters a 72 character+ password, the
> chances of a collision because of the truncation are so small that
> it's not worth worrying about.
>

I agree it would not be an serious issue.

However, it's worth documenting, as what you don't want is people
> inventing their own crypto by prefixing their own secret:
>
>     password_hash(hash('sha512', SECRET_KEY) . $password, PASSWORD_DEFAULT)
>
> Which would then always produce the same hash (since the sha512 hash
> is 128 bytes long, truncation would happen too early).
>

Good example. People do this kind of things.
 `E_NOTICE` error should help to prevent such code.


> We should be educating people to avoid their own crypto. That was the
> entire point of the password_hash APIs. Make it so simple that it's
> difficult to screw up. Yet people will always find a way. The only way
> to solve that problem is education. And adding big red boxes isn't
> education. It's fear.


I'm not closely following doc commit. It seems my commit was modified.

http://jp2.php.net/manual/en/function.password-hash.php

"Caution Using the `PASSWORD_BCRYPT` for the algo parameter, will result in
the password parameter being truncated to a maximum length of 72
characters."

This may be too much. I've added truncation spec in `PASSWORD_BCRYPT` 
constant explanation.
I suppose it was better than this. (Besides grammar)

Anyway, there are 2 things to resolve.

 - If we have `E_NOTICE` for `password_hash()` with `PASSWORD_BCRYPT` or not
 - How we document password_*()

Your example

    password_hash(hash('sha512', SECRET_KEY) . $password, PASSWORD_DEFAULT)

shows that we are better to have `E_NOTICE` for too long password.
I'm OK with any documentation as long as it's precise.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #75732 — Yasuo Ohgaki — 2014-07-21T00:04:34+00:00

URL: https://staging.externals.io/message/75570#75732 · In reply to: #75700

Hi Anthony,

I want to finish and close this issue.



> Also, Deprecating `crypt()` without first discussing it (and having an
> > […]
>
I wrote

"Use of <function>crypt</function> is deprecated."

not

"crypt() is deprecated". I didn't mean `crypt()` function deprecation. If
it's confusing, I don't mind at all to rewrite it.
BTW, what part is wrong?

It seems we have misunderstanding each other, but the basis is the same, I
suppose.

 - `crypt()` will remain
 - User/developer should use password_*()
 - It's not good idea to have PHP own `crypt()`

The differences are `E_NOTICE` and workaround, it seems.
IMO, `password_hash()` must raise `E_NOTICE` for too long password. Truncation
without error is
not an option for me. People write stupid code without internal knowledge.
Adding fixed salt was
common since `crypt()` was not good enough used to be. In addition, maximum
password length
is not decided by us, but decided by app developers. Therefore, we are
better to provide/explain
workaround for `password_hash()` limitation.

Prehash in PHP is not an option as we don't want PHP only `crypt()`. Prehash
by developer is
acceptable workaround for me. As you know, chars that are used in password
is limited. Some
developers even allow UTF-8 for password, structured encoding could reduce
total number of bits
in password hash with limited password length. Prehash with raw SHA512 will
give us adequate
data for `PASSWORD_BCRYPT` hashing regardless of password length.

Prehash ruins password_*() flexibility for sure, but there is workaround
also. Developer may use
timestamp to check new hash (e.g. 1024 bits hash, etc) should be used or
not.

If we don't want such workarounds, we may enable SHA512 hash for
 `password_hash()` for those
who don't want password length limit.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #75736 — David Muir — 2014-07-21T05:53:34+00:00

URL: https://staging.externals.io/message/75570#75736 · In reply to: #75732

> Hi Anthony,
> 
> I want to finish and close this issue.
> 
> 
> 
> > […]
> I wrote
> 
> "Use of <function>crypt</function> is deprecated."
> 
> not
> 
> "crypt() is deprecated". I didn't mean `crypt()` function deprecation. If
> it's confusing, I don't mind at all to rewrite it.
> BTW, what part is wrong?
> 
> It seems we have misunderstanding each other, but the basis is the same, I
> suppose.
> 
> - `crypt()` will remain
> - User/developer should use password_*()
> - It's not good idea to have PHP own `crypt()`
> 
> The differences are `E_NOTICE` and workaround, it seems.
> IMO, `password_hash()` must raise `E_NOTICE` for too long password. Truncation
> without error is
> not an option for me. People write stupid code without internal knowledge.
> Adding fixed salt was
> common since `crypt()` was not good enough used to be. In addition, maximum
> password length
> is not decided by us, but decided by app developers. Therefore, we are
> better to provide/explain
> workaround for `password_hash()` limitation.
> 
> Prehash in PHP is not an option as we don't want PHP only `crypt()`. Prehash
> by developer is
> acceptable workaround for me. As you know, chars that are used in password
> is limited. Some
> developers even allow UTF-8 for password, structured encoding could reduce
> total number of bits
> in password hash with limited password length. Prehash with raw SHA512 will
> give us adequate
> data for `PASSWORD_BCRYPT` hashing regardless of password length.
> 
> Prehash ruins password_*() flexibility for sure, but there is workaround
> also. Developer may use
> timestamp to check new hash (e.g. 1024 bits hash, etc) should be used or
> not.
> 
> If we don't want such workarounds, we may enable SHA512 hash for
> `password_hash()` for those
> who don't want password length limit.
> 
> Regards,
> 
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net


Yasuo, 

Prehashing with sha512 means it is no longer blowfish. It is now a non-vetted DIY algorithm. The whole point of password_hash is to avoid this type of thing, and should be clearly discouraged in the documentation.

It's a classic example of what not to do.

David

---

## #75739 — Yasuo Ohgaki — 2014-07-21T06:17:01+00:00

URL: https://staging.externals.io/message/75570#75739 · In reply to: #75736

Hi David,



> Prehashing with sha512 means it is no longer blowfish. It is now a
> non-vetted DIY algorithm. The whole point of password_hash is to avoid this
> type of thing, and should be clearly discouraged in the documentation.
>

I agree. It's far better if it could handle limitless password length.
The problem is "there is no way to achieve this with current
implementation".

It's a classic example of what not to do.
>

I agree here, too. We are better to have algorithm that does not enforce
user/developer to certain password and recommend "Just use it".

However, Using multiple hashes for better security is common technique.
An example is SSL. So I would not say one should not. Especially when there
is a limitation.

In old days, `crypt()` was unusable securely. There are many users/developers
that
are used to have static slat. Code like below disables authentication
completely.

password_hash(hash('sha512', SOME_SECRET_SALT).$password, DEFAULT);

This should be prevented. (I would like to prevent it by raising `E_NOTICE` 
error)

If we would like to recommend "Just use it", we may consider adding SHA512
to `password_hash()`.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

Next page: https://staging.externals.io/message/75570.md?page=2
