github.com/emmansun/gmsm@v0.29.1/internal/subtle/xor.go (about)

     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 := len(x)
    13  	if len(y) < n {
    14  		n = len(y)
    15  	}
    16  	if n == 0 {
    17  		return 0
    18  	}
    19  	if n > len(dst) {
    20  		panic("subtle.XORBytes: dst too short")
    21  	}
    22  	xorBytes(&dst[0], &x[0], &y[0], n) // arch-specific
    23  	return n
    24  }