Skip to content
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

Merged
merged 7 commits into from Apr 2, 2018
Merged

Calibrate with fixed r #13

merged 7 commits into from Apr 2, 2018

Conversation

LouisChrist
Copy link
Contributor

@LouisChrist LouisChrist commented Apr 1, 2018

[edit by @elithrar]: Addresses #12

@elithrar
Copy link
Owner

elithrar commented Apr 1, 2018

@FiloSottile - mind taking a look at this as well? More eyes always good.

@elithrar
Copy link
Owner

elithrar commented Apr 1, 2018

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.

@LouisChrist
Copy link
Contributor Author

LouisChrist commented Apr 1, 2018

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.

@elithrar
Copy link
Owner

elithrar commented Apr 2, 2018

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:

  • The 500ms tests should be more forgiving (+/- 75%)
  • Add additional tests (e.g. 1500ms) to help with accuracy at higher absolute run times.

@LouisChrist
Copy link
Contributor Author

LouisChrist commented Apr 2, 2018

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.

Copy link
Owner

@elithrar elithrar left a 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)
Copy link
Owner

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}".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes of course

@elithrar elithrar merged commit d150773 into elithrar:master Apr 2, 2018
This was referenced Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants