File tree Expand file tree Collapse file tree 1 file changed +2
-26
lines changed
Expand file tree Collapse file tree 1 file changed +2
-26
lines changed Original file line number Diff line number Diff line change 88package bitutil
99
1010import (
11+ "crypto/subtle"
1112 "runtime"
1213 "unsafe"
1314)
@@ -18,32 +19,7 @@ const supportsUnaligned = runtime.GOARCH == "386" || runtime.GOARCH == "amd64" |
1819// XORBytes xors the bytes in a and b. The destination is assumed to have enough
1920// space. Returns the number of bytes xor'd.
2021func XORBytes (dst , a , b []byte ) int {
21- if supportsUnaligned {
22- return fastXORBytes (dst , a , b )
23- }
24- return safeXORBytes (dst , a , b )
25- }
26-
27- // fastXORBytes xors in bulk. It only works on architectures that support
28- // unaligned read/writes.
29- func fastXORBytes (dst , a , b []byte ) int {
30- n := len (a )
31- if len (b ) < n {
32- n = len (b )
33- }
34- w := n / wordSize
35- if w > 0 {
36- dw := * (* []uintptr )(unsafe .Pointer (& dst ))
37- aw := * (* []uintptr )(unsafe .Pointer (& a ))
38- bw := * (* []uintptr )(unsafe .Pointer (& b ))
39- for i := 0 ; i < w ; i ++ {
40- dw [i ] = aw [i ] ^ bw [i ]
41- }
42- }
43- for i := n - n % wordSize ; i < n ; i ++ {
44- dst [i ] = a [i ] ^ b [i ]
45- }
46- return n
22+ return subtle .XORBytes (dst , a , b )
4723}
4824
4925// safeXORBytes xors one by one. It works on all architectures, independent if
You can’t perform that action at this time.
0 commit comments