Source file src/crypto/subtle/xor.go

     1  // Copyright 2022 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 subtle
     6  
     7  // XORBytes sets dst[i] = x[i] ^ y[i] for all i < n = min(len(x), len(y)),
     8  // returning n, the number of bytes written to dst.
     9  // If dst does not have length at least n,
    10  // XORBytes panics without writing anything to dst.
    11  func XORBytes(dst, x, y []byte) int {
    12  	n := min(len(x), len(y))
    13  	if n == 0 {
    14  		return 0
    15  	}
    16  	if n > len(dst) {
    17  		panic("subtle.XORBytes: dst too short")
    18  	}
    19  	xorBytes(&dst[0], &x[0], &y[0], n) // arch-specific
    20  	return n
    21  }
    22  

View as plain text