aboutsummaryrefslogtreecommitdiffstats
path: root/src/extra_tests/timing/timing-tests/ecdsa.cpp
blob: 42f2819118dd021d92f2a4d8b5c63c61f87cbb51 (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
/* 
 * File:   ecdsa.cpp
 *
 * 
 */

#include "TimingTest.h"

ECDSATest::ECDSATest(std::vector<std::string> &inputs, std::string result_folder, std::string ecgroup) :
   m_privkey(system_rng(), Botan::EC_Group(ecgroup)),
        m_order(m_privkey.domain().get_order()),
        m_base_point(m_privkey.domain().get_base_point(), m_order),
        m_x(m_privkey.private_value()),
        m_mod_order(m_order)
   {
   m_inputs = inputs;
   m_result_folder = result_folder;
   }

std::vector<byte> ECDSATest::prepare_input(std::string input)
   {
   const std::vector<byte> input_vector = Botan::hex_decode(input);
   return input_vector;
   }

ticks ECDSATest::measure_critical_function(std::vector<byte> input)
   {
   const BigInt k(input.data(), input.size());
   const BigInt msg(system_rng(), m_order.bits());
   
   ticks start = this->get_ticks();
   
   //The following ECDSA operations involve and should not leak any information about k.
   const Botan::PointGFp k_times_P = m_base_point.blinded_multiply(k, system_rng());
   const BigInt r = m_mod_order.reduce(k_times_P.get_affine_x());
   const BigInt s = m_mod_order.multiply(inverse_mod(k, m_order), mul_add(m_x, r, msg));
   
   ticks end = get_ticks();

   return (end - start);
   }