gmsm/cipher/xor_amd64.go

28 lines
669 B
Go
Raw Normal View History

2021-03-31 12:01:22 +08:00
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
2021-03-31 11:55:52 +08:00
package cipher
2021-03-18 17:54:10 +08:00
2021-03-31 11:55:52 +08:00
// XorBytes xors the bytes in a and b. The destination should have enough
2021-03-18 17:54:10 +08:00
// space, otherwise xorBytes will panic. Returns the number of bytes xor'd.
2021-03-31 11:55:52 +08:00
func XorBytes(dst, a, b []byte) int {
2021-03-18 17:54:10 +08:00
n := len(a)
if len(b) < n {
n = len(b)
}
if n == 0 {
return 0
}
_ = dst[n-1]
xorBytesSSE2(&dst[0], &a[0], &b[0], n) // amd64 must have SSE2
return n
}
2021-03-31 11:55:52 +08:00
func XorWords(dst, a, b []byte) {
XorBytes(dst, a, b)
2021-03-18 17:54:10 +08:00
}
//go:noescape
2021-03-31 11:55:52 +08:00
func xorBytesSSE2(dst, a, b *byte, n int)