diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-10-06 21:08:45 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-10-06 21:08:45 -0700 |
| commit | c5a5b24cf6370ab549c033b20ad0389ec3ce8ec1 (patch) | |
| tree | dfd8b0914e2021fdd75e65c1db1beadbb51f74d9 /internal/pwhash | |
| parent | d35bbbd54ed3de79d2a7d709013ff49d4a9413b8 (diff) | |
| download | roseh.moe-c5a5b24cf6370ab549c033b20ad0389ec3ce8ec1.tar.zst | |
Simplify simplify simplify
Diffstat (limited to 'internal/pwhash')
| -rw-r--r-- | internal/pwhash/pwhash.go | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/internal/pwhash/pwhash.go b/internal/pwhash/pwhash.go deleted file mode 100644 index c3c11ff..0000000 --- a/internal/pwhash/pwhash.go +++ /dev/null @@ -1,44 +0,0 @@ -package pwhash - -import ( - "crypto/pbkdf2" - "crypto/rand" - "crypto/sha512" - "crypto/subtle" - "errors" -) - -const defaultIter = 12504615 // from tools/finditers - -func HashIter(pw string, salt []byte, iter int) ([]byte, error) { - return pbkdf2.Key(sha512.New, pw, salt, iter, 32) -} - -func Hash(pw string) ([]byte, error) { - buf := make([]byte, 40) - salt := buf[32:] - rand.Read(salt) - hash, err := HashIter(pw, salt, defaultIter) - if err != nil { - return nil, err - } - copy(buf, hash) - return buf, nil -} - -var errBadPassword = errors.New("bad password") - -func Check(pwHash []byte, pw string) error { - if len(pwHash) < 32 { - return errBadPassword - } - wantHash, salt := pwHash[:32], pwHash[32:] - gotHash, err := HashIter(pw, salt, defaultIter) - if err != nil { - return err - } - if subtle.ConstantTimeCompare(gotHash, wantHash) == 0 { - return errBadPassword - } - return nil -} |
