]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[release-branch.go1.20] crypto/internal/bigmod: flag amd64 assembly as noescape
authorFilippo Valsorda <filippo@golang.org>
Sun, 8 Jan 2023 16:39:02 +0000 (17:39 +0100)
committerGopher Robot <gobot@golang.org>
Tue, 28 Feb 2023 01:46:28 +0000 (01:46 +0000)
I had forgotten, which caused amd64 allocations to go back up
significantly. Added an allocations test.

name                    old time/op    new time/op    delta
DecryptPKCS1v15/2048-8    1.50ms ± 0%    1.48ms ± 0%   -0.95%  (p=0.000 n=9+10)
DecryptPKCS1v15/3072-8    4.64ms ± 1%    4.60ms ± 0%   -0.82%  (p=0.000 n=8+10)
DecryptPKCS1v15/4096-8    10.7ms ± 0%    10.6ms ± 1%   -0.99%  (p=0.000 n=10+10)
EncryptPKCS1v15/2048-8     158µs ± 0%     157µs ± 0%   -0.63%  (p=0.000 n=10+10)
DecryptOAEP/2048-8        1.50ms ± 0%    1.48ms ± 0%   -1.09%  (p=0.000 n=9+10)
EncryptOAEP/2048-8         161µs ± 0%     160µs ± 0%   -0.34%  (p=0.000 n=9+10)
SignPKCS1v15/2048-8       1.55ms ± 0%    1.53ms ± 1%   -1.32%  (p=0.000 n=10+10)
VerifyPKCS1v15/2048-8      157µs ± 0%     157µs ± 0%   -0.33%  (p=0.004 n=9+10)
SignPSS/2048-8            1.55ms ± 0%    1.54ms ± 0%   -1.14%  (p=0.000 n=10+10)
VerifyPSS/2048-8           160µs ± 0%     160µs ± 0%   -0.32%  (p=0.000 n=10+10)

name                    old alloc/op   new alloc/op   delta
DecryptPKCS1v15/2048-8    15.0kB ± 0%     0.6kB ± 0%  -95.74%  (p=0.000 n=10+10)
DecryptPKCS1v15/3072-8    17.9kB ± 0%     3.5kB ± 0%  -80.65%  (p=0.000 n=10+10)
DecryptPKCS1v15/4096-8    19.1kB ± 0%     4.7kB ± 0%  -75.25%  (p=0.000 n=10+10)
EncryptPKCS1v15/2048-8    7.51kB ± 0%    1.17kB ± 0%  -84.39%  (p=0.000 n=10+10)
DecryptOAEP/2048-8        15.3kB ± 0%     0.9kB ± 0%  -94.29%  (p=0.000 n=10+10)
EncryptOAEP/2048-8        7.74kB ± 0%    1.40kB ± 0%  -81.86%  (p=0.000 n=10+10)
SignPKCS1v15/2048-8       21.6kB ± 0%     0.9kB ± 0%  -95.86%  (p=0.000 n=10+10)
VerifyPKCS1v15/2048-8     7.25kB ± 0%    0.91kB ± 0%  -87.42%  (p=0.000 n=10+10)
SignPSS/2048-8            22.0kB ± 0%     1.3kB ± 0%  -94.12%  (p=0.000 n=10+10)
VerifyPSS/2048-8          7.46kB ± 0%    1.12kB ± 0%  -84.98%  (p=0.000 n=10+10)

