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

randombit / botan / 22219971043

20 Feb 2026 10:10AM UTC coverage: 90.331% (+0.001%) from 90.33%
22219971043

Pull #5356

github

web-flow
Merge fc5a2e175 into 2cf293ee6
Pull Request #5356: Refactor: Generalize the SEC.1 decoder

103030 of 114058 relevant lines covered (90.33%)

11449806.04 hits per line

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

93.7
/src/tests/test_ec_group.cpp
1
/*
2
* (C) 2007 Falko Strenzke
3
*     2007 Manuel Hartl
4
*     2009,2015,2018,2021 Jack Lloyd
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
*/
8

9
#include "tests.h"
10

11
#if defined(BOTAN_HAS_ECC_GROUP)
12
   #include <botan/bigint.h>
13
   #include <botan/data_src.h>
14
   #include <botan/ec_group.h>
15
   #include <botan/hex.h>
16
   #include <botan/numthry.h>
17
   #include <botan/pk_keys.h>
18
   #include <botan/rng.h>
19
   #include <botan/x509_key.h>
20
   #include <botan/internal/barrett.h>
21
   #include <botan/internal/ec_inner_data.h>
22
   #include <botan/internal/ec_sec1.h>
23
   #include <botan/internal/stl_util.h>
24

25
   #if defined(BOTAN_HAS_ECDSA)
26
      #include <botan/pk_algs.h>
27
   #endif
28
#endif
29

