aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
authorFilippo Valsorda <filippo@golang.org>2024-11-20 16:11:49 +0100
committerGopher Robot <gobot@golang.org>2024-11-20 16:57:48 +0000
commitc483fdbfcfba9c86dbe93a096f120cc15f783d38 (patch)
treeec75ff9e35a341178ea346530c648f61c9dc252b /src/crypto
parent93fcd8fb1882b55b3456aa753d32a2cf3d369b1c (diff)
downloadgo-c483fdbfcfba9c86dbe93a096f120cc15f783d38.tar.xz
crypto/ed25519: fix TestAllocations in FIPS mode
Change-Id: Ic36e95dba29d43e73ddf105d538c4795bc4ce557 Reviewed-on: https://go-review.googlesource.com/c/go/+/630097 Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Daniel McCarney <daniel@binaryparadox.net> Auto-Submit: Filippo Valsorda <filippo@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/internal/fips/ed25519/cast.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/crypto/internal/fips/ed25519/cast.go b/src/crypto/internal/fips/ed25519/cast.go
index aa6ba668c0..8ac7a6f688 100644
--- a/src/crypto/internal/fips/ed25519/cast.go
+++ b/src/crypto/internal/fips/ed25519/cast.go
@@ -14,19 +14,25 @@ import (
func fipsPCT(k *PrivateKey) error {
return fips.PCT("Ed25519 sign and verify PCT", func() error {
- msg := []byte("PCT")
- sig := Sign(k, msg)
- // Note that this runs pub.a.SetBytes. If we wanted to make key generation
- // in FIPS mode faster, we could reuse A from GenerateKey. But another thing
- // that could make it faster is just _not doing a useless self-test_.
- pub, err := NewPublicKey(k.PublicKey())
- if err != nil {
- return err
- }
- return Verify(pub, msg, sig)
+ return pairwiseTest(k)
})
}
+// pairwiseTest needs to be a top-level function declaration to let the calls
+// inline and their allocations not escape.
+func pairwiseTest(k *PrivateKey) error {
+ msg := []byte("PCT")
+ sig := Sign(k, msg)
+ // Note that this runs pub.a.SetBytes. If we wanted to make key generation
+ // in FIPS mode faster, we could reuse A from GenerateKey. But another thing
+ // that could make it faster is just _not doing a useless self-test_.
+ pub, err := NewPublicKey(k.PublicKey())
+ if err != nil {
+ return err
+ }
+ return Verify(pub, msg, sig)
+}
+
func signWithoutSelfTest(priv *PrivateKey, message []byte) []byte {
signature := make([]byte, signatureSize)
return signWithDom(signature, priv, message, domPrefixPure, "")