aboutsummaryrefslogtreecommitdiffstats
path: root/src/extra_tests/timing/timing-tests/BleichenbacherTest.cpp
blob: abef8a7bec81be8b166cfb884a9dfebd28a62b6f (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
/* 
 * File:   BleichenbacherTest.cpp
 * Author: Juraj Somorovsky - juraj.somorovsky@hackmanit.de
 * 
 */

#include "TimingTest.h"

BleichenbacherTest::BleichenbacherTest(std::vector<std::string> &inputs,
        std::string result_folder, int keysize) : 
   m_privkey(system_rng(), keysize), 
   m_pubkey(m_privkey), 
   m_enc(m_pubkey, m_encrypt_padding), 
   m_dec(m_privkey, m_decrypt_padding) 
   {
   m_inputs = inputs;
   m_result_folder = result_folder;
   }

std::vector<byte> BleichenbacherTest::prepare_input(std::string input)
   {
   const std::vector<uint8_t> input_vector = Botan::hex_decode(input);
   const std::vector<byte> encrypted = m_enc.encrypt(input_vector, system_rng());
   return encrypted;
   }

ticks BleichenbacherTest::measure_critical_function(std::vector<byte> input)
   {
   const Botan::byte* in = &input[0];

   ticks start = this->get_ticks();
   m_dec.decrypt_or_random(in, m_ctext_length, m_expected_content_size, system_rng());
   ticks end = get_ticks();

   return (end - start);
   }