From edd01c62855ff5d1b0ef50a1d9350718cb033c84 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Fri, 24 Oct 2025 15:10:12 -0700 Subject: Remove all metadata --- pwhash.go | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) (limited to 'pwhash.go') diff --git a/pwhash.go b/pwhash.go index 2d7a70f..31f1487 100644 --- a/pwhash.go +++ b/pwhash.go @@ -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) { -- cgit v1.3.1