summaryrefslogtreecommitdiffstats
path: root/tools/finditer
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-10-07 08:31:39 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-10-07 08:41:15 -0700
commitbcc1c2d9dd7fefa538647c0d4e9e621511f1fde6 (patch)
tree64bd8f2b15dd3a737ae8d2db683641474acaff3f /tools/finditer
parent65b1ed1ff56e4d795c67d4d0b31634decec7767b (diff)
downloadroseh.moe-bcc1c2d9dd7fefa538647c0d4e9e621511f1fde6.tar.zst
Bring back pbkdf2
Diffstat (limited to 'tools/finditer')
-rw-r--r--tools/finditer/finditer.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/finditer/finditer.go b/tools/finditer/finditer.go
new file mode 100644
index 0000000..fbd0363
--- /dev/null
+++ b/tools/finditer/finditer.go
@@ -0,0 +1,43 @@
+package main
+
+import (
+ "encoding/hex"
+ "fmt"
+ "sort"
+ "testing"
+ "time"
+
+ "gitlab.com/rhogenson/roseh.moe/internal/pwhash"
+)
+
+func mustHex(s string) []byte {
+ b, err := hex.DecodeString(s)
+ if err != nil {
+ panic(err)
+ }
+ return b
+}
+
+const password = "emcee polio cardiac disclose superglue clapper cruelness stonework tingly unarmored"
+
+var salt = mustHex("a0aa6971f38827e5")
+
+var iterations int
+
+func BenchmarkHashIter(b *testing.B) {
+ for b.Loop() {
+ pwhash.HashIter(password, salt, iterations)
+ }
+}
+
+func main() {
+ const targetDuration = 5 * time.Second
+ for iterations = 8192; time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) < targetDuration; 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()) > targetDuration
+ }))
+}