Skip to content

Commit 82f6571

Browse files
gdsmithlance6716
andauthored
Apply suggestions from code review
Co-authored-by: lance6716 <[email protected]>
1 parent 0578e29 commit 82f6571

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

mysql/util.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func NativePasswordHash(password []byte) []byte {
106106
// stage2Hash = SHA1(stage1Hash)
107107
crypt.Reset()
108108
crypt.Write(stage1)
109-
return crypt.Sum(nil)
109+
return crypt.Sum(stage1[:0])
110110
}
111111

112112
func CompareNativePassword(reply []byte, stored []byte, seed []byte) bool {
@@ -117,13 +117,11 @@ func CompareNativePassword(reply []byte, stored []byte, seed []byte) bool {
117117
// hash_stage1 = xor(reply, sha1(public_seed, hash_stage2))
118118
stage1 := stage1FromReply(reply, seed, stored)
119119
// andidate_hash2 = sha1(hash_stage1)
120-
crypt := sha1.New()
121-
crypt.Write(stage1)
122-
stage2 := crypt.Sum(nil)
120+
stage2 := sha1.Sum(stage1)
123121

124122
// check(candidate_hash2 == hash_stage2)
125123
// use ConstantTimeCompare to mitigate timing based attacks
126-
return subtle.ConstantTimeCompare(stage2, stored) == 1
124+
return subtle.ConstantTimeCompare(stage2[:], stored) == 1
127125
}
128126

129127
// CalcCachingSha2Password: Hash password using MySQL 8+ method (SHA256)

0 commit comments

Comments
 (0)