Skip to content

Commit

Permalink
add rsa benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Mar 17, 2022
1 parent 0bd3593 commit 1c22c15
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cng/rsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package cng
import (
"bytes"
"crypto"
"math/big"
"strconv"
"testing"
)
Expand Down Expand Up @@ -163,3 +164,28 @@ func TestSignVerifyRSAPSS(t *testing.T) {
t.Fatal(err)
}
}

func fromBase36(base36 string) *big.Int {
i, ok := new(big.Int).SetString(base36, 36)
if !ok {
panic("bad number: " + base36)
}
return i
}

func BenchmarkEncryptRSAPKCS1(b *testing.B) {
b.StopTimer()
// Public key length should be at least of 2048 bits, else OpenSSL will report an error when running in FIPS mode.
n := fromBase36("14314132931241006650998084889274020608918049032671858325988396851334124245188214251956198731333464217832226406088020736932173064754214329009979944037640912127943488972644697423190955557435910767690712778463524983667852819010259499695177313115447116110358524558307947613422897787329221478860907963827160223559690523660574329011927531289655711860504630573766609239332569210831325633840174683944553667352219670930408593321661375473885147973879086994006440025257225431977751512374815915392249179976902953721486040787792801849818254465486633791826766873076617116727073077821584676715609985777563958286637185868165868520557")
test2048PubKey, err := NewPublicKeyRSA(n, big.NewInt(3))
if err != nil {
b.Fatal(err)
}
b.StartTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := EncryptRSAPKCS1(test2048PubKey, []byte("testing")); err != nil {
b.Fatal(err)
}
}
}

0 comments on commit 1c22c15

Please sign in to comment.