...
1
2
3
4
5 package sha3
6
7 import (
8 "crypto/subtle"
9 "encoding/binary"
10 "unsafe"
11
12 "golang.org/x/sys/cpu"
13 )
14
15
16 func xorIn(d *state, buf []byte) {
17 if cpu.IsBigEndian {
18 for i := 0; len(buf) >= 8; i++ {
19 a := binary.LittleEndian.Uint64(buf)
20 d.a[i] ^= a
21 buf = buf[8:]
22 }
23 } else {
24 ab := (*[25 * 64 / 8]byte)(unsafe.Pointer(&d.a))
25 subtle.XORBytes(ab[:], ab[:], buf)
26 }
27 }
28
29
30 func copyOut(d *state, b []byte) {
31 if cpu.IsBigEndian {
32 for i := 0; len(b) >= 8; i++ {
33 binary.LittleEndian.PutUint64(b, d.a[i])
34 b = b[8:]
35 }
36 } else {
37 ab := (*[25 * 64 / 8]byte)(unsafe.Pointer(&d.a))
38 copy(b, ab[:])
39 }
40 }
41
View as plain text