Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto/aes: AES cipher creation and encrypt / decrypt operations can be sped up significantly #65507

Closed
marten-seemann opened this issue Feb 4, 2024 · 3 comments
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. Performance
Milestone

Comments

@marten-seemann
Copy link
Contributor

Go version

go version go1.21.4 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/marten/Library/Caches/go-build'
GOENV='/Users/marten/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/marten/src/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/marten/src/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/marten/bin/go1.21ex'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/marten/bin/go1.21ex/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/q0/b5ynf00142l7bl9sp8y098zr0000gn/T/go-build341590646=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I'm the maintainer of quic-go, and I'm working on reducing the allocations during the QUIC handshake (tracking issue).

What did you see happen?

The major source of allocations lies in the standard library, especially the crypto packages. Creating AES ciphers is part of this.

The allocations coming from the two slices embedded in aesCipher could easily be avoided:

// A cipher is an instance of AES encryption using a particular key.
type aesCipher struct {
enc []uint32
dec []uint32
}

These slices have lengths between 44 and 60 bytes, depending on the AES variant (AES-128, AES-192, AES-256). By replacing them with a fixed-size 60 element array (plus one length field), the number of allocations can be reduced significantly. This also reduces pointer chasing when encrypting / decrypting data.

What did you expect to see?

I'm going to submit a CL that implements this suggestion.

@gopherbot
Copy link

Change https://go.dev/cl/561080 mentions this issue: crypto/aes: speed up AES by reducing allocation

@Jorropo Jorropo added this to the Backlog milestone Feb 4, 2024
@Jorropo Jorropo added Performance NeedsFix The path to resolution is known, but the work has not been done. labels Feb 4, 2024
@Jorropo
Copy link
Member

Jorropo commented Feb 4, 2024

cc @FiloSottile @rolandshoemaker @golang/security as per https://dev.golang.org/owners

@mateusz834
Copy link
Member

mateusz834 commented Feb 4, 2024

I've made a similar change before in CL CL 461078, but this seems better. I will abort that change.

@mateusz834 mateusz834 added FixPending Issues that have a fix which has not yet been reviewed or submitted. and removed NeedsFix The path to resolution is known, but the work has not been done. labels Feb 4, 2024
@dmitshur dmitshur modified the milestones: Backlog, Go1.23 Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. Performance
Projects
None yet
Development

No branches or pull requests

5 participants