Skip to content

Commit c494ea2

Browse files
authored
Merge pull request #1361 from AkihiroSuda/dev
detectAESAcceleration: workaround for darwin/amd64
2 parents 5cba475 + 70ae5a5 commit c494ea2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/sshutil/sshutil.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os/exec"
1212
"path/filepath"
1313
"regexp"
14+
"runtime"
1415
"strings"
1516
"sync"
1617

@@ -298,6 +299,19 @@ func detectValidPublicKey(content string) bool {
298299

299300
func detectAESAcceleration() bool {
300301
if !cpu.Initialized {
302+
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
303+
// golang.org/x/sys/cpu supports darwin/amd64, linux/amd64, and linux/arm64,
304+
// but apparently lacks support for darwin/arm64: https://github.com/golang/sys/blob/v0.5.0/cpu/cpu_arm64.go#L43-L60
305+
//
306+
// According to https://gist.github.com/voluntas/fd279c7b4e71f9950cfd4a5ab90b722b ,
307+
// aes-128-gcm is faster than chacha20-poly1305 on Apple M1.
308+
//
309+
// So we return `true` here.
310+
//
311+
// This workaround will not be needed when https://go-review.googlesource.com/c/sys/+/332729 is merged.
312+
logrus.Debug("Failed to detect CPU features. Assuming that AES acceleration is available on this Apple silicon.")
313+
return true
314+
}
301315
logrus.Warn("Failed to detect CPU features. Assuming that AES acceleration is not available.")
302316
return false
303317
}

0 commit comments

Comments
 (0)