| 1 |
// Copyright 2012 Aaron Jacobs. All Rights Reserved. |
| 2 |
// Author: [email protected] (Aaron Jacobs) |
| 3 |
// |
| 4 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
// you may not use this file except in compliance with the License. |
| 6 |
// You may obtain a copy of the License at |
| 7 |
// |
| 8 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
// |
| 10 |
// Unless required by applicable law or agreed to in writing, software |
| 11 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
// See the License for the specific language governing permissions and |
| 14 |
// limitations under the License. |
| 15 |
|
| 16 |
// +build amd64 arm64 ppc64 ppc64le ppc64el mips64 mips64le mips64el s390x alpha amd64p32 arm64be mipso64 mipsn64 mips64p32 mips64p32le ia64 riscv64 sparc64 |
| 17 |
|
| 18 |
// This code assumes that it's safe to perform unaligned word-sized loads. This is safe on: |
| 19 |
// - arm64 per http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0024a/ch05s01s02.html |
| 20 |
// - Section "5.5.8 Alignment Interrupt" of PowerPC Operating Environment Architecture Book III Version 2.02 |
| 21 |
// (the first PowerPC ISA version to include 64-bit), available from |
| 22 |
// http://www.ibm.com/developerworks/systems/library/es-archguide-v2.html does not permit fixed-point loads |
| 23 |
// or stores to generate exceptions on unaligned access |
| 24 |
// - IBM mainframe's have allowed unaligned accesses since the System/370 arrived in 1970 |
| 25 |
// - On mips unaligned accesses are fixed up by the kernel per https://www.linux-mips.org/wiki/Alignment |
| 26 |
// so performance might be quite bad but it will work. |
| 27 |
|
| 28 |
package cmac |
| 29 |
|
| 30 |
import ( |
| 31 |
"log" |
| 32 |
"unsafe" |
| 33 |
) |
| 34 |
|
| 35 |
// XOR the blockSize bytes starting at a and b, writing the result over dst. |
| 36 |
func xorBlock( |
| 37 |
dstPtr unsafe.Pointer, |
| 38 |
aPtr unsafe.Pointer, |
| 39 |
bPtr unsafe.Pointer) { |
| 40 |
// Check assumptions. (These are compile-time constants, so this should |
| 41 |
// compile out.) |
| 42 |
const wordSize = unsafe.Sizeof(uintptr(0)) |
| 43 |
if blockSize != 2*wordSize { |
| 44 |
log.Panicf("%d %d", blockSize, wordSize) |
| 45 |
} |
| 46 |
|
| 47 |
// Convert. |
| 48 |
a := (*[2]uintptr)(aPtr) |
| 49 |
b := (*[2]uintptr)(bPtr) |
| 50 |
dst := (*[2]uintptr)(dstPtr) |
| 51 |
|
| 52 |
// Compute. |
| 53 |
dst[0] = a[0] ^ b[0] |
| 54 |
dst[1] = a[1] ^ b[1] |
| 55 |
} |