Skip to content

Commit bc39c04

Browse files
bench: add key gen benchmarks
1 parent 1e21564 commit bc39c04

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

benches/key.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate test;
55
use base64ct::{Base64, Encoding};
66
use crypto_bigint::BoxedUint;
77
use hex_literal::hex;
8-
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
8+
use rand_chacha::{ChaCha8Rng, rand_core::SeedableRng};
99
use rsa::{Pkcs1v15Encrypt, Pkcs1v15Sign, RsaPrivateKey};
1010
use sha2::{Digest, Sha256};
1111
use test::Bencher;
@@ -75,6 +75,26 @@ fn get_key() -> RsaPrivateKey {
7575
.unwrap()
7676
}
7777

78+
#[bench]
79+
fn bench_rsa_1024_gen_key(b: &mut Bencher) {
80+
let mut rng = ChaCha8Rng::from_seed([42; 32]);
81+
82+
b.iter(|| {
83+
let key = RsaPrivateKey::new(&mut rng, 1024).unwrap();
84+
test::black_box(key);
85+
});
86+
}
87+
88+
#[bench]
89+
fn bench_rsa_2048_gen_key(b: &mut Bencher) {
90+
let mut rng = ChaCha8Rng::from_seed([42; 32]);
91+
92+
b.iter(|| {
93+
let key = RsaPrivateKey::new(&mut rng, 2048).unwrap();
94+
test::black_box(key);
95+
});
96+
}
97+
7898
#[bench]
7999
fn bench_rsa_2048_pkcsv1_decrypt(b: &mut Bencher) {
80100
let priv_key = get_key();

0 commit comments

Comments
 (0)