Skip to content

Commit 3b42687

Browse files
FiloSottilegopherbot
authored andcommitted
crypto/rsa: add BenchmarkParsePKCS8PrivateKey and BenchmarkGenerateKey
BenchmarkParsePKCS8PrivateKey is a useful high-level measure of the performance of Validate + Precompute. Change-Id: Ibc32bf7006cd6669019dc3c697566614ee348d0f Reviewed-on: https://go-review.googlesource.com/c/go/+/630516 Reviewed-by: Russ Cox <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Filippo Valsorda <[email protected]>
1 parent 0598229 commit 3b42687

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/crypto/rsa/rsa_test.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ F6rgN3QiyCA9J/1FluUCQQC5nX+PTU1FXx+6Ri2ZCi6EjEKMHr7gHcABhMinZYOt
436436
N59pra9UdVQw9jxCU9G7eMyb0jJkNACAuEwakX3gi27b
437437
-----END RSA TESTING KEY-----`))
438438

439-
var test2048Key = parseKey(testingKey(`-----BEGIN TESTING KEY-----
439+
var test2048KeyPEM = testingKey(`-----BEGIN TESTING KEY-----
440440
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDNoyFUYeDuqw+k
441441
iyv47iBy/udbWmQdpbUZ8JobHv8uQrvL7sQN6l83teHgNJsXqtiLF3MC+K+XI6Dq
442442
hxUWfQwLip8WEnv7Jx/+53S8yp/CS4Jw86Q1bQHbZjFDpcoqSuwAxlegw18HNZCY
@@ -463,7 +463,9 @@ mCSL4FGK02ImUNDsd0RVVFw51DRId4rmsuJYMK9NAoGAKlYdc4784ixTD2ZICIOC
463463
ZWPxPAyQUEA7EkuUhAX1bVNG6UJTYA8kmGcUCG4jPTgWzi00IyUUr8jK7efyU/zs
464464
qiJuVs1bia+flYIQpysMl1VzZh8gW1nkB4SVPm5l2wBvVJDIr9Mc6rueC/oVNkh2
465465
fLVGuFoTVIu2bF0cWAjNNMg=
466-
-----END TESTING KEY-----`))
466+
-----END TESTING KEY-----`)
467+
468+
var test2048Key = parseKey(test2048KeyPEM)
467469

468470
var test3072Key = parseKey(testingKey(`-----BEGIN TESTING KEY-----
469471
MIIG/gIBADANBgkqhkiG9w0BAQEFAASCBugwggbkAgEAAoIBgQDJrvevql7G07LM
@@ -713,6 +715,28 @@ func BenchmarkVerifyPSS(b *testing.B) {
713715
})
714716
}
715717

718+
func BenchmarkGenerateKey(b *testing.B) {
719+
b.Run("2048", func(b *testing.B) {
720+
for i := 0; i < b.N; i++ {
721+
if _, err := GenerateKey(rand.Reader, 2048); err != nil {
722+
b.Fatal(err)
723+
}
724+
}
725+
})
726+
}
727+
728+
func BenchmarkParsePKCS8PrivateKey(b *testing.B) {
729+
b.Run("2048", func(b *testing.B) {
730+
p, _ := pem.Decode([]byte(test2048KeyPEM))
731+
b.ResetTimer()
732+
for i := 0; i < b.N; i++ {
733+
if _, err := x509.ParsePKCS8PrivateKey(p.Bytes); err != nil {
734+
b.Fatal(err)
735+
}
736+
}
737+
})
738+
}
739+
716740
type testEncryptOAEPMessage struct {
717741
in []byte
718742
seed []byte

0 commit comments

Comments
 (0)