]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/rsa: add benchmarks for not and partially optimized keys
authorFilippo Valsorda <filippo@golang.org>
Tue, 17 Dec 2024 19:40:49 +0000 (20:40 +0100)
committerGopher Robot <gobot@golang.org>
Sat, 15 Feb 2025 00:01:58 +0000 (16:01 -0800)
Updates #59695

Change-Id: I7944195c805cd9da819cdf2bd49ecb2423ccd73b
Reviewed-on: https://go-review.googlesource.com/c/go/+/637178
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
src/crypto/rsa/rsa_test.go

index 9e4478f9705f852d118700059052c5812c861c8e..795439d1c13df0a76c84c97fdf1eefa86d314ff3 100644 (file)
@@ -698,19 +698,48 @@ func BenchmarkEncryptOAEP(b *testing.B) {
 }
 
 func BenchmarkSignPKCS1v15(b *testing.B) {
-       b.Run("2048", func(b *testing.B) {
-               hashed := sha256.Sum256([]byte("testing"))
+       b.Run("2048", func(b *testing.B) { benchmarkSignPKCS1v15(b, test2048Key) })
+       b.Run("2048/noprecomp/OnlyD", func(b *testing.B) {
+               benchmarkSignPKCS1v15(b, &PrivateKey{
+                       PublicKey: test2048Key.PublicKey,
+                       D:         test2048Key.D,
+               })
+       })
+       b.Run("2048/noprecomp/Primes", func(b *testing.B) {
+               benchmarkSignPKCS1v15(b, &PrivateKey{
+                       PublicKey: test2048Key.PublicKey,
+                       D:         test2048Key.D,
+                       Primes:    test2048Key.Primes,
+               })
+       })
+       // This is different from "2048" because it's only the public precomputed
+       // values, and not the crypto/internal/fips140/rsa.PrivateKey.
+       b.Run("2048/noprecomp/AllValues", func(b *testing.B) {
+               benchmarkSignPKCS1v15(b, &PrivateKey{
+                       PublicKey: test2048Key.PublicKey,
+                       D:         test2048Key.D,
+                       Primes:    test2048Key.Primes,
+                       Precomputed: PrecomputedValues{
+                               Dp:   test2048Key.Precomputed.Dp,
+                               Dq:   test2048Key.Precomputed.Dq,
+                               Qinv: test2048Key.Precomputed.Qinv,
+                       },
+               })
+       })
+}
 
-               var sink byte
-               b.ResetTimer()
-               for i := 0; i < b.N; i++ {
-                       s, err := SignPKCS1v15(rand.Reader, test2048Key, crypto.SHA256, hashed[:])
-                       if err != nil {
-                               b.Fatal(err)
-                       }
-                       sink ^= s[0]
+func benchmarkSignPKCS1v15(b *testing.B, k *PrivateKey) {
+       hashed := sha256.Sum256([]byte("testing"))
+
+       var sink byte
+       b.ResetTimer()
+       for i := 0; i < b.N; i++ {
+               s, err := SignPKCS1v15(rand.Reader, k, crypto.SHA256, hashed[:])
+               if err != nil {
+                       b.Fatal(err)
                }
-       })
+               sink ^= s[0]
+       }
 }
 
 func BenchmarkVerifyPKCS1v15(b *testing.B) {