blob: 3326a89dbdcb2bf5dfa47c36c93ffa4ac39c64bc [file] [log] [blame]
Andrea Campanella7167ebb2020-02-24 09:56:38 +01001// Copyright (c) 2016 Andreas Auernhammer. All rights reserved.
2// Use of this source code is governed by a license that can be
3// found in the LICENSE file.
4
5// +build amd64, !gccgo, !appengine
6
7package cmac
8
9import "unsafe"
10
11const wordSize = int(unsafe.Sizeof(uintptr(0)))
12
13// xor xors the bytes in dst with src and writes the result to dst.
14// The destination is assumed to have enough space.
15func xor(dst, src []byte) {
16 n := len(src)
17
18 w := n / wordSize
19 if w > 0 {
20 dstPtr := *(*[]uintptr)(unsafe.Pointer(&dst))
21 srcPtr := *(*[]uintptr)(unsafe.Pointer(&src))
22 for i, v := range srcPtr[:w] {
23 dstPtr[i] ^= v
24 }
25 }
26
27 for i := (n & (^(wordSize - 1))); i < n; i++ {
28 dst[i] ^= src[i]
29 }
30}