podman
1// Copyright 2015 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//go:build (amd64 || 386 || ppc64le) && !purego
6
7package sha38
9import "unsafe"10
11// A storageBuf is an aligned array of maxRate bytes.
12type storageBuf [maxRate / 8]uint6413
14func (b *storageBuf) asBytes() *[maxRate]byte {15return (*[maxRate]byte)(unsafe.Pointer(b))16}
17
18// xorInUnaligned uses unaligned reads and writes to update d.a to contain d.a
19// XOR buf.
20func xorInUnaligned(d *state, buf []byte) {21n := len(buf)22bw := (*[maxRate / 8]uint64)(unsafe.Pointer(&buf[0]))[: n/8 : n/8]23if n >= 72 {24d.a[0] ^= bw[0]25d.a[1] ^= bw[1]26d.a[2] ^= bw[2]27d.a[3] ^= bw[3]28d.a[4] ^= bw[4]29d.a[5] ^= bw[5]30d.a[6] ^= bw[6]31d.a[7] ^= bw[7]32d.a[8] ^= bw[8]33}34if n >= 104 {35d.a[9] ^= bw[9]36d.a[10] ^= bw[10]37d.a[11] ^= bw[11]38d.a[12] ^= bw[12]39}40if n >= 136 {41d.a[13] ^= bw[13]42d.a[14] ^= bw[14]43d.a[15] ^= bw[15]44d.a[16] ^= bw[16]45}46if n >= 144 {47d.a[17] ^= bw[17]48}49if n >= 168 {50d.a[18] ^= bw[18]51d.a[19] ^= bw[19]52d.a[20] ^= bw[20]53}54}
55
56func copyOutUnaligned(d *state, buf []byte) {57ab := (*[maxRate]uint8)(unsafe.Pointer(&d.a[0]))58copy(buf, ab[:])59}
60
61var (62xorIn = xorInUnaligned63copyOut = copyOutUnaligned64)
65
66const xorImplementationUnaligned = "unaligned"67