30
namespace Botan_Tests {
31

32
namespace {
33

34
#if defined(BOTAN_HAS_ECC_GROUP)
35

36
   #if defined(BOTAN_HAS_LEGACY_EC_POINT)
37

38
Botan::BigInt test_integer(Botan::RandomNumberGenerator& rng, size_t bits, const BigInt& max) {
560✔
39
   /*
40
   Produces integers with long runs of ones and zeros, for testing for
41
   carry handling problems.
42
   */
43
   Botan::BigInt x = 0;
560✔
44

45
   auto flip_prob = [](size_t i) -> double {
154,040✔
46
      if(i % 64 == 0) {
153,480✔
47
         return .5;
48
      }
49
      if(i % 32 == 0) {
150,980✔
50
         return .4;
51
      }
52
      if(i % 8 == 0) {
148,560✔
53
         return .05;
14,360✔
54
      }
55
      return .01;
56
   };
57

58
   bool active = (rng.next_byte() > 128) ? true : false;
560✔
59
   for(size_t i = 0; i != bits; ++i) {
154,040✔
60
      x <<= 1;
153,480✔
61
      x += static_cast<int>(active);
153,480✔
62

63
      const double prob = flip_prob(i);
153,480✔
64
      const double sample = double(rng.next_byte() % 100) / 100.0;  // biased
153,480✔
65

66
      if(sample < prob) {
153,480✔
67
         active = !active;
4,959✔
68
      }
69
   }
70

71
   if(x == 0) {
560✔
72
      // EC_Scalar rejects zero as an input, if we hit this case instead
73
      // test with a completely randomized scalar
74
      return BigInt::random_integer(rng, 1, max);
1✔
75
   }
76

77
   if(max > 0) {
559✔
78
      while(x >= max) {
640✔
79
         const size_t b = x.bits() - 1;
81✔
80
         BOTAN_ASSERT(x.get_bit(b) == true, "Set");
162✔
81
         x.clear_bit(b);
81✔
82
      }
83
   }
84

85
   return x;
559✔
86
}
560✔
87

88
Botan::EC_Point create_random_point(Botan::RandomNumberGenerator& rng, const Botan::EC_Group& group) {
112✔
89
   const Botan::BigInt& p = group.get_p();
112✔
90
   auto mod_p = Botan::Barrett_Reduction::for_public_modulus(p);
112✔
91

92
   for(;;) {
135✔
93
      const Botan::BigInt x = Botan::BigInt::random_integer(rng, 1, p);
247✔
94
      const Botan::BigInt x3 = mod_p.multiply(x, mod_p.square(x));
247✔
95
      const Botan::BigInt ax = mod_p.multiply(group.get_a(), x);
247✔
96
      const Botan::BigInt y = mod_p.reduce(x3 + ax + group.get_b());
247✔
97
      const Botan::BigInt sqrt_y = Botan::sqrt_modulo_prime(y, p);
247✔
98

99
      if(sqrt_y > 1) {
247✔
100
         BOTAN_ASSERT_EQUAL(mod_p.square(sqrt_y), y, "Square root is correct");
224✔
101
         return group.point(x, sqrt_y);
112✔
102
      }
103
   }
247✔
104
}
112✔
105

106
class ECC_Randomized_Tests final : public Test {
1✔
107
   public:
108
      std::vector<Test::Result> run() override;
109
};
110

111
std::vector<Test::Result> ECC_Randomized_Tests::run() {
1✔
112
   std::vector<Test::Result> results;
1✔
113
   for(const std::string& group_name : Botan::EC_Group::known_named_groups()) {
29✔
114
      Test::Result result("ECC randomized " + group_name);
28✔
115

116
      result.start_timer();
28✔
117

118
      auto group = Botan::EC_Group::from_name(group_name);
28✔
119

120
      const Botan::EC_Point pt = create_random_point(this->rng(), group);
28✔
121

122
      try {
28✔
123
         std::vector<Botan::BigInt> blind_ws;
28✔
124
         const size_t trials = (Test::run_long_tests() ? 10 : 3);
28✔
125
         for(size_t i = 0; i < trials; ++i) {
308✔
126
            const Botan::BigInt a = test_integer(rng(), group.get_order_bits(), group.get_order());
280✔
127
            const Botan::BigInt b = test_integer(rng(), group.get_order_bits(), group.get_order());
280✔
128
            const Botan::BigInt c = group.mod_order(a + b);
280✔
129

130
            const Botan::EC_Point P = pt * a;
280✔
131
            const Botan::EC_Point Q = pt * b;
280✔
132
            const Botan::EC_Point R = pt * c;
280✔
133

134
            Botan::EC_Point P1 = group.blinded_var_point_multiply(pt, a, this->rng(), blind_ws);
280✔
135
            Botan::EC_Point Q1 = group.blinded_var_point_multiply(pt, b, this->rng(), blind_ws);
280✔
136
            Botan::EC_Point R1 = group.blinded_var_point_multiply(pt, c, this->rng(), blind_ws);
280✔
137

138
            Botan::EC_Point A1 = P + Q;
280✔
139
            Botan::EC_Point A2 = Q + P;
280✔
140

141
            result.test_bin_eq("p + q", A1.xy_bytes(), R.xy_bytes());
560✔
142
            result.test_bin_eq("q + p", A2.xy_bytes(), R.xy_bytes());
560✔
143

144
            A1.force_affine();
280✔
145
            A2.force_affine();
280✔
146
            result.test_bin_eq("p + q", A1.xy_bytes(), R.xy_bytes());
560✔
147
            result.test_bin_eq("q + p", A2.xy_bytes(), R.xy_bytes());
560✔
148

149
            result.test_is_true("p on the curve", P.on_the_curve());
280✔
150
            result.test_is_true("q on the curve", Q.on_the_curve());
280✔
151
            result.test_is_true("r on the curve", R.on_the_curve());
280✔
152

153
            result.test_bin_eq("P1", P1.xy_bytes(), P.xy_bytes());
560✔
154
            result.test_bin_eq("Q1", Q1.xy_bytes(), Q.xy_bytes());
560✔
155
            result.test_bin_eq("R1", R1.xy_bytes(), R.xy_bytes());
560✔
156

157
            P1.force_affine();
280✔
158
            Q1.force_affine();
280✔
159
            R1.force_affine();
280✔
160
            result.test_bin_eq("P1", P1.xy_bytes(), P.xy_bytes());
560✔
161
            result.test_bin_eq("Q1", Q1.xy_bytes(), Q.xy_bytes());
560✔
162
            result.test_bin_eq("R1", R1.xy_bytes(), R.xy_bytes());
560✔
163
         }
280✔
164
      } catch(std::exception& e) {
28✔
165
         result.test_failure(group_name, e.what());
×
166
      }
×
167
      result.end_timer();
28✔
168
      results.push_back(result);
28✔
169
   }
28✔
170

171
   return results;
1✔
172
}
×
173

174
BOTAN_REGISTER_TEST("pubkey", "ecc_randomized", ECC_Randomized_Tests);
175

176
   #endif
177

178
class EC_Group_Tests : public Test {
1✔
179
   public:
180
      std::vector<Test::Result> run() override {
1✔
181
         std::vector<Test::Result> results;
1✔
182

183
         for(const std::string& group_name : Botan::EC_Group::known_named_groups()) {
29✔
184
            Test::Result result("EC_Group " + group_name);
28✔
185

186
            result.start_timer();
28✔
187

188
            const auto group = Botan::EC_Group::from_name(group_name);
28✔
189

190
            result.test_is_true("EC_Group is known", group.get_curve_oid().has_value());
28✔
191
            result.test_is_true("EC_Group is considered valid", group.verify_group(this->rng(), true));
28✔
192
            result.test_is_true("EC_Group is not considered explicit encoding", !group.used_explicit_encoding());
28✔
193

194
            result.test_sz_eq("EC_Group has correct bit size", group.get_p().bits(), group.get_p_bits());
28✔
195
            result.test_sz_eq("EC_Group has byte size", group.get_p().bytes(), group.get_p_bytes());
28✔
196

197
            result.test_bn_eq("EC_Group has cofactor == 1", group.get_cofactor(), 1);
28✔
198

199
            const Botan::OID from_order = Botan::EC_Group::EC_group_identity_from_order(group.get_order());
28✔
200

201
            result.test_str_eq(
28✔
202
               "EC_group_identity_from_order works", from_order.to_string(), group.get_curve_oid().to_string());
56✔
203

204
            result.test_is_true("Same group is same", group == Botan::EC_Group::from_name(group_name));
28✔
205

206
            try {
28✔
207
               const Botan::EC_Group copy(group.get_curve_oid(),
28✔
208
                                          group.get_p(),
209
                                          group.get_a(),
210
                                          group.get_b(),
211
                                          group.get_g_x(),
212
                                          group.get_g_y(),
213
                                          group.get_order());
28✔
214

215
               result.test_is_true("Same group is same even with copy", group == copy);
20✔
216
            } catch(Botan::Invalid_Argument&) {}
28✔
217

218
            const auto group_der_oid = group.DER_encode();
28✔
219
            const Botan::EC_Group group_via_oid(group_der_oid);
28✔
220
            result.test_is_true("EC_Group via OID is not considered explicit encoding",
28✔
221
                                !group_via_oid.used_explicit_encoding());
28✔
222

223
            const auto group_der_explicit = group.DER_encode(Botan::EC_Group_Encoding::Explicit);
28✔
224
            const Botan::EC_Group group_via_explicit(group_der_explicit);
28✔
225
            result.test_is_true("EC_Group via explicit DER is considered explicit encoding",
28✔
226
                                group_via_explicit.used_explicit_encoding());
28✔
227

228
            if(group.a_is_minus_3()) {
28✔
229
               result.test_bn_eq("Group A equals -3", group.get_a(), group.get_p() - 3);
17✔
230
            } else {
231
               result.test_bn_ne("Group " + group_name + " A does not equal -3", group.get_a(), group.get_p() - 3);
33✔
232
            }
233

234
            if(group.a_is_zero()) {
28✔
235
               result.test_bn_eq("Group A is zero", group.get_a(), BigInt(0));
4✔
236
            } else {
237
               result.test_bn_ne("Group " + group_name + " A does not equal zero", group.get_a(), BigInt(0));
72✔
238
            }
239

240
   #if defined(BOTAN_HAS_LEGACY_EC_POINT)
241
            const auto pt_mult_by_order = group.get_base_point() * group.get_order();
28✔
242
            result.test_is_true("Multiplying point by the order results in zero point", pt_mult_by_order.is_zero());
28✔
243

244
            // get a valid point
245
            Botan::EC_Point p = group.get_base_point() * this->rng().next_nonzero_byte();
28✔
246

247
            // get a copy
248
            Botan::EC_Point q = p;
28✔
249

250
            p.randomize_repr(this->rng());
28✔
251
            q.randomize_repr(this->rng());
28✔
252

253
            result.test_bn_eq("affine x after copy", p.get_affine_x(), q.get_affine_x());
28✔
254
            result.test_bn_eq("affine y after copy", p.get_affine_y(), q.get_affine_y());
28✔
255

256
            q.force_affine();
28✔
257

258
            result.test_bn_eq("affine x after copy", p.get_affine_x(), q.get_affine_x());
28✔
259
            result.test_bn_eq("affine y after copy", p.get_affine_y(), q.get_affine_y());
28✔
260

261
            test_ser_der(result, group);
28✔
262
            test_basic_math(result, group);
28✔
263
            test_point_swap(result, group);
28✔
264
            test_zeropoint(result, group);
28✔
265
   #endif
266

267
            result.end_timer();
28✔
268

269
            results.push_back(result);
28✔
270
         }
84✔
271

272
         return results;
1✔
273
      }
×
274

275
   private:
276
   #if defined(BOTAN_HAS_LEGACY_EC_POINT)
277

278
      void test_ser_der(Test::Result& result, const Botan::EC_Group& group) {
28✔
279
         // generate point
280
         const Botan::EC_Point pt = create_random_point(this->rng(), group);
28✔
281
         const Botan::EC_Point zero = group.zero_point();
28✔
282

283
         for(auto scheme : {Botan::EC_Point_Format::Uncompressed,
84✔
284
                            Botan::EC_Point_Format::Compressed,
285
                            Botan::EC_Point_Format::Hybrid}) {
112✔
286
            try {
84✔
287
               result.test_bin_eq("encoded/decode rt works", group.OS2ECP(pt.encode(scheme)).xy_bytes(), pt.xy_bytes());
336✔
288
            } catch(Botan::Exception& e) {
×
289
               result.test_failure("Failed to round trip encode a random point", e.what());
×
290
            }
×
291

292
            try {
84✔
293
               result.test_is_true("encoded/decode rt works", group.OS2ECP(zero.encode(scheme)).is_zero());
252✔
294
            } catch(Botan::Exception& e) {
×
295
               result.test_failure("Failed to round trip encode the identity element", e.what());
×
296
            }
×
297
         }
298
      }
28✔
299

300
      static void test_basic_math(Test::Result& result, const Botan::EC_Group& group) {
28✔
301
         const Botan::EC_Point& G = group.get_base_point();
28✔
302

303
         const auto G2 = G * 2;
56✔
304
         const auto G3 = G * 3;
56✔
305

306
         Botan::EC_Point p1 = G2;
28✔
307
         p1 += G;
28✔
308

309
         result.test_bin_eq("point addition", p1.xy_bytes(), G3.xy_bytes());
56✔
310

311
         p1 -= G2;
28✔
312

313
         result.test_bin_eq("point subtraction", p1.xy_bytes(), G.xy_bytes());
56✔
314

315
         // The scalar multiplication algorithm relies on this being true:
316
         try {
28✔
317
            const Botan::EC_Point zero_coords = group.point(0, 0);
56✔
318
            result.test_is_true("point (0,0) is not on the curve", !zero_coords.on_the_curve());
×
319
         } catch(Botan::Exception&) {
28✔
320
            result.test_success("point (0,0) is rejected");
28✔
321
         }
28✔
322
      }
28✔
323

324
      void test_point_swap(Test::Result& result, const Botan::EC_Group& group) {
28✔
325
         const Botan::EC_Point a(create_random_point(this->rng(), group));
28✔
326
         Botan::EC_Point b(create_random_point(this->rng(), group));
28✔
327
         b *= Botan::BigInt(this->rng(), 20);
28✔
328

329
         Botan::EC_Point c(a);
28✔
330
         Botan::EC_Point d(b);
28✔
331

332
         d.swap(c);
28✔
333
         result.test_bin_eq("swap correct", a.xy_bytes(), d.xy_bytes());
56✔
334
         result.test_bin_eq("swap correct", b.xy_bytes(), c.xy_bytes());
56✔
335
      }
28✔
336

337
      static void test_zeropoint(Test::Result& result, const Botan::EC_Group& group) {
28✔
338
         Botan::EC_Point zero = group.zero_point();
28✔
339

340
         result.test_throws("Zero point throws", "Cannot convert zero point to affine", [&]() { zero.get_affine_x(); });
56✔
341
         result.test_throws("Zero point throws", "Cannot convert zero point to affine", [&]() { zero.get_affine_y(); });
56✔
342

343
         const Botan::EC_Point p1 = group.get_base_point() * 2;
28✔
344

345
         result.test_is_true("point is on the curve", p1.on_the_curve());
28✔
346
         result.test_is_true("point is not zero", !p1.is_zero());
28✔
347

348
         Botan::EC_Point p2 = p1;
28✔
349
         p2 -= p1;
28✔
350

351
         result.test_is_true("p - q with q = p results in zero", p2.is_zero());
28✔
352

353
         const Botan::EC_Point minus_p1 = -p1;
28✔
354
         result.test_is_true("point is on the curve", minus_p1.on_the_curve());
28✔
355
         const Botan::EC_Point shouldBeZero = p1 + minus_p1;
28✔
356
         result.test_is_true("point is on the curve", shouldBeZero.on_the_curve());
28✔
357
         result.test_is_true("point is zero", shouldBeZero.is_zero());
28✔
358

359
         result.test_bn_eq("minus point x", minus_p1.get_affine_x(), p1.get_affine_x());
28✔
360
         result.test_bn_eq("minus point y", minus_p1.get_affine_y(), group.get_p() - p1.get_affine_y());
28✔
361

362
         result.test_is_true("zero point is zero", zero.is_zero());
28✔
363
         result.test_is_true("zero point is on the curve", zero.on_the_curve());
28✔
364
         result.test_bin_eq("addition of zero does nothing", p1.xy_bytes(), (p1 + zero).xy_bytes());
84✔
365
         result.test_bin_eq("addition of zero does nothing", p1.xy_bytes(), (zero + p1).xy_bytes());
84✔
366
         result.test_bin_eq("addition of zero does nothing", p1.xy_bytes(), (p1 - zero).xy_bytes());
84✔
367
         result.test_is_true("zero times anything is the zero point", (zero * 39193).is_zero());
56✔
368

369
         for(auto scheme : {Botan::EC_Point_Format::Uncompressed,
196✔
370
                            Botan::EC_Point_Format::Compressed,
371
                            Botan::EC_Point_Format::Hybrid}) {
112✔
372
            const std::vector<uint8_t> v = zero.encode(scheme);
84✔
373
            result.test_is_true("encoded/decode rt works", group.OS2ECP(v).is_zero());
168✔
374
         }
84✔
375
      }
28✔
376
   #endif
377
};
378

379
BOTAN_REGISTER_TEST("pubkey", "ec_group", EC_Group_Tests);
380

381
Test::Result test_decoding_with_seed() {
1✔
382
   Test::Result result("Decode EC_Group with seed");
1✔
383

384
   try {
1✔
385
      if(Botan::EC_Group::supports_named_group("secp384r1")) {
1✔
386
         const auto secp384r1 = Botan::EC_Group::from_name("secp384r1");
1✔
387
         const auto secp384r1_with_seed =
1✔
388
            Botan::EC_Group::from_PEM(Test::read_data_file("x509/ecc/secp384r1_seed.pem"));
2✔
389
         result.test_is_true("decoding worked", secp384r1_with_seed.initialized());
1✔
390
         result.test_bn_eq("P-384 prime", secp384r1_with_seed.get_p(), secp384r1.get_p());
1✔
391
      }
1✔
392
   } catch(Botan::Exception& e) {
×
393
      result.test_failure(e.what());
×
394
   }
×
395

396
   return result;
1✔
397
}
×
398

399
Test::Result test_mixed_points() {
1✔
400
   Test::Result result("Mixed Point Arithmetic");
1✔
401

402
   if(Botan::EC_Group::supports_named_group("secp256r1") && Botan::EC_Group::supports_named_group("secp384r1")) {
1✔
403
      const auto secp256r1 = Botan::EC_Group::from_name("secp256r1");
1✔
404
      const auto secp384r1 = Botan::EC_Group::from_name("secp384r1");
1✔
405

406
   #if defined(BOTAN_HAS_LEGACY_EC_POINT)
407
      const Botan::EC_Point& G256 = secp256r1.get_base_point();
1✔
408
      const Botan::EC_Point& G384 = secp384r1.get_base_point();
1✔
409

410
      result.test_throws("Mixing points from different groups", [&] { const Botan::EC_Point p = G256 + G384; });
2✔
411
   #endif
412

413
      const auto p1 = Botan::EC_AffinePoint::generator(secp256r1);
1✔
414
      const auto p2 = Botan::EC_AffinePoint::generator(secp384r1);
1✔
415
      result.test_throws("Mixing points from different groups", [&] { auto p3 = p1.add(p2); });
2✔
416
   }
1✔
417

418
   return result;
1✔
419
}
×
420

421
class ECC_Unit_Tests final : public Test {
1✔
422
   public:
423
      std::vector<Test::Result> run() override {
1✔
424
         std::vector<Test::Result> results;
1✔
425

426
         results.push_back(test_decoding_with_seed());
2✔
427
         results.push_back(test_mixed_points());
2✔
428

429
         return results;
1✔
430
      }
×
431
};
432

433
BOTAN_REGISTER_TEST("pubkey", "ecc_unit", ECC_Unit_Tests);
434

435
class EC_Group_Registration_Tests final : public Test {
1✔
436
   public:
437
      std::vector<Test::Result> run() override {
1✔
438
         std::vector<Test::Result> results;
1✔
439

440
         if(Botan::EC_Group::supports_application_specific_group()) {
1✔
441
            results.push_back(test_ecc_registration());
2✔
442
            results.push_back(test_ec_group_from_params());
2✔
443
            results.push_back(test_ec_group_bad_registration());
2✔
444
            results.push_back(test_ec_group_duplicate_orders());
2✔
445
            results.push_back(test_ec_group_registration_with_custom_oid());
2✔
446
            results.push_back(test_ec_group_unregistration());
2✔
447
         }
448

449
         return results;
1✔
450
      }
×
451

452
   private:
453
      Test::Result test_ecc_registration() {
1✔
454
         Test::Result result("ECC registration");
1✔
455

456
         // numsp256d1
457
         const Botan::BigInt p("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF43");
1✔
458
         const Botan::BigInt a("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF40");
1✔
459
         const Botan::BigInt b("0x25581");
1✔
460
         const Botan::BigInt order("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE43C8275EA265C6020AB20294751A825");
1✔
461

462
         const Botan::BigInt g_x("0x01");
1✔
463
         const Botan::BigInt g_y("0x696F1853C1E466D7FC82C96CCEEEDD6BD02C2F9375894EC10BF46306C2B56C77");
1✔
464

465
         const Botan::OID oid("1.3.6.1.4.1.25258.4.1");
1✔
466

467
         // Creating this object implicitly registers the curve for future use ...
468
         const Botan::EC_Group reg_group(oid, p, a, b, g_x, g_y, order);
1✔
469

470
         auto group = Botan::EC_Group::from_OID(oid);
1✔
471

472
         result.test_bn_eq("Group registration worked", group.get_p(), p);
1✔
473

474
         // TODO(Botan4) this could change to == Generic
475
         result.test_is_true("Group is not pcurve", group.engine() != Botan::EC_Group_Engine::Optimized);
1✔
476

477
         return result;
1✔
478
      }
1✔
479

480
      Test::Result test_ec_group_from_params() {
1✔
481
         Test::Result result("EC_Group from params");
1✔
482

483
         Botan::EC_Group::clear_registered_curve_data();
1✔
484

485
         // secp256r1
486
         const Botan::BigInt p("0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF");
1✔
487
         const Botan::BigInt a("0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC");
1✔
488
         const Botan::BigInt b("0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B");
1✔
489

490
         const Botan::BigInt g_x("0x6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296");
1✔
491
         const Botan::BigInt g_y("0x4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5");
1✔
492
         const Botan::BigInt order("0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
1✔
493

494
         const Botan::OID oid("1.2.840.10045.3.1.7");
1✔
495

496
         // This uses the deprecated constructor to verify we dedup even without an OID
497
         // This whole test can be removed once explicit curve support is removed
498
         const Botan::EC_Group reg_group(p, a, b, g_x, g_y, order, 1);
1✔
499
         result.test_is_true("Group has correct OID", reg_group.get_curve_oid() == oid);
1✔
500

501
         return result;
1✔
502
      }
1✔
503

504
      Test::Result test_ec_group_bad_registration() {
1✔
505
         Test::Result result("EC_Group registering non-match");
1✔
506

507
         Botan::EC_Group::clear_registered_curve_data();
1✔
508

509
         // secp256r1 params except with a bad B param
510
         const Botan::BigInt p("0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF");
1✔
511
         const Botan::BigInt a("0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC");
1✔
512
         const Botan::BigInt b("0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604C");
1✔
513

514
         const Botan::BigInt g_x("0x6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296");
1✔
515
         const Botan::BigInt g_y("0x4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5");
1✔
516
         const Botan::BigInt order("0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
1✔
517

518
         const Botan::OID oid("1.2.840.10045.3.1.7");
1✔
519

520
         try {
1✔
521
            const Botan::EC_Group reg_group(oid, p, a, b, g_x, g_y, order);
1✔
522
            result.test_failure("Should have failed");
×
523
         } catch(Botan::Invalid_Argument&) {
1✔
524
            result.test_success("Got expected exception");
1✔
525
         }
1✔
526

527
         return result;
2✔
528
      }
1✔
529

530
      Test::Result test_ec_group_duplicate_orders() {
1✔
531
         Test::Result result("EC_Group with duplicate group order");
1✔
532

533
         Botan::EC_Group::clear_registered_curve_data();
1✔
534

535
         // secp256r1
536
         const Botan::BigInt p("0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF");
1✔
537
         const Botan::BigInt a("0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC");
1✔
538
         const Botan::BigInt b("0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B");
1✔
539

540
         const Botan::BigInt g_x("0x6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296");
1✔
541
         const Botan::BigInt g_y("0x4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5");
1✔
542
         const Botan::BigInt order("0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
1✔
543

544
         const Botan::OID oid("1.3.6.1.4.1.25258.100.0");  // some other random OID
1✔
545

546
         const Botan::EC_Group reg_group(oid, p, a, b, g_x, g_y, order);
1✔
547
         result.test_success("Registration success");
1✔
548
         result.test_is_true("Group has correct OID", reg_group.get_curve_oid() == oid);
1✔
549

550
         // We can now get it by OID:
551
         const auto hc_group = Botan::EC_Group::from_OID(oid);
1✔
552
         result.test_is_true("Group has correct OID", hc_group.get_curve_oid() == oid);
1✔
553

554
         // Existing secp256r1 unmodified:
555
         const Botan::OID secp160r1("1.2.840.10045.3.1.7");
1✔
556
         const auto other_group = Botan::EC_Group::from_OID(secp160r1);
1✔
557
         result.test_is_true("Group has correct OID", other_group.get_curve_oid() == secp160r1);
1✔
558

559
         return result;
1✔
560
      }
1✔
561

562
      Test::Result test_ec_group_registration_with_custom_oid() {
1✔
563
         Test::Result result("EC_Group registration of standard group with custom OID");
1✔
564

565
         Botan::EC_Group::clear_registered_curve_data();
1✔
566

567
         const Botan::OID secp256r1_oid("1.2.840.10045.3.1.7");
1✔
568
         const auto secp256r1 = Botan::EC_Group::from_OID(secp256r1_oid);
1✔
569
         result.test_is_true("Group has correct OID", secp256r1.get_curve_oid() == secp256r1_oid);
1✔
570

571
         const Botan::OID custom_oid("1.3.6.1.4.1.25258.100.99");  // some other random OID
1✔
572

573
         Botan::OID::register_oid(custom_oid, "secp256r1");
1✔
574

575
         const Botan::EC_Group reg_group(custom_oid,
1✔
576
                                         secp256r1.get_p(),
577
                                         secp256r1.get_a(),
578
                                         secp256r1.get_b(),
579
                                         secp256r1.get_g_x(),
580
                                         secp256r1.get_g_y(),
581
                                         secp256r1.get_order());
1✔
582

583
         result.test_success("Registration success");
1✔
584
         result.test_is_true("Group has correct OID", reg_group.get_curve_oid() == custom_oid);
1✔
585

586
         // We can now get it by OID:
587
         result.test_is_true("Group has correct OID",
1✔
588
                             Botan::EC_Group::from_OID(custom_oid).get_curve_oid() == custom_oid);
1✔
589

590
         // In the current data model of EC_Group there is a 1:1 OID:group, so these
591
         // have distinct underlying data
592
         result.test_is_true("Groups have different inner data pointers", reg_group._data() != secp256r1._data());
1✔
593

594
   #if defined(BOTAN_HAS_PCURVES_SECP256R1)
595
         // However we should have gotten a pcurves out of the deal *and* it
596
         // should be the exact same shared_ptr as the official curve
597

598
         result.test_enum_eq("Group is pcurves based", reg_group.engine(), Botan::EC_Group_Engine::Optimized);
1✔
599

600
         try {
1✔
601
            const auto& pcurve = reg_group._data()->pcurve();
1✔
602
            result.test_is_true("Group with custom OID got the same pcurve pointer",
1✔
603
                                &pcurve == &secp256r1._data()->pcurve());
1✔
604
         } catch(...) {
×
605
            result.test_failure("Group with custom OID did not get a pcurve pointer");
×
606
         }
×
607
   #endif
608

609
         return result;
2✔
610
      }
1✔
611

612
      Test::Result test_ec_group_unregistration() {
1✔
613
         Test::Result result("EC_Group unregistration of group");
1✔
614

615
         Botan::EC_Group::clear_registered_curve_data();
1✔
616

617
         const Botan::OID secp256r1_oid("1.2.840.10045.3.1.7");
1✔
618
         const auto secp256r1 = Botan::EC_Group::from_OID(secp256r1_oid);
1✔
619
         const Botan::OID custom_oid("1.3.6.1.4.1.25258.100.99");
1✔
620
         Botan::OID::register_oid(custom_oid, "secp256r1");
1✔
621

622
         const Botan::EC_Group reg_group(custom_oid,
1✔
623
                                         secp256r1.get_p(),
624
                                         secp256r1.get_a(),
625
                                         secp256r1.get_b(),
626
                                         secp256r1.get_g_x(),
627
                                         secp256r1.get_g_y(),
628
                                         secp256r1.get_order());
1✔
629

630
         const Botan::EC_Group group_from_oid = Botan::EC_Group::from_OID(custom_oid);
1✔
631

632
         result.test_is_true("Internal group is unregistered", Botan::EC_Group::unregister(secp256r1_oid));
1✔
633
         result.test_is_false("Unregistering internal group again does nothing",
1✔
634
                              Botan::EC_Group::unregister(secp256r1_oid));
1✔
635
         result.test_is_true("User defined group is unregistered", Botan::EC_Group::unregister(custom_oid));
1✔
636
         result.test_is_false("Unregistering user defined group again does nothing",
1✔
637
                              Botan::EC_Group::unregister(custom_oid));
1✔
638

639
         try {
1✔
640
            Botan::EC_Group::from_OID(custom_oid);
1✔
641
            result.test_failure("Should have failed");
×
642
         } catch(Botan::Invalid_Argument&) {
1✔
643
            result.test_success("Got expected exception");
1✔
644
         }
1✔
645

646
         result.test_is_true("Group can still be accessed", reg_group.get_curve_oid() == custom_oid);
1✔
647
         result.test_is_true("Group has correct p parameter", reg_group.get_p() == secp256r1.get_p());
1✔
648
         result.test_is_true("Group has correct a parameter", reg_group.get_a() == secp256r1.get_a());
1✔
649
         result.test_is_true("Group has correct b parameter", reg_group.get_b() == secp256r1.get_b());
1✔
650
         result.test_is_true("Group has correct g_x parameter", reg_group.get_g_x() == secp256r1.get_g_x());
1✔
651
         result.test_is_true("Group has correct g_y parameter", reg_group.get_g_y() == secp256r1.get_g_y());
1✔
652
         result.test_is_true("Group has correct order parameter", reg_group.get_order() == secp256r1.get_order());
1✔
653

654
   #if defined(BOTAN_HAS_ECDSA)
655
         std::unique_ptr<Botan::RandomNumberGenerator> rng = Test::new_rng("test_ec_group_unregistration");
1✔
656
         std::unique_ptr<Botan::Private_Key> key = Botan::create_ec_private_key("ECDSA", group_from_oid, *rng);
1✔
657
         result.test_success("Can still use group to create a key");
1✔
658
         result.test_is_true("Key was created correctly", key->check_key(*rng, true));
1✔
659
   #endif
660

661
         // TODO(Botan4) remove this when OIDs lose internal nullability
662
         try {
1✔
663
            const Botan::OID empty_oid("");
1✔
664
            Botan::EC_Group::unregister(empty_oid);
1✔
665
            result.test_failure("Should have failed");
×
666
         } catch(Botan::Invalid_Argument&) {
1✔
667
            result.test_success("Got expected exception");
1✔
668
         }
1✔
669

670
         return result;
1✔
671
      }
2✔
672
};
673

674
BOTAN_REGISTER_SERIALIZED_TEST("pubkey", "ec_group_registration", EC_Group_Registration_Tests);
675

676
class EC_PointEnc_Tests final : public Test {
1✔
677
   public:
678
      std::vector<Test::Result> run() override {
1✔
679
         std::vector<Test::Result> results;
1✔
680

681
         auto& rng = Test::rng();
1✔
682

683
         for(const auto& group_id : Botan::EC_Group::known_named_groups()) {
29✔
684
            const auto group = Botan::EC_Group::from_name(group_id);
28✔
685

686
            Result result("EC_AffinePoint encoding " + group_id);
28✔
687

688
            result.start_timer();
28✔
689

690
            for(size_t trial = 0; trial != 100; ++trial) {
2,828✔
691
               const auto scalar = Botan::EC_Scalar::random(group, rng);
2,800✔
692
               const auto pt = Botan::EC_AffinePoint::g_mul(scalar, rng);
2,800✔
693

694
               const auto pt_u = pt.serialize_uncompressed();
2,800✔
695
               result.test_u8_eq("Expected uncompressed header", pt_u[0], 0x04);
2,800✔
696
               const size_t fe_bytes = (pt_u.size() - 1) / 2;
2,800✔
697
               const auto pt_c = pt.serialize_compressed();
2,800✔
698

699
               result.test_sz_eq("Expected compressed size", pt_c.size(), 1 + fe_bytes);
2,800✔
700
               const uint8_t expected_c_header = (pt_u[pt_u.size() - 1] % 2 == 0) ? 0x02 : 0x03;
2,800✔
701
               result.test_u8_eq("Expected compressed header", pt_c[0], expected_c_header);
2,800✔
702

703
               result.test_bin_eq(
2,800✔
704
                  "Expected compressed x", std::span{pt_c}.subspan(1), std::span{pt_u}.subspan(1, fe_bytes));
705

706
               if(auto d_pt_u = Botan::EC_AffinePoint::deserialize(group, pt_u)) {
2,800✔
707
                  result.test_bin_eq(
2,800✔
708
                     "Deserializing uncompressed returned correct point", d_pt_u->serialize_uncompressed(), pt_u);
5,600✔
709
               } else {
710
                  result.test_failure("Failed to deserialize uncompressed point");
×
711
               }
×
712

713
               if(auto d_pt_c = Botan::EC_AffinePoint::deserialize(group, pt_c)) {
2,800✔
714
                  result.test_bin_eq(
2,800✔
715
                     "Deserializing compressed returned correct point", d_pt_c->serialize_uncompressed(), pt_u);
5,600✔
716
               } else {
717
                  result.test_failure("Failed to deserialize compressed point");
×
718
               }
×
719

720
               const auto neg_pt_c = [&]() {
2,800✔
721
                  auto x = pt_c;
2,800✔
722
                  x[0] ^= 0x01;
2,800✔
723
                  return x;
2,800✔
724
               }();
2,800✔
725

726
               if(auto d_neg_pt_c = Botan::EC_AffinePoint::deserialize(group, neg_pt_c)) {
2,800✔
727
                  result.test_bin_eq("Deserializing compressed with inverted header returned negated point",
2,800✔
728
                                     d_neg_pt_c->serialize_uncompressed(),
5,600✔
729
                                     pt.negate().serialize_uncompressed());
5,600✔
730
               } else {
731
                  result.test_failure("Failed to deserialize compressed point");
×
732
               }
2,800✔
733
            }
2,800✔
734

735
            result.end_timer();
28✔
736

737
            results.push_back(result);
28✔
738
         }
28✔
739

740
         return results;
1✔
741
      }
2,800✔
742
};
743

744
BOTAN_REGISTER_TEST("pubkey", "ec_point_enc", EC_PointEnc_Tests);
745

746
class EC_Point_Arithmetic_Tests final : public Test {
1✔
747
   public:
748
      std::vector<Test::Result> run() override {
1✔
749
         std::vector<Test::Result> results;
1✔
750

751
         auto& rng = Test::rng();
1✔
752

753
         for(const auto& group_id : Botan::EC_Group::known_named_groups()) {
29✔
754
            const auto group = Botan::EC_Group::from_name(group_id);
28✔
755

756
            Result result("EC_AffinePoint arithmetic " + group_id);
28✔
757

758
            result.start_timer();
28✔
759

760
            const auto one = Botan::EC_Scalar::one(group);
28✔
761
            const auto zero = one - one;  // NOLINT(*-redundant-expression)
28✔
762
            const auto g = Botan::EC_AffinePoint::generator(group);
28✔
763
            const auto g_bytes = g.serialize_uncompressed();
28✔
764

765
            const auto id = Botan::EC_AffinePoint::g_mul(zero, rng);
28✔
766
            result.test_is_true("g*zero is point at identity", id.is_identity());
28✔
767

768
            const auto id2 = id.add(id);
28✔
769
            result.test_is_true("identity plus itself is identity", id2.is_identity());
28✔
770

771
            const auto g_one = Botan::EC_AffinePoint::g_mul(one, rng);
28✔
772
            result.test_bin_eq("g*one == generator", g_one.serialize_uncompressed(), g_bytes);
28✔
773

774
            const auto g_plus_id = g_one.add(id);
28✔
775
            result.test_bin_eq("g + id == g", g_plus_id.serialize_uncompressed(), g_bytes);
28✔
776

777
            const auto id_plus_g = id.add(g_one);
28✔
778
            result.test_bin_eq("id + g == g", id_plus_g.serialize_uncompressed(), g_bytes);
28✔
779

780
            const auto g_neg_one = Botan::EC_AffinePoint::g_mul(one.negate(), rng);
28✔
781

782
            const auto id_from_g = g_one.add(g_neg_one);
28✔
783
            result.test_is_true("g - g is identity", id_from_g.is_identity());
28✔
784

785
            const auto g_two = Botan::EC_AffinePoint::g_mul(one + one, rng);
28✔
786
            const auto g_plus_g = g_one.add(g_one);
28✔
787
            result.test_bin_eq("2*g == g+g", g_two.serialize_uncompressed(), g_plus_g.serialize_uncompressed());
56✔
788

789
            result.test_is_true("Scalar::zero is zero", zero.is_zero());
28✔
790
            result.test_is_true("(zero+zero) is zero", (zero + zero).is_zero());
28✔
791
            result.test_is_true("(zero*zero) is zero", (zero * zero).is_zero());
28✔
792
            result.test_is_true("(zero-zero) is zero", (zero - zero).is_zero());  // NOLINT(*-redundant-expression)
28✔
793

794
            const auto neg_zero = zero.negate();
28✔
795
            result.test_is_true("zero.negate() is zero", neg_zero.is_zero());
28✔
796

797
            result.test_is_true("(zero+nz) is zero", (zero + neg_zero).is_zero());
28✔
798
            result.test_is_true("(nz+nz) is zero", (neg_zero + neg_zero).is_zero());
28✔
799
            result.test_is_true("(nz+zero) is zero", (neg_zero + zero).is_zero());
28✔
800

801
            result.test_is_true("Scalar::one is not zero", !one.is_zero());
28✔
802
            result.test_is_true("(one-one) is zero", (one - one).is_zero());  // NOLINT(*-redundant-expression)
28✔
803
            result.test_is_true("(one+one.negate()) is zero", (one + one.negate()).is_zero());
56✔
804
            result.test_is_true("(one.negate()+one) is zero", (one.negate() + one).is_zero());
56✔
805

806
            for(size_t i = 0; i != 16; ++i) {
476✔
807
               const auto pt = Botan::EC_AffinePoint::g_mul(Botan::EC_Scalar::random(group, rng), rng);
448✔
808

809
               const auto a = Botan::EC_Scalar::random(group, rng);
448✔
810
               const auto b = Botan::EC_Scalar::random(group, rng);
448✔
811
               const auto c = a + b;
448✔
812

813
               const auto Pa = pt.mul(a, rng);
448✔
814
               const auto Pb = pt.mul(b, rng);
448✔
815
               const auto Pc = pt.mul(c, rng);
448✔
816

817
               const auto Pc_bytes = Pc.serialize_uncompressed();
448✔
818

819
               const auto Pab = Pa.add(Pb);
448✔
820
               result.test_bin_eq("Pa + Pb == Pc", Pab.serialize_uncompressed(), Pc_bytes);
448✔
821

822
               const auto Pba = Pb.add(Pa);
448✔
823
               result.test_bin_eq("Pb + Pa == Pc", Pba.serialize_uncompressed(), Pc_bytes);
448✔
824
            }
896✔
825

826
            for(size_t i = 0; i != 64; ++i) {
1,820✔
827
               auto h = [&]() {
5,376✔
828
                  const auto s = [&]() {
5,376✔
829
                     if(i == 0) {
1,792✔
830
                        // Test the identity case
831
                        return Botan::EC_Scalar(zero);
28✔
832
                     } else if(i <= 32) {
1,764✔
833
                        // Test cases where the two points have a linear relation
834
                        std::vector<uint8_t> sbytes(group.get_order_bytes());
896✔
835
                        sbytes[sbytes.size() - 1] = static_cast<uint8_t>((i + 1) / 2);
896✔
836
                        auto si = Botan::EC_Scalar::deserialize(group, sbytes).value();
1,792✔
837
                        if(i % 2 == 0) {
896✔
838
                           return si;
448✔
839
                        } else {
840
                           return si.negate();
448✔
841
                        }
842
                     } else {
1,792✔
843
                        return Botan::EC_Scalar::random(group, rng);
868✔
844
                     }
845
                  }();
1,792✔
846
                  auto x = Botan::EC_AffinePoint::g_mul(s, rng);
1,792✔
847
                  return x;
1,792✔
848
               }();
3,584✔
849

850
               const auto s1 = Botan::EC_Scalar::random(group, rng);
1,792✔
851
               const auto s2 = Botan::EC_Scalar::random(group, rng);
1,792✔
852

853
               const Botan::EC_Group::Mul2Table mul2_table(h);
1,792✔
854

855
               const auto ref = Botan::EC_AffinePoint::g_mul(s1, rng).add(h.mul(s2, rng));
1,792✔
856

857
               if(auto mul2pt = mul2_table.mul2_vartime(s1, s2)) {
1,792✔
858
                  result.test_bin_eq("ref == mul2t", ref.serialize_uncompressed(), mul2pt->serialize_uncompressed());
5,376✔
859
               } else {
860
                  result.test_is_true("ref is identity", ref.is_identity());
×
861
               }
×
862
            }
1,792✔
863

864
            result.end_timer();
28✔
865

866
            results.push_back(result);
28✔
867
         }
56✔
868

869
         return results;
1✔
870
      }
×
871
};
872

873
BOTAN_REGISTER_TEST("pubkey", "ec_point_arith", EC_Point_Arithmetic_Tests);
874

875
   #if defined(BOTAN_HAS_ECDSA)
876

877
class ECC_Invalid_Key_Tests final : public Text_Based_Test {
×
878
   public:
879
      ECC_Invalid_Key_Tests() : Text_Based_Test("pubkey/ecc_invalid.vec", "SubjectPublicKey") {}
2✔
880

881
      bool clear_between_callbacks() const override { return false; }
5✔
882

883
      Test::Result run_one_test(const std::string& /*header*/, const VarMap& vars) override {
5✔
884
         Test::Result result("ECC invalid keys");
5✔
885

886
         const std::string encoded = vars.get_req_str("SubjectPublicKey");
5✔
887
         Botan::DataSource_Memory key_data(Botan::hex_decode(encoded));
10✔
888

889
         try {
5✔
890
            auto key = Botan::X509::load_key(key_data);
5✔
891
            result.test_is_false("public key fails check", key->check_key(this->rng(), false));
×
892
         } catch(Botan::Decoding_Error&) {
5✔
893
            result.test_success("Decoding invalid ECC key results in decoding error exception");
5✔
894
         }
5✔
895

896
         return result;
5✔
897
      }
5✔
898
};
899

900
BOTAN_REGISTER_TEST("pubkey", "ecc_invalid", ECC_Invalid_Key_Tests);
901

902
   #endif
903

904
class ECC_SEC1_Parsing_Tests final : public Text_Based_Test {
×
905
   public:
906
      ECC_SEC1_Parsing_Tests() :
1✔
907
            Text_Based_Test("pubkey/ecc_point_parsing.vec", "Input,FieldBytes,Result", "X,Y,YIsEven") {}
2✔
908

909
      Test::Result run_one_test(const std::string& /* header */, const VarMap& vars) override {
21✔
910
         Test::Result result("ECC SEC1 point parsing");
21✔
911

912
         const auto parsed = Botan::sec1_decode(
21✔
913
            vars.get_req_bin("Input"),
21✔
914
            vars.get_req_sz("FieldBytes"),
915
            Botan::overloaded{
916
               [&](Botan::SEC1_Identity) {
1✔
917
                  return result.test_str_eq("result type", "Identity", vars.get_req_str("Result"));
1✔
918
               },
919
               [&](Botan::SEC1_Compressed c) {
2✔
920
                  return result.test_is_true("X key exists", vars.has_key("X")) &&
4✔
921
                         result.test_is_true("YIsEven key exists", vars.has_key("YIsEven")) &&
4✔
922
                         result.test_str_eq("result type", "Compressed", vars.get_req_str("Result")) &&
6✔
923
                         result.test_bin_eq("x coordinate", c.x, vars.get_req_bin("X")) &&
8✔
924
                         result.test_bool_eq("y_is_even", c.y_is_even.as_bool(), vars.get_req_bool("YIsEven"));
6✔
925
               },
926
               [&](Botan::SEC1_Full f) {
4✔
927
                  return result.test_is_true("X key exists", vars.has_key("X")) &&
8✔
928
                         result.test_is_true("Y key exists", vars.has_key("Y")) &&
8✔
929
                         result.test_str_eq("result type", "Full", vars.get_req_str("Result")) &&
12✔
930
                         result.test_bin_eq("x coordinate", f.x, vars.get_req_bin("X")) &&
12✔
931
                         result.test_bin_eq("y coordinate", f.y, vars.get_req_bin("Y"));
12✔
932
               },
933
            });
934

935
         if(parsed.has_value()) {
21✔
936
            result.test_is_true("value checks have passed", *parsed);
7✔
937
         } else {
938
            result.test_str_eq("result type", "Error", vars.get_req_str("Result"));
14✔
939
         }
940

941
         return result;
21✔
942
      }
×
943
};
944

945
BOTAN_REGISTER_TEST("pubkey", "ecc_sec1_parsing", ECC_SEC1_Parsing_Tests);
946

947
#endif
948

949
}  // namespace
950

951
}  // 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

© 2026 Coveralls, Inc