diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-10-24 15:10:12 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-10-24 15:10:12 -0700 |
| commit | edd01c62855ff5d1b0ef50a1d9350718cb033c84 (patch) | |
| tree | 24651fbc3774da158d36a19f8a532ed50828cf45 /pwhash.go | |
| parent | 9a08b03b83ff28a26b0c20ccebc178df29cf7312 (diff) | |
| download | sym-edd01c62855ff5d1b0ef50a1d9350718cb033c84.tar.zst | |
Remove all metadata
Diffstat (limited to 'pwhash.go')
| -rw-r--r-- | pwhash.go | 32 |
1 files changed, 2 insertions, 30 deletions
@@ -3,7 +3,6 @@ package main import ( "crypto/pbkdf2" "crypto/sha256" - "fmt" "os" "golang.org/x/term" @@ -11,35 +10,8 @@ import ( const defaultPBKDF2Iters = 35_000_000 -//go:generate go tool stringer -type=pwHash -linecomment -type pwHash int8 - -const ( - pwHashInvalid pwHash = iota - pwHashPBKDF2_HMAC_SHA256 // PBKDF2-HMAC-SHA256 -) - -type hashMetadata struct { - PasswordHashType pwHash - Iterations int32 - SaltSize int8 -} - -func (h *hashMetadata) validate() error { - if h.PasswordHashType != pwHashPBKDF2_HMAC_SHA256 { - return fmt.Errorf("invalid hash type %q", h.PasswordHashType) - } - if h.Iterations <= 0 || h.Iterations > defaultPBKDF2Iters { - return fmt.Errorf("too many iterations") - } - if h.SaltSize <= 0 || h.SaltSize > defaultSaltSize { - return fmt.Errorf("salt size too long") - } - return nil -} - -func (h *hashMetadata) hashPassword(password string, salt []byte) ([]byte, error) { - return pbkdf2.Key(sha256.New, password, salt, int(h.Iterations), 32) +func hashPassword(password string, salt []byte, iters int) ([]byte, error) { + return pbkdf2.Key(sha256.New, password, salt, iters, 32) } func termReadPassword() (string, error) { |
