New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calibrate with fixed r #13
Conversation
@FiloSottile - mind taking a look at this as well? More eyes always good. |
Failed in Go 1.7 - restarted the build. $ go test -v ./...
=== RUN TestGenerateRandomBytes
--- PASS: TestGenerateRandomBytes (0.00s)
=== RUN TestGenerateFromPassword
--- PASS: TestGenerateFromPassword (9.47s)
=== RUN TestCompareHashAndPassword
--- PASS: TestCompareHashAndPassword (0.18s)
=== RUN TestCost
--- PASS: TestCost (0.06s)
=== RUN TestDecodeHash
--- PASS: TestDecodeHash (0.00s)
=== RUN TestCalibrate
--- FAIL: TestCalibrate (10.40s)
scrypt_test.go:140: GenerateFromPassword with scrypt.Params{N:131072, R:8, P:1, SaltLen:16, DKLen:32} took 472.320073ms (<nil>)
scrypt_test.go:140: GenerateFromPassword with scrypt.Params{N:131072, R:8, P:1, SaltLen:16, DKLen:32} took 506.033718ms (<nil>)
scrypt_test.go:140: GenerateFromPassword with scrypt.Params{N:65536, R:8, P:1, SaltLen:16, DKLen:32} took 230.961435ms (<nil>)
scrypt_test.go:145: 2. GenerateFromPassword was too fast (wanted around 500ms, got 230.961435ms) with scrypt.Params{N:65536, R:8, P:1, SaltLen:16, DKLen:32}.
scrypt_test.go:140: GenerateFromPassword with scrypt.Params{N:32768, R:8, P:4, SaltLen:16, DKLen:32} took 657.942582ms (<nil>)
scrypt_test.go:140: GenerateFromPassword with scrypt.Params{N:16384, R:8, P:8, SaltLen:16, DKLen:32} took 495.989112ms (<nil>)
scrypt_test.go:140: GenerateFromPassword with scrypt.Params{N:8192, R:8, P:17, SaltLen:16, DKLen:32} took 463.957228ms (<nil>)
scrypt_test.go:140: GenerateFromPassword with scrypt.Params{N:4096, R:8, P:34, SaltLen:16, DKLen:32} took 520.679261ms (<nil>)
scrypt_test.go:140: GenerateFromPassword with scrypt.Params{N:512, R:8, P:280, SaltLen:16, DKLen:32} took 527.884269ms (<nil>)
FAIL
exit status 1
FAIL github.com/elithrar/simple-scrypt 20.183s
The command "go test -v ./..." exited with 1. |
It works perfectly fine on windows, but on linux not at all. The measured runtime of GenerateFromPassword() with the same parameters varies on my linux system by about 50ms to 100ms. This may be related to #8. |
The problem is that in a CI, or other contended environment, a +/- 250ms difference on a 500ms target isn't that absurd given the "expense" of scrypt. Calibration, being what it is, isn't perfect. Proposing:
|
This should work better. It's slower but the results are more consistent. I ran the tests 20 times and had no failures. This might also fix #8. TestCalibrate fails around 80% percent of the time with the old Calibrate function on my computer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost done!
scrypt_test.go
Outdated
@@ -140,7 +143,7 @@ func TestCalibrate(t *testing.T) { | |||
} | |||
if dur < timeout/2 { | |||
t.Errorf("%d. GenerateFromPassword was too fast (wanted around %s, got %s) with %#v.", testNum, timeout, dur, p) | |||
} else if timeout*2 < dur { | |||
} else if timeout+timeout/2 < dur { | |||
t.Errorf("%d. GenerateFromPassword took too long (wanted around %s, got %s) with %#v.", testNum, timeout, dur, p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but one last ask: can you change the error message to detail what "around" means - e.g. "expected between {lower bound} and {upper bound}".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes of course
[edit by @elithrar]: Addresses #12