use bencher::{benchmark_group, benchmark_main, Bencher}; use kzen_paillier::*; mod helpers; use helpers::*; pub fn bench_encryption_ek(b: &mut Bencher) { let keypair = KS::keypair(); let ek = EncryptionKey::from(&keypair); b.iter(|| { let _ = Paillier::encrypt(&ek, 10); }); } pub fn bench_encryption_dk(b: &mut Bencher) { let keypair = KS::keypair(); let dk = DecryptionKey::from(&keypair); b.iter(|| { let _ = Paillier::encrypt(&dk, 10); }); } pub fn bench_decryption(b: &mut Bencher) { let keypair = KS::keypair(); let (ek, dk) = keypair.keys(); let c = Paillier::encrypt(&ek, 10); b.iter(|| { let _ = Paillier::decrypt(&dk, &c); }); } pub fn bench_rerandomisation(b: &mut Bencher) { let keypair = KS::keypair(); let ek = EncryptionKey::from(&keypair); let c = Paillier::encrypt(&ek, 10); b.iter(|| { let _ = Paillier::rerandomize(&ek, &c); }); } pub fn bench_addition(b: &mut Bencher) { let keypair = KS::keypair(); let ek = EncryptionKey::from(&keypair); let c1 = Paillier::encrypt(&ek, 10); let c2 = Paillier::encrypt(&ek, 20); b.iter(|| { let _ = Paillier::add(&ek, &c1, &c2); }); } pub fn bench_multiplication(b: &mut Bencher) { let keypair = KS::keypair(); let ek = EncryptionKey::from(&keypair); let c = Paillier::encrypt(&ek, 10); b.iter(|| { let _ = Paillier::mul(&ek, &c, 20); }); } benchmark_group!( ks_2048, self::bench_encryption_ek, self::bench_encryption_dk, self::bench_decryption, self::bench_rerandomisation, self::bench_addition, self::bench_multiplication ); benchmark_group!( ks_4096, self::bench_encryption_ek, self::bench_encryption_dk, self::bench_decryption, self::bench_rerandomisation, self::bench_addition, self::bench_multiplication ); benchmark_main!(ks_2048, ks_4096);