...
1
2
3
4
5
6
7
8
9 package sha3
10
11 import "unsafe"
12
13
14 type storageBuf [maxRate / 8]uint64
15
16 func (b *storageBuf) asBytes() *[maxRate]byte {
17 return (*[maxRate]byte)(unsafe.Pointer(b))
18 }
19
20
21
22 func xorIn(d *State, buf []byte) {
23 n := len(buf)
24 bw := (*[maxRate / 8]uint64)(unsafe.Pointer(&buf[0]))[: n/8 : n/8]
25 if n >= 72 {
26 d.a[0] ^= bw[0]
27 d.a[1] ^= bw[1]
28 d.a[2] ^= bw[2]
29 d.a[3] ^= bw[3]
30 d.a[4] ^= bw[4]
31 d.a[5] ^= bw[5]
32 d.a[6] ^= bw[6]
33 d.a[7] ^= bw[7]
34 d.a[8] ^= bw[8]
35 }
36 if n >= 104 {
37 d.a[9] ^= bw[9]
38 d.a[10] ^= bw[10]
39 d.a[11] ^= bw[11]
40 d.a[12] ^= bw[12]
41 }
42 if n >= 136 {
43 d.a[13] ^= bw[13]
44 d.a[14] ^= bw[14]
45 d.a[15] ^= bw[15]
46 d.a[16] ^= bw[16]
47 }
48 if n >= 144 {
49 d.a[17] ^= bw[17]
50 }
51 if n >= 168 {
52 d.a[18] ^= bw[18]
53 d.a[19] ^= bw[19]
54 d.a[20] ^= bw[20]
55 }
56 }
57
58 func copyOut(d *State, buf []byte) {
59 ab := (*[maxRate]uint8)(unsafe.Pointer(&d.a[0]))
60 copy(buf, ab[:])
61 }
62
View as plain text