-
Notifications
You must be signed in to change notification settings - Fork 1
/
polyval_arm64.go
56 lines (45 loc) · 1.08 KB
/
polyval_arm64.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//go:build gc && !purego
package polyval
import (
"runtime"
"golang.org/x/sys/cpu"
)
var (
haveAsm = runtime.GOOS == "darwin" || cpu.ARM64.HasPMULL
haveSHA3 = runtime.GOOS == "darwin" || cpu.ARM64.HasSHA3
)
func polymul(acc, key *fieldElement) {
if haveAsm {
polymulAsm(acc, key)
} else {
polymulGeneric(acc, key)
}
}
func polymulBlocks(acc *fieldElement, pow *[8]fieldElement, blocks []byte) {
if len(blocks) == 0 {
return
}
if haveAsm {
if haveSHA3 {
polymulBlocksAsmSHA3(acc, pow, &blocks[0], len(blocks)/16)
} else {
polymulBlocksAsm(acc, pow, &blocks[0], len(blocks)/16)
}
} else {
polymulBlocksGeneric(acc, pow, blocks)
}
}
func ctmul(x, y uint64) (z1, z0 uint64) {
if haveAsm {
return ctmulAsm(x, y)
}
return ctmulGeneric(x, y)
}
//go:noescape
func polymulAsm(acc, key *fieldElement)
//go:noescape
func polymulBlocksAsm(acc *fieldElement, pow *[8]fieldElement, input *byte, nblocks int)
//go:noescape
func polymulBlocksAsmSHA3(acc *fieldElement, pow *[8]fieldElement, input *byte, nblocks int)
//go:noescape
func ctmulAsm(x, y uint64) (z1, z0 uint64)