0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

2026年、パスワードをハッシュ化して保存するには

0
Posted at

パスワードをハッシュ化して保存するには

背景

パスワードを保存する際の、セキュリティを担保するためのベストプラクティスを知らなかったため、調査した。

手順

  1. ランダムなソルトを生成
  2. ソルトとパスワードをもとにハッシュを生成
  3. ハッシュとソルトをデータベースに保存

ハッシュ化のアルゴリズム

アルゴリズム

Argon2idが良い。

こちらのOWASPの記事によると、

Argon2 was the winner of the 2015 Password Hashing Competition. Out of the three Argon2 versions, use the Argon2id variant since it provides a balanced approach to resisting both side-channel and GPU-based attacks.

Argon2は2015年のパスワードハッシュコンテストで優勝しました。Argon2には3つのバージョンがありますが、サイドチャネル攻撃とGPUベースの攻撃の両方に対してバランスの取れた対策を提供するArgon2idバージョンを使用することをお勧めします。

他にもscrypt, bcryptという選択肢もあるが、argon2が一番良いとのこと。セキュリティ的には argon2 => scrypt => bcryptといった感じの優先順位。

パラメータ

メモリ使用量m、反復回数t、並列度p のパラメータが必要であるが、以下は全て同じレベルのセキュリティである。

m=47104 (46 MiB), t=1, p=1 (Do not use with Argon2i)
m=19456 (19 MiB), t=2, p=1 (Do not use with Argon2i)
m=12288 (12 MiB), t=3, p=1
m=9216 (9 MiB), t=4, p=1
m=7168 (7 MiB), t=5, p=1
These configuration settings provide an equal level of defense, and the only difference is a trade off between CPU and RAM usage.

これらの構成設定は同等のレベルの防御を提供し、唯一の違いはCPUとRAMの使用量のトレードオフです。


迷ったら、メモリ19MiB、反復回数2、並列度1でよいと思う。後はCPUとRAMのトレードオフを考慮すればよい。

Use Argon2id with a minimum configuration of 19 MiB of memory, an iteration count of 2, and 1 degree of parallelism.

Argon2idを使用する場合は、最小構成としてメモリ19MiB、反復回数2、並列度1を設定してください。

ソルト

ソルトとは何か?なぜ必要なのか?

レインボーテーブル攻撃などからパスワードの平文を守るための、ランダムなデータ。

要約

レインボーテーブル攻撃は事前計算を行い、そのデータを使いまわせるところが利点である。しかし、ソルトを加えると、毎回ハッシュ計算を行う必要が出てくる。結果、レインボーテーブル攻撃から総当たり攻撃に格下げすることができる。

保存方法

ソルトはハッシュとともに保存してよい。

ソルトの長さ

16が推奨。

Salt length — Length of the random salt. 16 bytes is recommended for password hashing.

ソルト長 — ランダムソルトの長さ。パスワードハッシュには16バイトが推奨されます。

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?