-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathtls13.rs
More file actions
139 lines (117 loc) · 4.15 KB
/
Copy pathtls13.rs
File metadata and controls
139 lines (117 loc) · 4.15 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#![allow(clippy::let_underscore_future)]
use criterion::{criterion_group, criterion_main, Criterion};
use hmac_sha256::{Mode, Role, Tls13KeySched};
use mpz_common::context::test_mt_context;
use mpz_garble::protocol::semihonest::{Evaluator, Garbler};
use mpz_ot::ideal::cot::ideal_cot;
use mpz_vm_core::{
memory::{
binary::{Binary, U8},
correlated::Delta,
Array,
},
prelude::*,
Execute, Vm,
};
use rand::{rngs::StdRng, SeedableRng};
#[allow(clippy::unit_arg)]
fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("tls13");
group.sample_size(10);
let rt = tokio::runtime::Runtime::new().unwrap();
group.bench_function("tls13_normal", |b| {
b.to_async(&rt).iter(|| tls13(Mode::Normal))
});
group.bench_function("tls13_reduced", |b| {
b.to_async(&rt).iter(|| tls13(Mode::Reduced))
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
async fn tls13(mode: Mode) {
let mut rng = StdRng::seed_from_u64(0);
let pms = [42u8; 32];
let (mut leader_exec, mut follower_exec) = test_mt_context(8);
let mut leader_ctx = leader_exec.new_context().await.unwrap();
let mut follower_ctx = follower_exec.new_context().await.unwrap();
let delta = Delta::random(&mut rng);
let (ot_send, ot_recv) = ideal_cot(delta.into_inner());
let mut leader_vm = Garbler::new(ot_send, [0u8; 16], delta);
let mut follower_vm = Evaluator::new(ot_recv);
fn setup_ks(
vm: &mut (dyn Vm<Binary> + Send),
pms: [u8; 32],
mode: Mode,
role: Role,
) -> Tls13KeySched {
let secret: Array<U8, 32> = vm.alloc().unwrap();
vm.mark_public(secret).unwrap();
vm.assign(secret, pms).unwrap();
vm.commit(secret).unwrap();
let mut ks = Tls13KeySched::new(mode, role);
ks.alloc(vm, secret).unwrap();
ks
}
let mut leader_ks = setup_ks(&mut leader_vm, pms, mode, Role::Leader);
let mut follower_ks = setup_ks(&mut follower_vm, pms, mode, Role::Follower);
while leader_ks.wants_flush() || follower_ks.wants_flush() {
tokio::try_join!(
async {
leader_ks.flush(&mut leader_vm).unwrap();
leader_vm.execute_all(&mut leader_ctx).await
},
async {
follower_ks.flush(&mut follower_vm).unwrap();
follower_vm.execute_all(&mut follower_ctx).await
}
)
.unwrap();
}
let hello_hash = [1u8; 32];
leader_ks.set_hello_hash(hello_hash).unwrap();
follower_ks.set_hello_hash(hello_hash).unwrap();
while leader_ks.wants_flush() || follower_ks.wants_flush() {
tokio::try_join!(
async {
leader_ks.flush(&mut leader_vm).unwrap();
leader_vm.execute_all(&mut leader_ctx).await
},
async {
follower_ks.flush(&mut follower_vm).unwrap();
follower_vm.execute_all(&mut follower_ctx).await
}
)
.unwrap();
}
leader_ks.continue_to_app_keys().unwrap();
follower_ks.continue_to_app_keys().unwrap();
while leader_ks.wants_flush() || follower_ks.wants_flush() {
tokio::try_join!(
async {
leader_ks.flush(&mut leader_vm).unwrap();
leader_vm.execute_all(&mut leader_ctx).await
},
async {
follower_ks.flush(&mut follower_vm).unwrap();
follower_vm.execute_all(&mut follower_ctx).await
}
)
.unwrap();
}
let handshake_hash = [2u8; 32];
leader_ks.set_handshake_hash(handshake_hash).unwrap();
follower_ks.set_handshake_hash(handshake_hash).unwrap();
while leader_ks.wants_flush() || follower_ks.wants_flush() {
tokio::try_join!(
async {
leader_ks.flush(&mut leader_vm).unwrap();
leader_vm.execute_all(&mut leader_ctx).await
},
async {
follower_ks.flush(&mut follower_vm).unwrap();
follower_vm.execute_all(&mut follower_ctx).await
}
)
.unwrap();
}
}