summaryrefslogtreecommitdiffstats
path: root/internal/pwhash/pwhash.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pwhash/pwhash.go')
-rw-r--r--internal/pwhash/pwhash.go44
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
-}