1
2
3
4
5 package chacha20
6
7 import "runtime"
8
9
10 const unaligned = runtime.GOARCH == "386" ||
11 runtime.GOARCH == "amd64" ||
12 runtime.GOARCH == "arm64" ||
13 runtime.GOARCH == "ppc64le" ||
14 runtime.GOARCH == "s390x"
15
16
17
18 func addXor(dst, src []byte, a, b uint32) {
19 _, _ = src[3], dst[3]
20 if unaligned {
21
22
23
24
25
26 v := uint32(src[0])
27 v |= uint32(src[1]) << 8
28 v |= uint32(src[2]) << 16
29 v |= uint32(src[3]) << 24
30 v ^= a + b
31 dst[0] = byte(v)
32 dst[1] = byte(v >> 8)
33 dst[2] = byte(v >> 16)
34 dst[3] = byte(v >> 24)
35 } else {
36 a += b
37 dst[0] = src[0] ^ byte(a)
38 dst[1] = src[1] ^ byte(a>>8)
39 dst[2] = src[2] ^ byte(a>>16)
40 dst[3] = src[3] ^ byte(a>>24)
41 }
42 }
43
View as plain text