Skip to content

Commit a8b0991

Browse files
authored
Feat: refine the logic of security type AUTO (#1913)
* Feat: refine the logic of security type AUTO https://cs.opensource.google/go/go/+/master:src/crypto/tls/cipher_suites.go;drc=9e6cd3985dbcdcfe0ed2075be6dbe8c5d6de59cb;l=364 * fix fmt
1 parent 0a0fecb commit a8b0991

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

common/protocol/headers.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package protocol
33
import (
44
"runtime"
55

6+
"golang.org/x/sys/cpu"
7+
68
"github.com/v2fly/v2ray-core/v5/common/bitmask"
79
"github.com/v2fly/v2ray-core/v5/common/net"
810
"github.com/v2fly/v2ray-core/v5/common/uuid"
@@ -79,9 +81,21 @@ type CommandSwitchAccount struct {
7981
ValidMin byte
8082
}
8183

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+
8296
func (sc *SecurityConfig) GetSecurityType() SecurityType {
8397
if sc == nil || sc.Type == SecurityType_AUTO {
84-
if runtime.GOARCH == "amd64" || runtime.GOARCH == "s390x" || runtime.GOARCH == "arm64" {
98+
if hasAESGCMHardwareSupport {
8599
return SecurityType_AES128_GCM
86100
}
87101
return SecurityType_CHACHA20_POLY1305

0 commit comments

Comments
 (0)