-
Notifications
You must be signed in to change notification settings - Fork 0
/
SGX_Measurement.cpp
248 lines (168 loc) · 6.01 KB
/
SGX_Measurement.cpp
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*!
*
* SGX_Measurement.cpp
*
* Copyright (c) 2020 IWATA Daiki
*
* This software is released under the MIT License.
* see http://opensource.org/licenses/mit-license
*
*/
#include "SGX_Measurement.hpp"
chrono::system_clock::time_point chrono_start;
void OCALL_chrono_start()
{
chrono_start = chrono::system_clock::now();
}
double OCALL_chrono_end()
{
chrono::system_clock::time_point chrono_end = chrono::system_clock::now();
double elapsed =
chrono::duration_cast<chrono::milliseconds>(chrono_end - chrono_start).count();
return elapsed;
}
chrono::system_clock::time_point chrono_Total_start, chrono_Total_end;
chrono::system_clock::time_point chrono_AESenc_start, chrono_AESenc_end;
chrono::system_clock::time_point chrono_AESdec_start, chrono_AESdec_end;
chrono::system_clock::time_point chrono_FileIn_start, chrono_FileIn_end;
chrono::system_clock::time_point chrono_FileOut_start, chrono_FileOut_end;
chrono::system_clock::time_point chrono_GetPath_start, chrono_GetPath_end;
chrono::system_clock::time_point chrono_WritePath_start, chrono_WritePath_end;
chrono::system_clock::time_point chrono_Check_start, chrono_Check_end;
double Total_elapsed, AESenc_elapsed, AESdec_elapsed, FileIn_elapsed, FileOut_elapsed;
double GetPath_elapsed, WritePath_elapsed, Check_elapsed;
void OCALL_chrono_Total_start()
{
chrono_Total_start = chrono::system_clock::now();
}
void OCALL_chrono_Total_end()
{
chrono_Total_end = chrono::system_clock::now();
double elapsed = chrono::duration_cast<chrono::milliseconds>(chrono_Total_end - chrono_Total_start).count();
Total_elapsed += elapsed;
}
void OCALL_chrono_AESenc_start()
{
chrono_AESenc_start = chrono::system_clock::now();
}
void OCALL_chrono_AESenc_end()
{
chrono_AESenc_end = chrono::system_clock::now();
double elapsed = chrono::duration_cast<chrono::microseconds>(chrono_AESenc_end - chrono_AESenc_start).count();
AESenc_elapsed += elapsed / 1000;
}
void OCALL_chrono_AESdec_start()
{
chrono_AESdec_start = chrono::system_clock::now();
}
void OCALL_chrono_AESdec_end()
{
chrono_AESdec_end = chrono::system_clock::now();
double elapsed = chrono::duration_cast<chrono::microseconds>(chrono_AESdec_end - chrono_AESdec_start).count();
AESdec_elapsed += elapsed / 1000;
}
void OCALL_chrono_FileIn_start()
{
chrono_FileIn_start = chrono::system_clock::now();
}
void OCALL_chrono_FileIn_end()
{
chrono_FileIn_end = chrono::system_clock::now();
double elapsed = chrono::duration_cast<chrono::microseconds>(chrono_FileIn_end - chrono_FileIn_start).count();
FileIn_elapsed += elapsed / 1000;
}
void OCALL_chrono_FileOut_start()
{
chrono_FileOut_start = chrono::system_clock::now();
}
void OCALL_chrono_FileOut_end()
{
chrono_FileOut_end = chrono::system_clock::now();
double elapsed = chrono::duration_cast<chrono::microseconds>(chrono_FileOut_end - chrono_FileOut_start).count();
FileOut_elapsed += elapsed / 1000;
}
void OCALL_chrono_GetPath_start()
{
chrono_GetPath_start = chrono::system_clock::now();
}
void OCALL_chrono_GetPath_end()
{
chrono_GetPath_end = chrono::system_clock::now();
double elapsed = chrono::duration_cast<chrono::microseconds>(chrono_GetPath_end - chrono_GetPath_start).count();
GetPath_elapsed += elapsed / 1000;
}
void OCALL_chrono_WritePath_start()
{
chrono_WritePath_start = chrono::system_clock::now();
}
void OCALL_chrono_WritePath_end()
{
chrono_WritePath_end = chrono::system_clock::now();
double elapsed = chrono::duration_cast<chrono::microseconds>(chrono_WritePath_end - chrono_WritePath_start).count();
WritePath_elapsed += elapsed / 1000;
}
void OCALL_chrono_Check_start()
{
chrono_Check_start = chrono::system_clock::now();
}
void OCALL_chrono_Check_end()
{
chrono_Check_end = chrono::system_clock::now();
double elapsed = chrono::duration_cast<chrono::microseconds>(chrono_Check_end - chrono_Check_start).count();
Check_elapsed += elapsed / 1000;
}
void OCALL_ShowMeasuredTime()
{
cout << endl;
cout << "--------------- Calculation Time ---------------" << endl;
cout << "AES encryption: " << AESenc_elapsed << "[ms]." << endl;
cout << "AES decryption: " << AESdec_elapsed << "[ms]." << endl;
cout << " File In: " << FileIn_elapsed << "[ms]." << endl;
cout << " File Out: " << FileOut_elapsed << "[ms]." << endl << endl;
cout << " GetPath() func: " << GetPath_elapsed << "[ms]." << endl;
cout << "WritePath() func: " << WritePath_elapsed << "[ms]." << endl;
cout << "\ncheck: " << Check_elapsed << "[ms]." << endl;
cout << "\nTotal: " << Total_elapsed << "[ms]." << endl;
cout << "------------------------------------------------" << endl;
cout << endl;
}
chrono::system_clock::time_point chrono_FS_start, chrono_FS_end;
chrono::system_clock::time_point chrono_ML_start, chrono_ML_end;
chrono::system_clock::time_point chrono_res_start, chrono_res_end;
void OCALL_FS_start()
{
chrono_FS_start = chrono::system_clock::now();
}
void OCALL_FS_end()
{
chrono_FS_end = chrono::system_clock::now();
}
void OCALL_ML_start()
{
chrono_ML_start = chrono::system_clock::now();
}
void OCALL_ML_end()
{
chrono_ML_end = chrono::system_clock::now();
}
void OCALL_res_start()
{
chrono_res_start = chrono::system_clock::now();
}
void OCALL_res_end()
{
chrono_res_end = chrono::system_clock::now();
}
void OCALL_ExpResult()
{
double FS_time = chrono::duration_cast<chrono::microseconds>(chrono_FS_end - chrono_FS_start).count() / 1000.0;
double ML_time = chrono::duration_cast<chrono::microseconds>(chrono_ML_end - chrono_ML_start).count() / 1000.0;
double res_time = chrono::duration_cast<chrono::microseconds>(chrono_res_end - chrono_res_start).count() / 1000.0;
cout << endl;
cout << "--------------- Calculation Time ---------------" << endl;
cout << "File Search: " << FS_time << "[ms]." << endl;
cout << "ML function: " << ML_time << "[ms]." << endl;
cout << " Total: " << res_time << "[ms]." << endl;
cout << "------------------------------------------------" << endl;
cout << endl;
}