/
cn_amd64.go
71 lines (62 loc) · 1.55 KB
/
cn_amd64.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
//go:build amd64
// +build amd64
package aes
import (
"github.com/esrrhs/gohome/loggo"
"golang.org/x/sys/cpu"
"unsafe"
)
var (
hasAES = cpu.X86.HasAES
)
func CnExpandKeyGo(key []uint64, rkeys *[40]uint32) {
if !hasAES {
CnExpandKeyGoSoft(key, rkeys)
return
}
if uintptr(unsafe.Pointer(&key[0]))%16 != 0 {
loggo.Error("CnExpandKeyGo %v", &key[0])
}
if uintptr(unsafe.Pointer(&rkeys[0]))%16 != 0 {
loggo.Error("CnExpandKeyGo %v", &rkeys[0])
}
CnExpandKeyAsm(&key[0], rkeys)
}
func CnRoundsGo(dst, src []uint64, rkeys *[40]uint32) {
if !hasAES {
CnRoundsGoSoft(dst, src, rkeys)
return
}
if uintptr(unsafe.Pointer(&dst[0]))%16 != 0 {
loggo.Error("CnRoundsGo %v", &dst[0])
}
if uintptr(unsafe.Pointer(&src[0]))%16 != 0 {
loggo.Error("CnRoundsGo %v", &src[0])
}
if uintptr(unsafe.Pointer(&rkeys[0]))%16 != 0 {
loggo.Error("CnRoundsGo %v", &rkeys[0])
}
CnRoundsAsm(&dst[0], &src[0], &rkeys[0])
}
func CnSingleRoundGo(dst, src []uint64, rkey *[2]uint64) {
if !hasAES {
CnSingleRoundGoSoft(dst, src, rkey)
return
}
if uintptr(unsafe.Pointer(&dst[0]))%16 != 0 {
loggo.Error("CnSingleRoundGo %v", &dst[0])
}
if uintptr(unsafe.Pointer(&src[0]))%16 != 0 {
loggo.Error("CnSingleRoundGo %v", &src[0])
}
if uintptr(unsafe.Pointer(&rkey[0]))%16 != 0 {
loggo.Error("CnSingleRoundGo %v", &rkey[0])
}
CnSingleRoundAsm(&dst[0], &src[0], &rkey[0])
}
//go:noescape
func CnExpandKeyAsm(src *uint64, rkey *[40]uint32)
//go:noescape
func CnRoundsAsm(dst, src *uint64, rkeys *uint32)
//go:noescape
func CnSingleRoundAsm(dst, src *uint64, rkeys *uint64)