-
Notifications
You must be signed in to change notification settings - Fork 1
/
asm.go
86 lines (64 loc) · 1.4 KB
/
asm.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// +build ignore
package main
import (
. "github.com/mmcloughlin/avo/build"
. "github.com/mmcloughlin/avo/operand"
. "github.com/mmcloughlin/avo/reg"
)
func speckRound(x, y Register, k Op) {
RORQ(Imm(8), x)
ADDQ(y, x)
XORQ(k, x)
ROLQ(Imm(3), y)
XORQ(x, y)
}
func makeEncryptASM() {
TEXT("EncryptASM", NOSPLIT, "func(pt, ct, k []uint64)")
pt := GP64()
Load(Param("pt").Base(), pt)
ct0 := GP64()
ct1 := GP64()
MOVQ(Mem{Base: pt}, ct0)
MOVQ(Mem{Base: pt, Disp: 8}, ct1)
k := GP64()
Load(Param("k").Base(), k)
for i := 0; i < 32; i++ {
speckRound(ct1, ct0, Mem{Base: k, Disp: 8 * i})
}
ct := GP64()
Load(Param("ct").Base(), ct)
MOVQ(ct0, Mem{Base: ct})
MOVQ(ct1, Mem{Base: ct, Disp: 8})
RET()
}
func makeExpandEncryptASM() {
TEXT("ExpandEncryptASM", NOSPLIT, "func(pt, ct, k []uint64)")
pt := GP64()
Load(Param("pt").Base(), pt)
ct0 := GP64()
ct1 := GP64()
MOVQ(Mem{Base: pt}, ct0)
MOVQ(Mem{Base: pt, Disp: 8}, ct1)
k := GP64()
Load(Param("k").Base(), k)
a := GP64()
b := GP64()
MOVQ(Mem{Base: k}, a)
MOVQ(Mem{Base: k, Disp: 8}, b)
speckRound(ct1, ct0, a)
for i := 0; i < 31; i++ {
speckRound(b, a, Imm(uint64(i)))
speckRound(ct1, ct0, a)
}
ct := GP64()
Load(Param("ct").Base(), ct)
MOVQ(ct0, Mem{Base: ct})
MOVQ(ct1, Mem{Base: ct, Disp: 8})
RET()
}
func main() {
Package("github.com/dgryski/go-speck")
makeEncryptASM()
makeExpandEncryptASM()
Generate()
}