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 Jun 26, 2023
1 parent 290613a commit 4e151f6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 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,11 @@ func IsValidHash(s string) bool {

// XOR takes two byte slices, XORs them together, returns the resulting slice.
func XOR(a, b []byte) []byte {
c := make([]byte, len(a))
for i := 0; i < len(a); i++ {
c[i] = a[i] ^ b[i]
if len(a) != len(b) {
panic("unmatched slices lengths")
}

c := make([]byte, len(a))
subtle.XORBytes(c, a, b)
return c
}

0 comments on commit 4e151f6

Please sign in to comment.