From 35469f25cd53707b3e801caaff49121926bb7238 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Wed, 24 Sep 2025 17:25:46 -0700 Subject: Rename cmd -> tools --- cmd/finditers/finditers.go | 44 -------------------------------------------- cmd/hashpw/hashpw.go | 34 ---------------------------------- tools/finditers/finditers.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ tools/hashpw/hashpw.go | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 78 deletions(-) delete mode 100644 cmd/finditers/finditers.go delete mode 100644 cmd/hashpw/hashpw.go create mode 100644 tools/finditers/finditers.go create mode 100644 tools/hashpw/hashpw.go diff --git a/cmd/finditers/finditers.go b/cmd/finditers/finditers.go deleted file mode 100644 index 2a256c8..0000000 --- a/cmd/finditers/finditers.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "encoding/hex" - "fmt" - "os" - "sort" - "testing" - "time" - - "gitlab.com/rhogenson/roseh.moe/internal/pwhash" -) - -var ( - iterations int - - salt, _ = hex.DecodeString("3fb84513fc3afcd6d3b230bf9ece91aaae2d2a99da17efbf7de83b21fafe3f08") -) - -func BenchmarkHashIter(b *testing.B) { - const password = "oboe shortness ether ideology undesired fresh freezable catching mashing glimpse" - for b.Loop() { - pwhash.HashIter(password, salt, iterations) - } -} - -func run() error { - for iterations = 8192; time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) < 500*time.Millisecond; iterations *= 2 { - } - lo := iterations / 2 - hi := iterations - fmt.Println(lo + sort.Search(hi-lo, func(i int) bool { - iterations = lo + i - return time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) > 500*time.Millisecond - })) - return nil -} - -func main() { - if err := run(); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } -} diff --git a/cmd/hashpw/hashpw.go b/cmd/hashpw/hashpw.go deleted file mode 100644 index 5bc740d..0000000 --- a/cmd/hashpw/hashpw.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "crypto/rand" - "fmt" - "os" - - "gitlab.com/rhogenson/roseh.moe/internal/pwhash" - "golang.org/x/term" -) - -func run() error { - fmt.Print("Enter password:") - password, err := term.ReadPassword(int(os.Stdin.Fd())) - fmt.Println() - if err != nil { - return err - } - salt := make([]byte, pwhash.SaltLen) - rand.Read(salt) - _, hashedPassword, err := pwhash.Hash(string(password), salt) - if err != nil { - return err - } - fmt.Printf("notepad-password=%x%x\n", salt, hashedPassword) - return nil -} - -func main() { - if err := run(); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } -} diff --git a/tools/finditers/finditers.go b/tools/finditers/finditers.go new file mode 100644 index 0000000..2a256c8 --- /dev/null +++ b/tools/finditers/finditers.go @@ -0,0 +1,44 @@ +package main + +import ( + "encoding/hex" + "fmt" + "os" + "sort" + "testing" + "time" + + "gitlab.com/rhogenson/roseh.moe/internal/pwhash" +) + +var ( + iterations int + + salt, _ = hex.DecodeString("3fb84513fc3afcd6d3b230bf9ece91aaae2d2a99da17efbf7de83b21fafe3f08") +) + +func BenchmarkHashIter(b *testing.B) { + const password = "oboe shortness ether ideology undesired fresh freezable catching mashing glimpse" + for b.Loop() { + pwhash.HashIter(password, salt, iterations) + } +} + +func run() error { + for iterations = 8192; time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) < 500*time.Millisecond; iterations *= 2 { + } + lo := iterations / 2 + hi := iterations + fmt.Println(lo + sort.Search(hi-lo, func(i int) bool { + iterations = lo + i + return time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) > 500*time.Millisecond + })) + return nil +} + +func main() { + if err := run(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} diff --git a/tools/hashpw/hashpw.go b/tools/hashpw/hashpw.go new file mode 100644 index 0000000..5bc740d --- /dev/null +++ b/tools/hashpw/hashpw.go @@ -0,0 +1,34 @@ +package main + +import ( + "crypto/rand" + "fmt" + "os" + + "gitlab.com/rhogenson/roseh.moe/internal/pwhash" + "golang.org/x/term" +) + +func run() error { + fmt.Print("Enter password:") + password, err := term.ReadPassword(int(os.Stdin.Fd())) + fmt.Println() + if err != nil { + return err + } + salt := make([]byte, pwhash.SaltLen) + rand.Read(salt) + _, hashedPassword, err := pwhash.Hash(string(password), salt) + if err != nil { + return err + } + fmt.Printf("notepad-password=%x%x\n", salt, hashedPassword) + return nil +} + +func main() { + if err := run(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} -- cgit v1.3.1