summaryrefslogtreecommitdiffstats
path: root/internal/pwhash/pwhash.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-09-25 17:54:29 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-09-25 17:54:29 -0700
commit251ea4f8fcfd0960f6a627501eb556e109a3e2b6 (patch)
tree4bcc15172503228559b22ee31dacf5ba2a118971 /internal/pwhash/pwhash.go
parent69cd1c740997cf2ccb6a710826a06ee82e41dbe7 (diff)
downloadroseh.moe-251ea4f8fcfd0960f6a627501eb556e109a3e2b6.tar.zst
Use AES-CTR-HMAC-SHA256 instead of AES-GCM
Diffstat (limited to 'internal/pwhash/pwhash.go')
-rw-r--r--internal/pwhash/pwhash.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/internal/pwhash/pwhash.go b/internal/pwhash/pwhash.go
index d886746..9ef5d2a 100644
--- a/internal/pwhash/pwhash.go
+++ b/internal/pwhash/pwhash.go
@@ -1,24 +1,33 @@
package pwhash
import (
+ "crypto/hkdf"
"crypto/pbkdf2"
- "crypto/sha512"
+ "crypto/sha256"
)
-const SaltLen = sha512.Size
+const SaltLen = 2 * sha256.Size
-const defaultIterations = 1220340 // from cmd/finditers
+const defaultIterations = 3749890 // from cmd/finditers
func HashIter(password string, salt []byte, iter int) ([]byte, error) {
- return pbkdf2.Key(sha512.New, password, salt, iter, sha512.Size)
+ return pbkdf2.Key(sha256.New, password, salt, iter, sha256.Size)
}
-func Hash(password string, salt []byte) (key, pwHash []byte, err error) {
- const aesKeySize = 32
+func Hash(password string, salt []byte) (rawKey, pwHash []byte, err error) {
+ const hashLen = 32
- key, err = HashIter(password, salt, defaultIterations)
+ key, err := HashIter(password, salt[:sha256.Size], defaultIterations)
if err != nil {
return nil, nil, err
}
- return key[:aesKeySize], key[aesKeySize:], nil
+ key, err = hkdf.Extract(sha256.New, key, salt[sha256.Size:])
+ if err != nil {
+ return nil, nil, err
+ }
+ pwHash, err = hkdf.Expand(sha256.New, key, "pwhash", hashLen)
+ if err != nil {
+ return nil, nil, err
+ }
+ return key, pwHash, nil
}