aboutsummaryrefslogtreecommitdiffstats
path: root/src/extra_tests/timing/timing-tests/ecdsa.cpp
diff options
context:
space:
mode:
authorNever <[email protected]>2017-02-16 15:44:45 +0100
committerNever <[email protected]>2017-02-16 15:48:26 +0100
commita6c4a358dfb3b3319c3f5f643e795f0ddc14d070 (patch)
treec78d6377da28d5285eabd2a9c89a2f79f5f1b39a /src/extra_tests/timing/timing-tests/ecdsa.cpp
parentfc3f52703f62d76beda013623f745d5ac3c8cd1c (diff)
Add ecdsa timing test
Diffstat (limited to 'src/extra_tests/timing/timing-tests/ecdsa.cpp')
-rw-r--r--src/extra_tests/timing/timing-tests/ecdsa.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/extra_tests/timing/timing-tests/ecdsa.cpp b/src/extra_tests/timing/timing-tests/ecdsa.cpp
new file mode 100644
index 000000000..42f281911
--- /dev/null
+++ b/src/extra_tests/timing/timing-tests/ecdsa.cpp
@@ -0,0 +1,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);
+ }