File: benchmark_test.go

package info (click to toggle)
golang-github-smallstep-crypto 0.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,800 kB
  • sloc: sh: 66; makefile: 50
file content (83 lines) | stat: -rw-r--r-- 2,010 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//go:build cgo
// +build cgo

package pkcs11

import (
	"crypto"
	"crypto/rand"
	"crypto/rsa"
	"testing"

	"go.step.sm/crypto/kms/apiv1"
)

func benchmarkSign(b *testing.B, signer crypto.Signer, opts crypto.SignerOpts) {
	hash := opts.HashFunc()
	h := hash.New()
	h.Write([]byte("buggy-coheir-RUBRIC-rabbet-liberal-eaglet-khartoum-stagger"))
	digest := h.Sum(nil)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_, _ = signer.Sign(rand.Reader, digest, opts)
	}
	b.StopTimer()
}

func BenchmarkSignRSA(b *testing.B) {
	k := setupPKCS11(b)
	signer, err := k.CreateSigner(&apiv1.CreateSignerRequest{
		SigningKey: "pkcs11:id=7371;object=rsa-key",
	})
	if err != nil {
		b.Fatalf("PKCS11.CreateSigner() error = %v", err)
	}
	benchmarkSign(b, signer, crypto.SHA256)
}

func BenchmarkSignRSAPSS(b *testing.B) {
	k := setupPKCS11(b)
	signer, err := k.CreateSigner(&apiv1.CreateSignerRequest{
		SigningKey: "pkcs11:id=7372;object=rsa-pss-key",
	})
	if err != nil {
		b.Fatalf("PKCS11.CreateSigner() error = %v", err)
	}
	benchmarkSign(b, signer, &rsa.PSSOptions{
		SaltLength: rsa.PSSSaltLengthEqualsHash,
		Hash:       crypto.SHA256,
	})
}

func BenchmarkSignP256(b *testing.B) {
	k := setupPKCS11(b)
	signer, err := k.CreateSigner(&apiv1.CreateSignerRequest{
		SigningKey: "pkcs11:id=7373;object=ecdsa-p256-key",
	})
	if err != nil {
		b.Fatalf("PKCS11.CreateSigner() error = %v", err)
	}
	benchmarkSign(b, signer, crypto.SHA256)
}

func BenchmarkSignP384(b *testing.B) {
	k := setupPKCS11(b)
	signer, err := k.CreateSigner(&apiv1.CreateSignerRequest{
		SigningKey: "pkcs11:id=7374;object=ecdsa-p384-key",
	})
	if err != nil {
		b.Fatalf("PKCS11.CreateSigner() error = %v", err)
	}
	benchmarkSign(b, signer, crypto.SHA384)
}

func BenchmarkSignP521(b *testing.B) {
	k := setupPKCS11(b)
	signer, err := k.CreateSigner(&apiv1.CreateSignerRequest{
		SigningKey: "pkcs11:id=7375;object=ecdsa-p521-key",
	})
	if err != nil {
		b.Fatalf("PKCS11.CreateSigner() error = %v", err)
	}
	benchmarkSign(b, signer, crypto.SHA512)
}