Skip to content

Commit

Permalink
util: Address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
shenli committed Oct 7, 2015
1 parent 58d3c37 commit a926f6f
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions util/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,21 @@ import (
// CalcPassword is the algorithm convert hashed password to auth string.
// See: https://dev.mysql.com/doc/internals/en/secure-password-authentication.html
// SHA1( password ) XOR SHA1( "20-bytes random data from server" <concat> SHA1( SHA1( password ) ) )
func CalcPassword(scramble, password []byte) []byte {
if len(password) == 0 {
func CalcPassword(scramble, sha1pwd []byte) []byte {
if len(sha1pwd) == 0 {
return nil
}

// scrambleHash = SHA1(scramble + SHA1(stage1Hash))
stage1 := password
// scrambleHash = SHA1(scramble + SHA1(sha1pwd))
// inner Hash
hash := Sha1Hash(stage1)
hash := Sha1Hash(sha1pwd)
// outer Hash
crypt := sha1.New()
crypt.Write(scramble)
crypt.Write(hash)
scramble = crypt.Sum(nil)

// token = scrambleHash XOR stage1Hash
for i := range scramble {
scramble[i] ^= stage1[i]
scramble[i] ^= sha1pwd[i]
}
return scramble
}
Expand Down

1 comment on commit a926f6f

@qiuyesuifeng
Copy link
Member

Choose a reason for hiding this comment

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

LGTM

Please sign in to comment.