-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
// SPDX-FileCopyrightText: 2025 Shota FUJI <pockawoooh@gmail.com>
// SPDX-License-Identifier: AGPL-3.0-only
package crypto
import (
"crypto/rand"
"golang.org/x/crypto/argon2"
)
func HashPassword(password []byte, salt []byte) []byte {
// RFC 推奨のパラメータ (Go のドキュメントに書いてあるもの)
return argon2.IDKey(password, salt, 1, 64*1024, 4, 32)
}
// SaltAndHashPassword は自動生成したソルトでパスワードをハッシュし、
// 生成されたハッシュとソルトを返す。
func SaltAndHashPassword(password []byte) ([]byte, []byte) {
salt := make([]byte, 32)
// ドキュメントに書いてあるとおり `rand.Read()` はエラーを返さない。
rand.Read(salt)
return HashPassword(password, salt), salt
}