@@ -53,7 +53,7 @@ func BenchmarkRSA_EncryptOAEP(b *testing.B) {
5353
5454// go test -v -bench=^BenchmarkRSA_DecryptPKCS1v15$ -benchtime=1s rsa_test.go
5555func BenchmarkRSA_DecryptPKCS1v15 (b * testing.B ) {
56- privateKey , err := rsa .LoadPublicKey ("rsa.key" )
56+ privateKey , err := rsa .LoadPrivateKey ("rsa.key" )
5757 if err != nil {
5858 b .Fatal (err )
5959 }
@@ -81,7 +81,7 @@ func BenchmarkRSA_DecryptPKCS1v15(b *testing.B) {
8181
8282// go test -v -bench=^BenchmarkRSA_DecryptPKCS1v15SessionKey$ -benchtime=1s rsa_test.go
8383func BenchmarkRSA_DecryptPKCS1v15SessionKey (b * testing.B ) {
84- privateKey , err := rsa .LoadPublicKey ("rsa.key" )
84+ privateKey , err := rsa .LoadPrivateKey ("rsa.key" )
8585 if err != nil {
8686 b .Fatal (err )
8787 }
@@ -95,14 +95,14 @@ func BenchmarkRSA_DecryptPKCS1v15SessionKey(b *testing.B) {
9595
9696 encrypt , err := publicKey .EncryptPKCS1v15 (sessionKey )
9797 if err != nil {
98- t .Fatal (err )
98+ b .Fatal (err )
9999 }
100100
101101 b .ReportAllocs ()
102102 b .ResetTimer ()
103103
104104 for i := 0 ; i < b .N ; i ++ {
105- err := privateKey .DecryptPKCS1v15SessionKey (encrypt , sessionKey , nil )
105+ err := privateKey .DecryptPKCS1v15SessionKey (encrypt , sessionKey )
106106 if err != nil {
107107 b .Fatal (err )
108108 }
@@ -111,7 +111,7 @@ func BenchmarkRSA_DecryptPKCS1v15SessionKey(b *testing.B) {
111111
112112// go test -v -bench=^BenchmarkRSA_DecryptOAEP$ -benchtime=1s rsa_test.go
113113func BenchmarkRSA_DecryptOAEP (b * testing.B ) {
114- privateKey , err := rsa .LoadPublicKey ("rsa.key" )
114+ privateKey , err := rsa .LoadPrivateKey ("rsa.key" )
115115 if err != nil {
116116 b .Fatal (err )
117117 }
@@ -137,50 +137,49 @@ func BenchmarkRSA_DecryptOAEP(b *testing.B) {
137137 }
138138}
139139
140- // go test -v -bench=^BenchmarkRSA_SignPSS $ -benchtime=1s rsa_test.go
141- func BenchmarkRSA_SignPSS (b * testing.B ) {
142- privateKey , err := rsa .LoadPublicKey ("rsa.key" )
140+ // go test -v -bench=^BenchmarkRSA_SignPKCS1v15 $ -benchtime=1s rsa_test.go
141+ func BenchmarkRSA_SignPKCS1v15 (b * testing.B ) {
142+ privateKey , err := rsa .LoadPrivateKey ("rsa.key" )
143143 if err != nil {
144144 b .Fatal (err )
145145 }
146146
147- digest := hash .SHA256 (rsaBenchData )
148- saltLength := 4
147+ hashed := hash .SHA256 (rsaBenchData )
149148
150149 b .ReportAllocs ()
151150 b .ResetTimer ()
152151
153152 for i := 0 ; i < b .N ; i ++ {
154- _ , err := privateKey .SignPSS ( digest , saltLength )
153+ _ , err := privateKey .SignPKCS1v15 ( hashed )
155154 if err != nil {
156155 b .Fatal (err )
157156 }
158157 }
159158}
160159
161- // go test -v -bench=^BenchmarkRSA_SignPKCS1v15 $ -benchtime=1s rsa_test.go
162- func BenchmarkRSA_SignPKCS1v15 (b * testing.B ) {
163- privateKey , err := rsa .LoadPublicKey ("rsa.key" )
160+ // go test -v -bench=^BenchmarkRSA_SignPSS $ -benchtime=1s rsa_test.go
161+ func BenchmarkRSA_SignPSS (b * testing.B ) {
162+ privateKey , err := rsa .LoadPrivateKey ("rsa.key" )
164163 if err != nil {
165164 b .Fatal (err )
166165 }
167166
168- hashed := hash .SHA256 (rsaBenchData )
167+ digest := hash .SHA256 (rsaBenchData )
169168
170169 b .ReportAllocs ()
171170 b .ResetTimer ()
172171
173172 for i := 0 ; i < b .N ; i ++ {
174- _ , err := privateKey .SignPKCS1v15 ( hashed )
173+ _ , err := privateKey .SignPSS ( digest )
175174 if err != nil {
176175 b .Fatal (err )
177176 }
178177 }
179178}
180179
181- // go test -v -bench=^BenchmarkRSA_VerifyPSS $ -benchtime=1s rsa_test.go
182- func BenchmarkRSA_VerifyPSS (b * testing.B ) {
183- privateKey , err := rsa .LoadPublicKey ("rsa.key" )
180+ // go test -v -bench=^BenchmarkRSA_VerifyPKCS1v15 $ -benchtime=1s rsa_test.go
181+ func BenchmarkRSA_VerifyPKCS1v15 (b * testing.B ) {
182+ privateKey , err := rsa .LoadPrivateKey ("rsa.key" )
184183 if err != nil {
185184 b .Fatal (err )
186185 }
@@ -190,10 +189,9 @@ func BenchmarkRSA_VerifyPSS(b *testing.B) {
190189 b .Fatal (err )
191190 }
192191
193- digest := hash .SHA256 (rsaBenchData )
194- saltLength := 4
192+ hashed := hash .SHA256 (rsaBenchData )
195193
196- sign , err := privateKey .SignPSS ( digest , saltLength )
194+ sign , err := privateKey .SignPKCS1v15 ( hashed )
197195 if err != nil {
198196 b .Fatal (err )
199197 }
@@ -202,16 +200,16 @@ func BenchmarkRSA_VerifyPSS(b *testing.B) {
202200 b .ResetTimer ()
203201
204202 for i := 0 ; i < b .N ; i ++ {
205- err = publicKey .VerifyPSS ( digest , sign , saltLength )
203+ err = publicKey .VerifyPKCS1v15 ( hashed , sign )
206204 if err != nil {
207205 b .Fatal (err )
208206 }
209207 }
210208}
211209
212- // go test -v -bench=^BenchmarkRSA_VerifyPKCS1v15 $ -benchtime=1s rsa_test.go
213- func BenchmarkRSA_VerifyPKCS1v15 (b * testing.B ) {
214- privateKey , err := rsa .LoadPublicKey ("rsa.key" )
210+ // go test -v -bench=^BenchmarkRSA_VerifyPSS $ -benchtime=1s rsa_test.go
211+ func BenchmarkRSA_VerifyPSS (b * testing.B ) {
212+ privateKey , err := rsa .LoadPrivateKey ("rsa.key" )
215213 if err != nil {
216214 b .Fatal (err )
217215 }
@@ -221,9 +219,9 @@ func BenchmarkRSA_VerifyPKCS1v15(b *testing.B) {
221219 b .Fatal (err )
222220 }
223221
224- hashed := hash .SHA256 (rsaBenchData )
222+ digest := hash .SHA256 (rsaBenchData )
225223
226- sign , err := privateKey .SignPKCS1v15 ( hashed )
224+ sign , err := privateKey .SignPSS ( digest )
227225 if err != nil {
228226 b .Fatal (err )
229227 }
@@ -232,7 +230,7 @@ func BenchmarkRSA_VerifyPKCS1v15(b *testing.B) {
232230 b .ResetTimer ()
233231
234232 for i := 0 ; i < b .N ; i ++ {
235- err = publicKey .VerifyPKCS1v15 ( hashed , sign )
233+ err = publicKey .VerifyPSS ( digest , sign )
236234 if err != nil {
237235 b .Fatal (err )
238236 }
0 commit comments