name                    old allocs/op  new allocs/op  delta
DecryptPKCS1v15/2048-8      54.0 ± 0%       4.0 ± 0%  -92.59%  (p=0.000 n=10+10)
DecryptPKCS1v15/3072-8      60.0 ± 0%      10.0 ± 0%  -83.33%  (p=0.000 n=10+10)
DecryptPKCS1v15/4096-8      60.0 ± 0%      10.0 ± 0%  -83.33%  (p=0.000 n=10+10)
EncryptPKCS1v15/2048-8      29.0 ± 0%       7.0 ± 0%  -75.86%  (p=0.000 n=10+10)
DecryptOAEP/2048-8          60.0 ± 0%      10.0 ± 0%  -83.33%  (p=0.000 n=10+10)
EncryptOAEP/2048-8          35.0 ± 0%      13.0 ± 0%  -62.86%  (p=0.000 n=10+10)
SignPKCS1v15/2048-8         77.0 ± 0%       5.0 ± 0%  -93.51%  (p=0.000 n=10+10)
VerifyPKCS1v15/2048-8       28.0 ± 0%       6.0 ± 0%  -78.57%  (p=0.000 n=10+10)
SignPSS/2048-8              82.0 ± 0%      10.0 ± 0%  -87.80%  (p=0.000 n=10+10)
VerifyPSS/2048-8            33.0 ± 0%      11.0 ± 0%  -66.67%  (p=0.000 n=10+10)

Updates #58501.
Fixes #58505.

Change-Id: I418c5152833787b80220b556336ec284674c2493
Reviewed-on: https://go-review.googlesource.com/c/go/+/460542
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
(cherry picked from commit ed370d8720750ad670564079b1e0bcf74f75dd3a)
Reviewed-on: https://go-review.googlesource.com/c/go/+/471855
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/crypto/internal/bigmod/_asm/nat_amd64_asm.go
src/crypto/internal/bigmod/nat_amd64.go
src/crypto/rsa/rsa_test.go

index cea9365dcca98845622818ffefde7cca81fc08d6..5690f04d1ee2683febc0063d81b45e73c56870df 100644 (file)
@@ -17,6 +17,7 @@ func main() {
        ConstraintExpr("amd64,gc,!purego")
 
        Implement("montgomeryLoop")
+       Pragma("noescape")
 
        size := Load(Param("d").Len(), GP64())
        d := Mem{Base: Load(Param("d").Base(), GP64())}
index eaed2280c4550efd066ae85d5441dfd91ab8b037..e94778245df27f91ec45ea825976d41b7274d8e7 100644 (file)
@@ -4,4 +4,5 @@
 
 package bigmod
 
+//go:noescape
 func montgomeryLoop(d []uint, a []uint, b []uint, m []uint, m0inv uint) uint
index 16101f043a770f82f82328e894fd5950882ddc16..3278a7ff3057660a764eb57b3ae74b45a5cbb348 100644 (file)
@@ -8,6 +8,7 @@ import (
        "bufio"
        "bytes"
        "crypto"
+       "crypto/internal/boring"
        "crypto/rand"
        . "crypto/rsa"
        "crypto/sha1"
@@ -16,6 +17,7 @@ import (
        "encoding/pem"
        "flag"
        "fmt"
+       "internal/testenv"
        "math/big"
        "strings"
        "testing"
@@ -129,6 +131,31 @@ func testKeyBasics(t *testing.T, priv *PrivateKey) {
        }
 }
 
+func TestAllocations(t *testing.T) {
+       if boring.Enabled {
+               t.Skip("skipping allocations test with BoringCrypto")
+       }
+       testenv.SkipIfOptimizationOff(t)
+
+       m := []byte("Hello Gophers")
+       c, err := EncryptPKCS1v15(rand.Reader, &test2048Key.PublicKey, m)
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       if allocs := testing.AllocsPerRun(100, func() {
+               p, err := DecryptPKCS1v15(nil, test2048Key, c)
+               if err != nil {
+                       t.Fatal(err)
+               }
+               if !bytes.Equal(p, m) {
+                       t.Fatalf("unexpected output: %q", p)
+               }
+       }); allocs > 10 {
+               t.Errorf("expected less than 10 allocations, got %0.1f", allocs)
+       }
+}
+
 var allFlag = flag.Bool("all", false, "test all key sizes up to 2048")
 
 func TestEverything(t *testing.T) {