Skip to content

Commit 4bbe25b

Browse files
committed
refactored scramblePassword
1 parent 77acdcc commit 4bbe25b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

utils.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,25 @@ func scramblePassword(scramble, password []byte) []byte {
8989
// stage1Hash = SHA1(password)
9090
crypt := sha1.New()
9191
crypt.Write(password)
92-
stage1Hash := crypt.Sum(nil)
92+
stage1 := crypt.Sum(nil)
9393

9494
// scrambleHash = SHA1(scramble + SHA1(stage1Hash))
9595
// inner Hash
9696
crypt.Reset()
97-
crypt.Write(stage1Hash)
98-
scrambleHash := crypt.Sum(nil)
97+
crypt.Write(stage1)
98+
hash := crypt.Sum(nil)
9999

100100
// outer Hash
101101
crypt.Reset()
102102
crypt.Write(scramble)
103-
crypt.Write(scrambleHash)
104-
scrambleHash = crypt.Sum(nil)
103+
crypt.Write(hash)
104+
scramble = crypt.Sum(nil)
105105

106106
// token = scrambleHash XOR stage1Hash
107-
result := make([]byte, 20)
108-
for i := range result {
109-
result[i] = scrambleHash[i] ^ stage1Hash[i]
107+
for i := range scramble {
108+
scramble[i] ^= stage1[i]
110109
}
111-
return result
110+
return scramble
112111
}
113112

114113
/******************************************************************************

0 commit comments

Comments
 (0)