[go] crypto/hmac: allocate hmac struct on the stack

13 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Aug 17, 2023, 5:25:47 AM8/17/23
to goph...@pubsubhelper.golang.org, Mateusz Poliwczak, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

crypto/hmac: allocate hmac struct on the stack

goos: linux
goarch: amd64
pkg: crypto/hmac
cpu: Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz
│ before │ after │
│ sec/op │ sec/op vs base │
HMACSHA256_1K-4 3.302µ ± 1% 3.296µ ± 1% ~ (p=0.740 n=25)
HMACSHA256_32-4 611.9n ± 3% 613.5n ± 2% ~ (p=0.450 n=25)
NewWriteSum-4 3.432µ ± 27% 2.513µ ± 18% -26.78% (p=0.011 n=25)
geomean 1.907µ 1.719µ -9.84%

│ before │ after │
│ B/s │ B/s vs base │
HMACSHA256_1K-4 295.8Mi ± 1% 296.3Mi ± 1% ~ (p=0.740 n=25)
HMACSHA256_32-4 49.87Mi ± 3% 49.74Mi ± 2% ~ (p=0.461 n=25)
NewWriteSum-4 8.888Mi ± 38% 12.140Mi ± 15% +36.59% (p=0.011 n=25)
geomean 50.80Mi 56.35Mi +10.93%

│ before │ after │
│ B/op │ B/op vs base │
HMACSHA256_1K-4 32.00 ± 0% 32.00 ± 0% ~ (p=1.000 n=25) ¹
HMACSHA256_32-4 32.00 ± 0% 32.00 ± 0% ~ (p=1.000 n=25) ¹
NewWriteSum-4 544.0 ± 0% 448.0 ± 0% -17.65% (p=0.000 n=25)
geomean 82.28 77.12 -6.27%
¹ all samples are equal

│ before │ after │
│ allocs/op │ allocs/op vs base │
HMACSHA256_1K-4 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=25) ¹
HMACSHA256_32-4 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=25) ¹
NewWriteSum-4 7.000 ± 0% 6.000 ± 0% -14.29% (p=0.000 n=25)
geomean 1.913 1.817 -5.01%
¹ all samples are equal

Change-Id: Ib9c812d52a7e56e9147fe8761c05dbffdb565d77
GitHub-Last-Rev: f9250ae1a1b25469939b6951a6981c9058c59304
GitHub-Pull-Request: golang/go#62088
---
M src/crypto/hmac/hmac.go
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/crypto/hmac/hmac.go b/src/crypto/hmac/hmac.go
index 35b9d5a..9b0f5a3 100644
--- a/src/crypto/hmac/hmac.go
+++ b/src/crypto/hmac/hmac.go
@@ -134,7 +134,13 @@
}
// BoringCrypto did not recognize h, so fall through to standard Go code.
}
+
hm := new(hmac)
+ hm.init(h, key)
+ return hm
+}
+
+func (hm *hmac) init(h func() hash.Hash, key []byte) {
hm.outer = h()
hm.inner = h()
unique := true
@@ -167,8 +173,6 @@
hm.opad[i] ^= 0x5c
}
hm.inner.Write(hm.ipad)
-
- return hm
}

// Equal compares two MACs for equality without leaking timing information.

To view, visit change 520269. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib9c812d52a7e56e9147fe8761c05dbffdb565d77
Gerrit-Change-Number: 520269
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-CC: Mateusz Poliwczak <mpoliw...@gmail.com>

Gopher Robot (Gerrit)

unread,
Aug 17, 2023, 5:25:49 AM8/17/23
to Gerrit Bot, Mateusz Poliwczak, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

View Change

1 comment:

To view, visit change 520269. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib9c812d52a7e56e9147fe8761c05dbffdb565d77
Gerrit-Change-Number: 520269
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Mateusz Poliwczak <mpoliw...@gmail.com>
Gerrit-Comment-Date: Thu, 17 Aug 2023 09:25:43 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No

