Which hash algorithm is most secure for passwords?

2019-02-25 00:37发布

问题:

According to http://php.net/manual/en/function.hash.php, there is a php hashing method: hash(). It supports all of the below methods, but I'm wondering, what is the absolute most secure method for password hashing.

Results: (in microseconds)
   1.  md4                           5307.912
   2.  md5                           6890.058
   3.  crc32b                        7298.946
   4.  crc32                         7561.922
   5.  sha1                          8886.098
   6.  tiger128,3                    11054.992
   7.  haval192,3                    11132.955
   8.  haval224,3                    11160.135
   9.  tiger160,3                    11162.996
  10.  haval160,3                    11242.151
  11.  haval256,3                    11327.981
  12.  tiger192,3                    11630.058
  13.  haval128,3                    11880.874
  14.  tiger192,4                    14776.945
  15.  tiger128,4                    14871.12
  16.  tiger160,4                    14946.937
  17.  haval160,4                    15661.954
  18.  haval192,4                    15717.029
  19.  haval256,4                    15759.944
  20.  adler32                       15796.184
  21.  haval128,4                    15887.022
  22.  haval224,4                    16047.954
  23.  ripemd256                     16245.126
  24.  haval160,5                    17818.927
  25.  haval128,5                    17887.115
  26.  haval224,5                    18085.002
  27.  haval192,5                    18135.07
  28.  haval256,5                    18678.903
  29.  sha256                        19020.08
  30.  ripemd128                     20671.844
  31.  ripemd160                     21853.923
  32.  ripemd320                     22425.889
  33.  sha384                        45102.119
  34.  sha512                        45655.965
  35.  gost                          57237.148
  36.  whirlpool                     64682.96
  37.  snefru                        80352.783
  38.  md2                           705397.844

回答1:

None of the above.

You should use bcrypt.



回答2:

what is the absolute most secure method for password hashing

To answer on the premise of the question: The absolute most secure will probably a composition of:

  1. First a Hardware Security Module, using HMAC with a secret key managed by the HSM,
  2. followed by hashing with the winner of the Password Hashing Competition, once that winner has been found, and has had 5-10 years of exposure to the real world and peer reviews.

Until that time, the most secure is probably:

  1. A HSM as above, and
  2. One of the good choices from the canonical answer on password hashing.

However, realistically password hashing isn't at major issue, and just hashing with any one of the 'good' solutions will more than suffice. The good solutions are:

  1. BCrypt,
  2. PBKDF2 with HMAC with SHA256 (or 512).
  3. And many people also consider SCrypt a strong choice, though some consider it a tad young.

For both of the above you should not roll your own composition. You should always use a mature, well tested and vetted library designed for long term password storage. Password hashing isn't only about using BCrypt or PBKDF2, you want a composition with sensible default values for character encodings, salt, iteration count/cost factors, etc.



标签: php security