diff options
| -rw-r--r-- | internal/pwhash/pwhash.go | 2 | ||||
| -rw-r--r-- | tools/finditer/finditer.go | 18 |
2 files changed, 10 insertions, 10 deletions
diff --git a/internal/pwhash/pwhash.go b/internal/pwhash/pwhash.go index 22b5368..d8a1b33 100644 --- a/internal/pwhash/pwhash.go +++ b/internal/pwhash/pwhash.go @@ -7,7 +7,7 @@ import ( const SaltSize = 8 -const defaultIter = 12500992 // from tools/finditer +const defaultIter = 12175430 // from tools/finditer func HashIter(password string, salt []byte, iter int) ([]byte, error) { return pbkdf2.Key(sha512.New, password, salt, iter, 32) diff --git a/tools/finditer/finditer.go b/tools/finditer/finditer.go index 99c17ee..a56c7fa 100644 --- a/tools/finditer/finditer.go +++ b/tools/finditer/finditer.go @@ -20,23 +20,23 @@ func mustHex(s string) []byte { var salt = mustHex("34539b5dd2591415") -func benchmarkHashIter(iter int) time.Duration { +var iter int + +func BenchmarkHashIter(b *testing.B) { 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()) + for b.Loop() { + pwhash.HashIter(password, salt, iter) + } } func main() { const targetTime = 5 * time.Second - iter := 8192 - for ; benchmarkHashIter(iter) < targetTime; iter *= 2 { + for iter = 8192; time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) < targetTime; iter *= 2 { } lo := iter / 2 hi := iter fmt.Println(lo + sort.Search(hi-lo, func(n int) bool { - return benchmarkHashIter(lo+n) > targetTime + iter = lo + n + return time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) > targetTime })) } |
