github.com/remobjects/goldbaselibrary@v0.0.0-20230924164425-d458680a936b/Source/Gold/crypto/cipher/xor_elements.go (about) 1 // Copyright 2013 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 cipher 6 7 import ( 8 "runtime" 9 "unsafe" 10 ) 11 12 func safeXORBytes(dst, a, b []byte) int { 13 n := len(a) 14 if len(b) < n { 15 n = len(b) 16 } 17 for i := 0; i < n; i++ { 18 dst[i] = a[i] ^ b[i] 19 } 20 return n 21 } 22 23 // xorBytes xors the bytes in a and b. The destination should have enough 24 // space, otherwise xorBytes will panic. Returns the number of bytes xor'd. 25 func xorBytes(dst, a, b []byte) int { 26 return safeXORBytes(dst, a, b) 27 } 28 29 func xorWords(dst, a, b []byte) { 30 safeXORBytes(dst, a, b) 31 }