forked from mortendahl/rust-paillier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryption.rs
96 lines (75 loc) · 2.21 KB
/
encryption.rs
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
84
85
86
87
88
89
90
91
92
93
94
95
96
#[macro_use]
extern crate bencher;
extern crate num_traits;
extern crate paillier;
use bencher::Bencher;
use paillier::encoding::*;
use paillier::*;
mod helpers;
use helpers::*;
pub fn bench_encryption_ek<KS: KeySize>(b: &mut Bencher) {
let ref keypair = KS::keypair();
let ek = EncryptionKey::from(keypair);
b.iter(|| {
let _ = Paillier::encrypt(&ek, 10);
});
}
pub fn bench_encryption_dk<KS: KeySize>(b: &mut Bencher) {
let ref keypair = KS::keypair();
let dk = DecryptionKey::from(keypair);
b.iter(|| {
let _ = Paillier::encrypt(&dk, 10);
});
}
pub fn bench_decryption<KS: KeySize>(b: &mut Bencher) {
let ref 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<KS: KeySize>(b: &mut Bencher) {
let ref 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<KS: KeySize>(b: &mut Bencher) {
let ref 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<KS: KeySize>(b: &mut Bencher) {
let ref 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<KeySize2048>,
self::bench_encryption_dk<KeySize2048>,
self::bench_decryption<KeySize2048>,
self::bench_rerandomisation<KeySize2048>,
self::bench_addition<KeySize2048>,
self::bench_multiplication<KeySize2048>
);
benchmark_group!(
ks_4096,
self::bench_encryption_ek<KeySize4096>,
self::bench_encryption_dk<KeySize4096>,
self::bench_decryption<KeySize4096>,
self::bench_rerandomisation<KeySize4096>,
self::bench_addition<KeySize4096>,
self::bench_multiplication<KeySize4096>
);
benchmark_main!(ks_2048, ks_4096);