author | Alberto Bertogli
<albertito@blitiri.com.ar> 2017-04-26 09:26:54 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2017-04-26 09:26:54 UTC |
parent | 17eff21279da881da54e95721033cc7409e2c558 |
internal/userdb/userdb.go | +4 | -2 |
diff --git a/internal/userdb/userdb.go b/internal/userdb/userdb.go index 182cc72..83f9942 100644 --- a/internal/userdb/userdb.go +++ b/internal/userdb/userdb.go @@ -33,8 +33,8 @@ package userdb //go:generate protoc --go_out=. userdb.proto import ( - "bytes" "crypto/rand" + "crypto/subtle" "errors" "fmt" "sync" @@ -210,5 +210,7 @@ func (s *Scrypt) PasswordMatches(plain string) bool { panic(fmt.Sprintf("scrypt failed: %v", err)) } - return bytes.Equal(dk, []byte(s.Encrypted)) + // This comparison should be high enough up the stack that it doesn't + // matter, but do it in constant time just in case. + return subtle.ConstantTimeCompare(dk, []byte(s.Encrypted)) == 1 }