Skip to content

Commit 93e73b9

Browse files
committed
Fix xor
1 parent 55d7dfb commit 93e73b9

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

mysql/util.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ func CalcNativePassword(scramble, password []byte) []byte {
5656
return Xor(scrambleHash, stage1)
5757
}
5858

59-
// Xor returns a new slice with hash1 XOR hash2
59+
// Xor returns a new slice with hash1 XOR hash2, wrapping hash2 if hash1 is longer.
6060
func Xor(hash1 []byte, hash2 []byte) []byte {
61-
l := min(len(hash1), len(hash2))
62-
result := make([]byte, l)
63-
for i := range l {
64-
result[i] = hash1[i] ^ hash2[i]
61+
result := make([]byte, len(hash1))
62+
for i := range hash1 {
63+
result[i] = hash1[i] ^ hash2[i%len(hash2)]
6564
}
6665
return result
6766
}

0 commit comments

Comments
 (0)