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

randombit / botan / 11856050109

15 Nov 2024 12:13PM UTC coverage: 91.073% (-0.002%) from 91.075%
11856050109

push

github

web-flow
Merge pull request #4433 from randombit/jack/mul-px-qy

Add a constant time p*x + q*y ECC operation

90625 of 99508 relevant lines covered (91.07%)

9482119.51 hits per line

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

95.0
/src/tests/test_ecc_pointmul.cpp
1
/*
2
* (C) 2014,2015,2019 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#if defined(BOTAN_HAS_BIGINT)
10
   #include <botan/bigint.h>
11
#endif
12

13
#if defined(BOTAN_HAS_ECC_GROUP)
14
   #include <botan/ec_group.h>
15
#endif
16

17
namespace Botan_Tests {
18

19
namespace {
20

21
#if defined(BOTAN_HAS_ECC_GROUP)
22

23
class ECC_Basepoint_Mul_Tests final : public Text_Based_Test {
×
24
   public:
25
      ECC_Basepoint_Mul_Tests() : Text_Based_Test("pubkey/ecc_base_point_mul.vec", "k,P") {}
2✔
26

27
      Test::Result run_one_test(const std::string& group_id, const VarMap& vars) override {
533✔
28
         Test::Result result("ECC base point multiply " + group_id);
533✔
29

30
         const auto k_bytes = vars.get_req_bin("k");
533✔
31
         const auto P_bytes = vars.get_req_bin("P");
533✔
32

33
         const auto group = Botan::EC_Group::from_name(group_id);
533✔
34

35
         const Botan::BigInt k(k_bytes);
533✔
36
         const auto pt = group.OS2ECP(P_bytes);
533✔
37

38
         const Botan::EC_Point& base_point = group.get_base_point();
533✔
39

40
         const Botan::EC_Point p1 = base_point * k;
533✔
41
         result.test_eq("mul with *", p1, pt);
533✔
42

43
         std::vector<Botan::BigInt> ws;
533✔
44
         const Botan::EC_Point p2 = group.blinded_base_point_multiply(k, this->rng(), ws);
533✔
45
         result.test_eq("blinded_base_point_multiply", p2, pt);
533✔
46

47
         const Botan::EC_Point p3 = group.blinded_var_point_multiply(base_point, k, this->rng(), ws);
533✔
48
         result.test_eq("blinded_var_point_multiply", p3, pt);
533✔
49

50
         const auto scalar = Botan::EC_Scalar::from_bigint(group, k);
533✔
51
         const auto apg = Botan::EC_AffinePoint::g_mul(scalar, this->rng(), ws);
533✔
52
         result.test_eq("AffinePoint::g_mul", apg.serialize_uncompressed(), P_bytes);
1,066✔
53

54
         const auto ag = Botan::EC_AffinePoint(group, base_point);
533✔
55
         const auto ap = ag.mul(scalar, this->rng(), ws);
533✔
56
         result.test_eq("AffinePoint::mul", ap.to_legacy_point(), pt);
1,066✔
57

58
         return result;
1,066✔
59
      }
2,132✔
60
};
61

62
BOTAN_REGISTER_TEST("pubkey", "ecc_basemul", ECC_Basepoint_Mul_Tests);
63

64
class ECC_Varpoint_Mul_Tests final : public Text_Based_Test {
×
65
   public:
66
      ECC_Varpoint_Mul_Tests() : Text_Based_Test("pubkey/ecc_var_point_mul.vec", "P,k,Z") {}
2✔
67

68
      Test::Result run_one_test(const std::string& group_id, const VarMap& vars) override {
829✔
69
         Test::Result result("ECC var point multiply " + group_id);
829✔
70

71
         const auto p = vars.get_req_bin("P");
829✔
72
         const Botan::BigInt k = vars.get_req_bn("k");
829✔
73
         const auto z = vars.get_req_bin("Z");
829✔
74

75
         const auto group = Botan::EC_Group::from_name(group_id);
829✔
76

77
         const Botan::EC_Point pt = group.OS2ECP(p);
829✔
78

79
         result.confirm("Input point is on the curve", pt.on_the_curve());
1,658✔
80

81
         const Botan::EC_Point p1 = pt * k;
829✔
82
         result.test_eq("p * k", p1.encode(Botan::EC_Point::Compressed), z);
1,658✔
83

84
         result.confirm("Output point is on the curve", p1.on_the_curve());
1,658✔
85

86
         std::vector<Botan::BigInt> ws;
829✔
87
         const Botan::EC_Point p2 = group.blinded_var_point_multiply(pt, k, this->rng(), ws);
829✔
88
         result.test_eq("p * k (blinded)", p2.encode(Botan::EC_Point::Compressed), z);
2,487✔
89

90
         const auto apt = Botan::EC_AffinePoint::deserialize(group, p).value();
1,658✔
91
         const auto apt_k = apt.mul(Botan::EC_Scalar::from_bigint(group, k), this->rng(), ws);
829✔
92
         result.test_eq("p * k (AffinePoint)", apt_k.serialize_compressed(), z);
1,658✔
93

94
         return result;
1,658✔
95
      }
3,316✔
96
};
97

98
BOTAN_REGISTER_TEST("pubkey", "ecc_varmul", ECC_Varpoint_Mul_Tests);
99

100
class ECC_Mul2_Tests final : public Text_Based_Test {
×
101
   public:
102
      ECC_Mul2_Tests() : Text_Based_Test("pubkey/ecc_var_point_mul2.vec", "P,x,Q,y,Z") {}
2✔
103

104
      Test::Result run_one_test(const std::string& group_id, const VarMap& vars) override {
819✔
105
         Test::Result result("ECC mul2 " + group_id);
819✔
106

107
         const auto Z_bytes = vars.get_req_bin("Z");
819✔
108

109
         const auto group = Botan::EC_Group::from_name(group_id);
819✔
110

111
         const auto p = Botan::EC_AffinePoint::deserialize(group, vars.get_req_bin("P")).value();
3,276✔
112
         const auto q = Botan::EC_AffinePoint::deserialize(group, vars.get_req_bin("Q")).value();
3,276✔
113
         const auto x = Botan::EC_Scalar::from_bigint(group, vars.get_req_bn("x"));
1,638✔
114
         const auto y = Botan::EC_Scalar::from_bigint(group, vars.get_req_bn("y"));
1,638✔
115

116
         const auto z1 = Botan::EC_AffinePoint::mul_px_qy(p, x, q, y, rng());
819✔
117

118
         result.test_eq("EC_AffinePoint::mul_px_qy", z1.serialize_compressed(), Z_bytes);
1,638✔
119

120
         return result;
1,638✔
121
      }
1,638✔
122
};
123

124
BOTAN_REGISTER_TEST("pubkey", "ecc_mul2", ECC_Mul2_Tests);
125

126
#endif
127

128
}  // namespace
129

130
}  // namespace Botan_Tests
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

© 2025 Coveralls, Inc