| 1 | // Copyright 2018 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Package xor provides utility functions used by other Pion |
| 6 | // packages. AMD64 arch. |
| 7 | package xor |
| 8 | |
| 9 | // XorBytes xors the bytes in a and b. The destination should have enough |
| 10 | // space, otherwise xorBytes will panic. Returns the number of bytes xor'd. |
| 11 | //revive:disable-next-line |
| 12 | func XorBytes(dst, a, b []byte) int { |
| 13 | n := len(a) |
| 14 | if len(b) < n { |
| 15 | n = len(b) |
| 16 | } |
| 17 | if n == 0 { |
| 18 | return 0 |
| 19 | } |
| 20 | _ = dst[n-1] |
| 21 | xorBytesSSE2(&dst[0], &a[0], &b[0], n) // amd64 must have SSE2 |
| 22 | return n |
| 23 | } |
| 24 | |
| 25 | //go:noescape |
| 26 | func xorBytesSSE2(dst, a, b *byte, n int) |