Skip to content

Commit

Permalink
util: use subtle for XORing bytes
Browse files Browse the repository at this point in the history
Fixes #377
  • Loading branch information
Jorropo committed Sep 27, 2023
1 parent 56861d6 commit ec910c3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package util

import (
"crypto/subtle"
"errors"
"io"
"math/rand"
Expand Down Expand Up @@ -150,9 +151,9 @@ func IsValidHash(s string) bool {

// XOR takes two byte slices, XORs them together, returns the resulting slice.
func XOR(a, b []byte) []byte {
_ = b[len(a)-1] // keeping same behaviour as previously but this looks like a bug

c := make([]byte, len(a))
for i := 0; i < len(a); i++ {
c[i] = a[i] ^ b[i]
}
subtle.XORBytes(c, a, b)
return c
}

0 comments on commit ec910c3

Please sign in to comment.