From 66e4d0829d919d575bf23d5b6bb76e69bde0c3c8 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 7 Dec 2025 14:46:56 -0800 Subject: Increase target security to 32 bytes --- tools/finditer/finditer.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tools/finditer/finditer.go (limited to 'tools/finditer') diff --git a/tools/finditer/finditer.go b/tools/finditer/finditer.go new file mode 100644 index 0000000..e788d89 --- /dev/null +++ b/tools/finditer/finditer.go @@ -0,0 +1,42 @@ +package main + +import ( + "encoding/hex" + "fmt" + "sort" + "testing" + "time" + + "roseh.moe/cmd/roseh.moe/internal/pwhash" +) + +func mustHex(s string) []byte { + b, err := hex.DecodeString(s) + if err != nil { + panic(err) + } + return b +} + +var salt = mustHex("34539b5dd2591415") + +func benchmarkHashIter(iter int) time.Duration { + const password = "wavy upend 4z jk linda k zing four atop pi" + return time.Duration(testing.Benchmark(func(b *testing.B) { + for b.Loop() { + pwhash.HashIter(password, salt, iter) + } + }).NsPerOp()) +} + +func main() { + const targetTime = 5 * time.Second + iter := 8192 + for ; benchmarkHashIter(iter) < targetTime; iter *= 2 { + } + lo := iter / 2 + hi := iter + fmt.Println(lo + sort.Search(hi-lo, func(n int) bool { + return benchmarkHashIter(lo+n) > targetTime + })) +} -- cgit v1.3.1