aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2017-08-07 10:05:53 -0700
committerEric Biggers <ebiggers@google.com>2017-08-07 10:05:53 -0700
commit297b46e65415c7d032844b39e7504bb862e2ea28 (patch)
tree1d090510397db0e035e0f87d80d56e69ce8a7714
parent1f2945839b9230e718476b54517b1c1ec772d734 (diff)
actions: calculate password hash difficulty correctly
'fscrypt setup' is supposed to calibrate the Argon2 password hashing difficulty to 1s by default, but actually it was setting it to only 1s / num_cpus because the hashing is done with all CPUs and it is timed using the CLOCK_PROCESS_CPUTIME_ID clock, which measures the time spent by all threads in the process. Fix this by dividing the elapsed time by HashingCosts.Parallelism, which is used as the number of threads.
-rw-r--r--actions/config.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/actions/config.go b/actions/config.go
index 55010a5..81f6e4f 100644
--- a/actions/config.go
+++ b/actions/config.go
@@ -230,7 +230,7 @@ func timeHashingCosts(costs *metadata.HashingCosts) (time.Duration, error) {
}
end := cpuTimeInNanoseconds()
- return time.Duration(end - begin), nil
+ return time.Duration((end - begin) / costs.Parallelism), nil
}
// cpuTimeInNanoseconds returns the nanosecond count based on the process's CPU usage.