summaryrefslogtreecommitdiffstats
path: root/internal/pwhash/pwhash.go
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@google.com>2025-09-24 08:40:19 -0700
committerRose Hogenson <rhogenson@google.com>2025-09-24 08:40:19 -0700
commite7443a7600fe6ce9fcb2692714db290254cb32ac (patch)
treee27e07936bf5a15651aaee94950daa9e7f4bdd33 /internal/pwhash/pwhash.go
parent501984f2d350470043d7f84e57a47671759f4eca (diff)
downloadroseh.moe-e7443a7600fe6ce9fcb2692714db290254cb32ac.tar.zst
Use PBKDF2-HMAC-SHA512 for key derivation
Diffstat (limited to 'internal/pwhash/pwhash.go')
-rw-r--r--internal/pwhash/pwhash.go26
1 files changed, 7 insertions, 19 deletions
diff --git a/internal/pwhash/pwhash.go b/internal/pwhash/pwhash.go
index f343d70..3074b0c 100644
--- a/internal/pwhash/pwhash.go
+++ b/internal/pwhash/pwhash.go
@@ -1,36 +1,24 @@
package pwhash
import (
- "crypto/hkdf"
"crypto/pbkdf2"
- "crypto/sha256"
"crypto/sha512"
- "fmt"
)
-const SaltLen = sha256.Size + sha512.Size
+const SaltLen = sha512.Size
-const defaultIterations = 3670016 // from cmd/finditers
+const defaultIterations = 903636 // from cmd/finditers
func HashIter(password string, salt []byte, iter int) ([]byte, error) {
- return pbkdf2.Key(sha256.New, password, salt, iter, sha256.Size)
+ return pbkdf2.Key(sha512.New, password, salt, iter, sha512.Size)
}
func Hash(password string, salt []byte) (key, pwHash []byte, err error) {
- if len(salt) != SaltLen {
- return nil, nil, fmt.Errorf("bad salt size")
- }
- hashedPassword, err := HashIter(password, salt[:sha256.Size], defaultIterations)
- if err != nil {
- return nil, nil, err
- }
- key, err = hkdf.Extract(sha512.New, hashedPassword, salt[sha256.Size:])
- if err != nil {
- return nil, nil, err
- }
- pwHash, err = hkdf.Expand(sha512.New, key, "auth", sha512.Size)
+ const aesKeySize = 32
+
+ key, err = HashIter(password, salt, defaultIterations)
if err != nil {
return nil, nil, err
}
- return key, pwHash, nil
+ return key[:aesKeySize], key[aesKeySize:], nil
}