diff options
| author | Keith Randall <khr@golang.org> | 2024-11-22 15:19:35 -0800 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2024-11-23 01:41:58 +0000 |
| commit | b68f8ca89a2fb6b33d1e78fadc33d1c35693f6b8 (patch) | |
| tree | 79f504d4953bd3da52a1c72a2775249077e3137d /src/crypto | |
| parent | 8397de2241ca71ba5df2fa60564a8559b9a2d25d (diff) | |
| download | go-b68f8ca89a2fb6b33d1e78fadc33d1c35693f6b8.tar.xz | |
crypto/internal: keep fips140/aes.NewCTR from allocating
Return a *CTR from an always-inlineable function, so the allocation
can be lifted to the callsite.
Put the potentially uninlineable code in a separate function that returns a CTR.
Fixes #70499
Change-Id: I2531a2516e4c00aba65407f3bc24a7c21dd8f842
Reviewed-on: https://go-review.googlesource.com/c/go/+/631317
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/crypto')
| -rw-r--r-- | src/crypto/internal/fips140/aes/ctr.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/crypto/internal/fips140/aes/ctr.go b/src/crypto/internal/fips140/aes/ctr.go index ec1959a225..f612034d85 100644 --- a/src/crypto/internal/fips140/aes/ctr.go +++ b/src/crypto/internal/fips140/aes/ctr.go @@ -18,11 +18,18 @@ type CTR struct { } func NewCTR(b *Block, iv []byte) *CTR { + // Allocate the CTR here, in an easily inlineable function, so + // the allocation can be done in the caller's stack frame + // instead of the heap. See issue 70499. + c := newCTR(b, iv) + return &c +} +func newCTR(b *Block, iv []byte) CTR { if len(iv) != BlockSize { panic("bad IV length") } - return &CTR{ + return CTR{ b: *b, ivlo: byteorder.BEUint64(iv[8:16]), ivhi: byteorder.BEUint64(iv[0:8]), |