Mateusz Poliwczak (Gerrit)

unread,
Aug 17, 2023, 5:26:24 AM8/17/23
to Gerrit Bot, goph...@pubsubhelper.golang.org, Roland Shoemaker, Filippo Valsorda, Gopher Robot, golang-co...@googlegroups.com

Attention is currently required from: Filippo Valsorda, Roland Shoemaker.

Patch set 1:Run-TryBot +1

View Change

    To view, visit change 520269. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib9c812d52a7e56e9147fe8761c05dbffdb565d77
    Gerrit-Change-Number: 520269
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Filippo Valsorda <fil...@golang.org>
    Gerrit-Reviewer: Mateusz Poliwczak <mpoliw...@gmail.com>
    Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Roland Shoemaker <rol...@golang.org>
    Gerrit-Attention: Filippo Valsorda <fil...@golang.org>
    Gerrit-Comment-Date: Thu, 17 Aug 2023 09:26:15 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes

    Mateusz Poliwczak (Gerrit)

    unread,
    Aug 20, 2023, 4:44:39 AM8/20/23
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Roland Shoemaker, Filippo Valsorda, golang-co...@googlegroups.com

    Attention is currently required from: Filippo Valsorda, Roland Shoemaker.

    View Change

    1 comment:

    To view, visit change 520269. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib9c812d52a7e56e9147fe8761c05dbffdb565d77
    Gerrit-Change-Number: 520269
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Filippo Valsorda <fil...@golang.org>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Mateusz Poliwczak <mpoliw...@gmail.com>
    Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
    Gerrit-Attention: Roland Shoemaker <rol...@golang.org>
    Gerrit-Attention: Filippo Valsorda <fil...@golang.org>
    Gerrit-Comment-Date: Sun, 20 Aug 2023 08:44:33 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Gopher Robot <go...@golang.org>

    Gerrit Bot (Gerrit)

    unread,
    Feb 19, 2024, 1:54:51 PM2/19/24
    to Mateusz Poliwczak, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Filippo Valsorda, Mateusz Poliwczak and Roland Shoemaker

    Gerrit Bot uploaded new patchset

    Gerrit Bot uploaded patch set #2 to this change.
    Following approvals got outdated and were removed:
    • Legacy-TryBots-Pass: TryBot-Result+1 by Gopher Robot, Run-TryBot+1 by Mateusz Poliwczak
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Filippo Valsorda
    • Mateusz Poliwczak
    • Roland Shoemaker
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib9c812d52a7e56e9147fe8761c05dbffdb565d77
    Gerrit-Change-Number: 520269
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Filippo Valsorda <fil...@golang.org>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
    Gerrit-CC: Mateusz Poliwczak <mpoliw...@gmail.com>
    Gerrit-Attention: Roland Shoemaker <rol...@golang.org>
    Gerrit-Attention: Mateusz Poliwczak <mpoliw...@gmail.com>
    Gerrit-Attention: Filippo Valsorda <fil...@golang.org>
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Mateusz Poliwczak (Gerrit)

    unread,
    Feb 19, 2024, 1:55:12 PM2/19/24
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Roland Shoemaker, Filippo Valsorda, golang-co...@googlegroups.com
    Attention needed from Filippo Valsorda and Roland Shoemaker

    Mateusz Poliwczak voted Commit-Queue+1

    Commit-Queue+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Filippo Valsorda
    • Roland Shoemaker
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib9c812d52a7e56e9147fe8761c05dbffdb565d77
    Gerrit-Change-Number: 520269
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Filippo Valsorda <fil...@golang.org>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Mateusz Poliwczak <mpoliw...@gmail.com>
    Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
    Gerrit-Attention: Roland Shoemaker <rol...@golang.org>
    Gerrit-Attention: Filippo Valsorda <fil...@golang.org>
    Gerrit-Comment-Date: Mon, 19 Feb 2024 18:55:06 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages