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

crypto/subtle: ConstantTimeCompare might give a false-positive on differing lengths #8131

Closed
gopherbot opened this issue Jun 1, 2014 · 1 comment

Comments

@gopherbot
Copy link

by justinas@justinas.me:

What does 'go version' print?
go version go1.2.2 darwin/amd64

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. Compare two byte slices with ConstantTimeCompare(), where the second slice is longer
and the first slice is a prefix of the second.

http://play.golang.org/p/XH0gRhdDTu

What happened?

The function compares slices only up to the length of the first slice and thus gives a
false-positive.

What should have happened instead?

I understand that this is not the way this function is supposed to be used. However, the
behavior on this incorrect usage varies based on the order of the arguments. 

I think that panicking (due to out-of-range access), as the function does when the
*first* slice is longer, is a much better solution. Panic clearly indicates a mistake on
the programmer's part, whereas passing silently can go unnoticed for a long time and
even be exploited.

It's a simple fix to do, I think: instead of iterating up to len(x), iterate up to
max(len(x), len(y)).
@ianlancetaylor
Copy link
Contributor

Comment 1:

Status changed to Duplicate.

Merged into issue #7304.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants