summaryrefslogtreecommitdiffstats
path: root/cmd/finditers
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-09-23 21:18:49 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-09-23 21:18:49 -0700
commit09517318b87e39506cbcb3232a395ac7d43c25f5 (patch)
tree8b0698270dfc5382655b50dc6df3b5de6dd20715 /cmd/finditers
parentAdd CSRF protection (diff)
downloadroseh.moe-09517318b87e39506cbcb3232a395ac7d43c25f5.tar.zst
Use pbkdf2 for password hashing instead of sha512
Diffstat (limited to 'cmd/finditers')
-rw-r--r--cmd/finditers/finditers.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/cmd/finditers/finditers.go b/cmd/finditers/finditers.go
new file mode 100644
index 0000000..2a256c8
--- /dev/null
+++ b/cmd/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)
+ }
+}