summaryrefslogtreecommitdiffstats
path: root/internal/pwhash/pwhash.go
blob: 5a2082dc684ce46fafcc21c1490789c014700aa7 (plain) (blame)
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
27
28
29
30
31
32
33
34
35
36
// Copyright 2026 Rose Hogenson <r@roseh.moe>
//
// This file is part of roseh.moe.
//
// roseh.moe is free software: you can redistribute it and/or modify it
// under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// roseh.moe is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public
// License along with roseh.moe. If not,
// see <https://www.gnu.org/licenses/>.

package pwhash

import (
	"crypto/pbkdf2"
	"crypto/sha512"
)

const SaltSize = 8

const defaultIter = 12175430 // from tools/finditer

func HashIter(password string, salt []byte, iter int) ([]byte, error) {
	return pbkdf2.Key(sha512.New, password, salt, iter, 32)
}

func Hash(password string, salt []byte) ([]byte, error) {
	return HashIter(password, salt, defaultIter)
}