forked from Prakhar314/TPM-Timing-Analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproj.cpp
58 lines (50 loc) · 1.59 KB
/
proj.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
// TPMTest1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <string>
#include <fstream>
#include <iterator>
#include <vector>
#include <filesystem>
#include <chrono>
#include "stdafx.h"
#include "Tpm2.h"
using namespace std;
using namespace TpmCpp;
Tpm2 tpm;
TpmTbsDevice device;
int total_time_tpm_only = 0;
void connectTPM() {
if (!device.Connect()) {
cerr << "Could not connect to the TPM device";
return;
}
// Create a Tpm2 object "on top" of the device.
tpm._SetDevice(device);
}
int getTime(){
return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
}
int main(){
connectTPM();
int times[] = {0,0,0,0,0};
vector<int> tests = {16,512,1024};
int iterations = 1000;
for(int i = 0 ; i < iterations;i++){
int start_time = getTime();
tpm.ReadClock();
times[0] += (getTime() - start_time);
start_time = getTime();
tpm.PCR_Read({}).pcrValues;
times[1] += (getTime() - start_time);
for(int tn = 0;tn<(int)tests.size();tn++){
auto b = tests[tn];
ByteVec bytes = Crypto::GetRand(b);
start_time = getTime();
tpm.Hash(bytes,TPM_ALG_ID::SHA256,TPM_RH_NULL).outHash;
times[tn+2] += (getTime() - start_time);
}
}
cout << 1.0*times[0]/iterations << "\t" << 1.0*times[1]/iterations << "\t" << 1.0*times[2]/iterations << "\t" << 1.0*times[3]/iterations<<"\t"<< 1.0*times[4]/iterations << "\t" << endl;
return 0;
}