Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 1 | // 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 | |
| 7 | package cmac |
| 8 | |
| 9 | import "unsafe" |
| 10 | |
| 11 | const 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. |
| 15 | func 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 | } |