File tree 1 file changed +15
-1
lines changed
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ package protocol
3
3
import (
4
4
"runtime"
5
5
6
+ "golang.org/x/sys/cpu"
7
+
6
8
"github.com/v2fly/v2ray-core/v5/common/bitmask"
7
9
"github.com/v2fly/v2ray-core/v5/common/net"
8
10
"github.com/v2fly/v2ray-core/v5/common/uuid"
@@ -79,9 +81,21 @@ type CommandSwitchAccount struct {
79
81
ValidMin byte
80
82
}
81
83
84
+ var (
85
+ hasGCMAsmAMD64 = cpu .X86 .HasAES && cpu .X86 .HasPCLMULQDQ
86
+ hasGCMAsmARM64 = cpu .ARM64 .HasAES && cpu .ARM64 .HasPMULL
87
+ // Keep in sync with crypto/aes/cipher_s390x.go.
88
+ hasGCMAsmS390X = cpu .S390X .HasAES && cpu .S390X .HasAESCBC && cpu .S390X .HasAESCTR &&
89
+ (cpu .S390X .HasGHASH || cpu .S390X .HasAESGCM )
90
+
91
+ hasAESGCMHardwareSupport = runtime .GOARCH == "amd64" && hasGCMAsmAMD64 ||
92
+ runtime .GOARCH == "arm64" && hasGCMAsmARM64 ||
93
+ runtime .GOARCH == "s390x" && hasGCMAsmS390X
94
+ )
95
+
82
96
func (sc * SecurityConfig ) GetSecurityType () SecurityType {
83
97
if sc == nil || sc .Type == SecurityType_AUTO {
84
- if runtime . GOARCH == "amd64" || runtime . GOARCH == "s390x" || runtime . GOARCH == "arm64" {
98
+ if hasAESGCMHardwareSupport {
85
99
return SecurityType_AES128_GCM
86
100
}
87
101
return SecurityType_CHACHA20_POLY1305
You can’t perform that action at this time.
0 commit comments