Skip to content

Commit

Permalink
Merge pull request #3 from moorereason/master
Browse files Browse the repository at this point in the history
Refactor SecureCompare.
  • Loading branch information
Rafe Colton committed Nov 10, 2014
2 parents b89e340 + 34ca52c commit 2bc7010
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package vauth

import (
"github.com/martini-contrib/auth"
"crypto/subtle"
)

// SecureCompare performs a constant time compare of two strings to limit timing attacks.
func SecureCompare(given string, actual string) bool {
return auth.SecureCompare(given, actual)
func SecureCompare(x string, y string) bool {
if len(x) != len(y) {
return false
}

return subtle.ConstantTimeCompare([]byte(x), []byte(y)) == 1
}

0 comments on commit 2bc7010

Please sign in to comment.