• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 21031897445

15 Jan 2026 12:50PM UTC coverage: 90.037% (-0.4%) from 90.395%
21031897445

Pull #5240

github

web-flow
Merge 13ffffdd5 into 32478179d
Pull Request #5240: Some changes to reduce time taken by the coverage build

102027 of 113317 relevant lines covered (90.04%)

11676540.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/cli/perf_ec.cpp
1
/*
2
* (C) 2024 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "perf.h"
8

9
#if defined(BOTAN_HAS_ECC_GROUP)
10
   #include <botan/assert.h>
11
   #include <botan/ec_group.h>
12
#endif
13

14
namespace Botan_CLI {
15

16
#if defined(BOTAN_HAS_ECC_GROUP)
17

18
class PerfTest_EllipticCurve final : public PerfTest {
×
19
   public:
20
      void go(const PerfConfig& config) override {
×
21
         const auto run = config.runtime();
×
22
         auto& rng = config.rng();
×
23

24
         for(const auto& group_name : config.ecc_groups()) {
×
25
            auto init_timer = config.make_timer(group_name + " initialization");
×
26

27
            while(init_timer->under(run)) {
×
28
               Botan::EC_Group::clear_registered_curve_data();
×
29
               init_timer->run([&]() { Botan::EC_Group::from_name(group_name); });
×
30
            }
31

32
            config.record_result(*init_timer);
×
33

34
            const auto group = Botan::EC_Group::from_name(group_name);
×
35

36
            auto bp_timer = config.make_timer(group_name + " base point mul");
×
37
            auto vp_timer = config.make_timer(group_name + " variable point mul");
×
38
            auto add_timer = config.make_timer(group_name + " point addition");
×
39
            auto der_uc_timer = config.make_timer(group_name + " point deserialize (uncompressed)");
×
40
            auto der_c_timer = config.make_timer(group_name + " point deserialize (compressed)");
×
41
            auto mul2_setup_timer = config.make_timer(group_name + " mul2_vartime setup");
×
42
            auto mul2_vt_timer = config.make_timer(group_name + " mul2_vartime");
×
43
            auto mul2_ct_timer = config.make_timer(group_name + " mul2");
×
44
            auto scalar_inv_timer = config.make_timer(group_name + " scalar inversion");
×
45
            auto scalar_inv_vt_timer = config.make_timer(group_name + " scalar inversion vartime");
×
46
            auto h2c_nu_timer = config.make_timer(group_name + " hash to curve (NU)");
×
47
            auto h2c_ro_timer = config.make_timer(group_name + " hash to curve (RO)");
×
48

49
            auto g = Botan::EC_AffinePoint::generator(group);
×
50

51
            const bool h2c_supported = [&]() {
×
52
               try {
×
53
                  Botan::EC_AffinePoint::hash_to_curve_nu(group, "SHA-256", {}, "");
×
54
               } catch(Botan::Not_Implemented&) {
×
55
                  return false;
×
56
               }
×
57
               return true;
×
58
            }();
×
59

60
            while(bp_timer->under(run) && vp_timer->under(run)) {
×
61
               const auto k = Botan::EC_Scalar::random(group, rng);
×
62
               const auto k2 = Botan::EC_Scalar::random(group, rng);
×
63
               const auto r1 = bp_timer->run([&]() { return Botan::EC_AffinePoint::g_mul(k, rng); });
×
64
               const auto r2 = vp_timer->run([&]() { return g.mul(k, rng); });
×
65

66
               const auto r1_bytes = r1.serialize_uncompressed();
×
67
               const auto r2_bytes = r2.serialize_uncompressed();
×
68
               BOTAN_ASSERT_EQUAL(r1_bytes, r2_bytes, "Same result for multiplication");
×
69

70
               add_timer->run([&]() { r1.add(r2); });
×
71

72
               der_uc_timer->run([&]() { Botan::EC_AffinePoint::deserialize(group, r1_bytes); });
×
73

74
               const auto r1_cbytes = r1.serialize_compressed();
×
75
               der_c_timer->run([&]() { Botan::EC_AffinePoint::deserialize(group, r1_cbytes); });
×
76

77
               auto mul2 = mul2_setup_timer->run([&]() { return Botan::EC_Group::Mul2Table(r1); });
×
78

79
               auto pt = mul2_vt_timer->run([&]() { return mul2.mul2_vartime(k, k2); });
×
80

81
               auto pt2 = mul2_ct_timer->run([&]() { return Botan::EC_AffinePoint::mul_px_qy(g, k, r1, k2, rng); });
×
82

83
               if(h2c_supported) {
×
84
                  h2c_nu_timer->run([&]() { Botan::EC_AffinePoint::hash_to_curve_nu(group, "SHA-256", r1_bytes, ""); });
×
85
                  h2c_ro_timer->run([&]() { Botan::EC_AffinePoint::hash_to_curve_ro(group, "SHA-256", r1_bytes, ""); });
×
86
               }
87
            }
×
88

89
            while(scalar_inv_timer->under(config.runtime())) {
×
90
               const auto k = Botan::EC_Scalar::random(group, rng);
×
91
               auto k_vt_inv = scalar_inv_vt_timer->run([&]() { return k.invert_vartime(); });
×
92
               auto k_inv = scalar_inv_timer->run([&]() { return k.invert(); });
×
93
               BOTAN_ASSERT_EQUAL(k_inv, k_vt_inv, "Same result for inversion");
×
94
            }
×
95

96
            config.record_result(*add_timer);
×
97
            config.record_result(*bp_timer);
×
98
            config.record_result(*vp_timer);
×
99
            config.record_result(*mul2_setup_timer);
×
100
            config.record_result(*mul2_vt_timer);
×
101
            config.record_result(*mul2_ct_timer);
×
102
            config.record_result(*scalar_inv_timer);
×
103
            config.record_result(*scalar_inv_vt_timer);
×
104
            config.record_result(*der_uc_timer);
×
105
            config.record_result(*der_c_timer);
×
106

107
            if(h2c_supported) {
×
108
               config.record_result(*h2c_nu_timer);
×
109
               config.record_result(*h2c_ro_timer);
×
110
            }
111
         }
×
112
      }
×
113
};
114

115
BOTAN_REGISTER_PERF_TEST("ecc", PerfTest_EllipticCurve);
×
116

117
#endif
118

119
}  // namespace Botan_CLI
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc