summaryrefslogtreecommitdiffstats
path: root/tools/finditers/finditers.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-09-26 09:12:27 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-09-26 09:12:27 -0700
commit768d3629b938196d132b80864204d7b6a9683a9e (patch)
treea147fbd27c911b6a1ec38c6492c02fd5f7b93456 /tools/finditers/finditers.go
parentFix test (diff)
downloadroseh.moe-768d3629b938196d132b80864204d7b6a9683a9e.tar.zst
Turn up all the parameters
Hopefully this makes it secure 😳
Diffstat (limited to 'tools/finditers/finditers.go')
-rw-r--r--tools/finditers/finditers.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/tools/finditers/finditers.go b/tools/finditers/finditers.go
index cd144fa..746242b 100644
--- a/tools/finditers/finditers.go
+++ b/tools/finditers/finditers.go
@@ -1,8 +1,8 @@
package main
import (
- "encoding/hex"
"fmt"
+ "math/rand/v2"
"os"
"sort"
"testing"
@@ -11,18 +11,17 @@ import (
"gitlab.com/rhogenson/roseh.moe/internal/cryptoutil"
)
-func mustHex(s string) []byte {
- bytes, err := hex.DecodeString(s)
- if err != nil {
- panic(fmt.Sprintf("mustHex: bad hex %q: %s", s, err))
- }
- return bytes
-}
-
var (
iterations int
- salt = mustHex("3fb84513fc3afcd6d3b230bf9ece91aaae2d2a99da17efbf7de83b21fafe3f08")
+ salt = func() []byte {
+ r := rand.New(new(rand.PCG))
+ salt := make([]byte, cryptoutil.SaltSize)
+ for i := range salt {
+ salt[i] = byte(r.IntN(256))
+ }
+ return salt
+ }()
)
func BenchmarkHashIter(b *testing.B) {
@@ -33,13 +32,15 @@ func BenchmarkHashIter(b *testing.B) {
}
func run() error {
- for iterations = 8192; time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) < 500*time.Millisecond; iterations *= 2 {
+ const targetDuration = 2 * 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()) > 500*time.Millisecond
+ return time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) > targetDuration
}))
return nil
}