podman

Форк
0
/x
/
xor_unaligned.go 
66 строк · 1.3 Кб
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

7
package sha3
8

9
import "unsafe"
10

11
// A storageBuf is an aligned array of maxRate bytes.
12
type storageBuf [maxRate / 8]uint64
13

14
func (b *storageBuf) asBytes() *[maxRate]byte {
15
	return (*[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.
20
func xorInUnaligned(d *state, buf []byte) {
21
	n := len(buf)
22
	bw := (*[maxRate / 8]uint64)(unsafe.Pointer(&buf[0]))[: n/8 : n/8]
23
	if n >= 72 {
24
		d.a[0] ^= bw[0]
25
		d.a[1] ^= bw[1]
26
		d.a[2] ^= bw[2]
27
		d.a[3] ^= bw[3]
28
		d.a[4] ^= bw[4]
29
		d.a[5] ^= bw[5]
30
		d.a[6] ^= bw[6]
31
		d.a[7] ^= bw[7]
32
		d.a[8] ^= bw[8]
33
	}
34
	if n >= 104 {
35
		d.a[9] ^= bw[9]
36
		d.a[10] ^= bw[10]
37
		d.a[11] ^= bw[11]
38
		d.a[12] ^= bw[12]
39
	}
40
	if n >= 136 {
41
		d.a[13] ^= bw[13]
42
		d.a[14] ^= bw[14]
43
		d.a[15] ^= bw[15]
44
		d.a[16] ^= bw[16]
45
	}
46
	if n >= 144 {
47
		d.a[17] ^= bw[17]
48
	}
49
	if n >= 168 {
50
		d.a[18] ^= bw[18]
51
		d.a[19] ^= bw[19]
52
		d.a[20] ^= bw[20]
53
	}
54
}
55

56
func copyOutUnaligned(d *state, buf []byte) {
57
	ab := (*[maxRate]uint8)(unsafe.Pointer(&d.a[0]))
58
	copy(buf, ab[:])
59
}
60

61
var (
62
	xorIn   = xorInUnaligned
63
	copyOut = copyOutUnaligned
64
)
65

66
const xorImplementationUnaligned = "unaligned"
67

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.