blob: a0295c6fd3fa79e068af2b78562e82bc9d567b74 (
plain)
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
|
/*
* File: TimingTest.h
* Author: Juraj Somorovsky - juraj.somorovsky@hackmanit.de
*
*/
#ifndef TIMINGTEST_H
#define TIMINGTEST_H
#include <botan/pubkey.h>
#include <botan/rsa.h>
#include <botan/system_rng.h>
#include <botan/hex.h>
#include <botan/rng.h>
#include <botan/numthry.h>
#include <iostream>
#include <vector>
#include <fstream>
#include <botan/internal/tls_cbc.h>
#include <botan/tls_exceptn.h>
#include <botan/cipher_mode.h>
#include <botan/ecdsa.h>
#include <botan/reducer.h>
using namespace Botan;
typedef unsigned long long ticks;
class TimingTest
{
protected:
std::string m_result_folder;
std::vector<std::string> m_inputs;
std::vector<ticks> m_results;
unsigned int m_warmup_iterations = 500;
unsigned int m_measurement_iterations = 10000;
virtual std::vector<byte> prepare_input(std::string input) = 0;
virtual ticks measure_critical_function(std::vector<byte> input) = 0;
public:
TimingTest();
virtual ~TimingTest();
void execute_evaluation();
void store_results_in_file(std::string file_name);
ticks get_ticks();
};
class BleichenbacherTest : public TimingTest
{
private:
const std::string m_encrypt_padding = "Raw";
const std::string m_decrypt_padding = "PKCS1v15";
const size_t m_expected_content_size = 48;
const size_t m_ctext_length = 256;
RSA_PrivateKey m_privkey;
RSA_PublicKey m_pubkey;
PK_Encryptor_EME m_enc;
PK_Decryptor_EME m_dec;
protected:
std::vector<byte> prepare_input(std::string input) override;
ticks measure_critical_function(std::vector<byte> input) override;
public:
BleichenbacherTest(std::vector<std::string> &inputs, std::string result_file, int keysize);
};
class MangerTest : public TimingTest
{
private:
const std::string m_encrypt_padding = "Raw";
const std::string m_decrypt_padding = "EME1(SHA-256)";
const size_t m_ctext_length = 256;
RSA_PrivateKey m_privkey;
RSA_PublicKey m_pubkey;
PK_Encryptor_EME m_enc;
PK_Decryptor_EME m_dec;
protected:
std::vector<byte> prepare_input(std::string input) override;
ticks measure_critical_function(std::vector<byte> input) override;
public:
MangerTest(std::vector<std::string> &inputs, std::string result_file, int keysize);
};
class Lucky13Test : public TimingTest
{
private:
const std::string m_mac_algo;
const size_t m_mac_keylen;
Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption m_dec;
protected:
std::vector<byte> prepare_input(std::string input) override;
ticks measure_critical_function(std::vector<byte> input) override;
public:
Lucky13Test(std::vector<std::string> &inputs, std::string result_file,
const std::string& mac_name, size_t mac_keylen);
};
class ECDSATest : public TimingTest
{
private:
const ECDSA_PrivateKey m_privkey;
const BigInt m_order;
Blinded_Point_Multiply m_base_point;
const BigInt m_x;
const Modular_Reducer m_mod_order;
protected:
std::vector<byte> prepare_input(std::string input) override;
ticks measure_critical_function(std::vector<byte> input) override;
public:
ECDSATest(std::vector<std::string> &inputs, std::string result_folder, std::string ecgroup);
};
#endif /* TIMINGTEST_H */
|