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

randombit / botan / 13486108206

23 Feb 2025 07:15PM UTC coverage: 91.693% (-0.001%) from 91.694%
13486108206

Pull #4712

github

web-flow
Merge 2a5de9490 into 3db6e2f01
Pull Request #4712: Add EC_Group::hash_to_curve_supported

95826 of 104508 relevant lines covered (91.69%)

11320922.03 hits per line

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

90.0
/src/tests/test_ecc_h2c.cpp
1
/*
2
* (C) 2019,2020 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_EC_HASH_TO_CURVE)
10
   #include <botan/ec_group.h>
11
#endif
12

13
#if defined(BOTAN_HAS_XMD)
14
   #include <botan/internal/xmd.h>
15
#endif
16

17
namespace Botan_Tests {
18

19
namespace {
20

21
#if defined(BOTAN_HAS_XMD)
22

23
class ECC_H2C_XMD_Tests final : public Text_Based_Test {
×
24
   public:
25
      ECC_H2C_XMD_Tests() : Text_Based_Test("pubkey/ec_h2c_xmd.vec", "Domain,Input,Output") {}
2✔
26

27
      bool clear_between_callbacks() const override { return false; }
20✔
28

29
      Test::Result run_one_test(const std::string& hash, const VarMap& vars) override {
20✔
30
         Test::Result result("ECC hash to curve XMD " + hash);
20✔
31

32
         const std::string domain = vars.get_req_str("Domain");
20✔
33
         const std::string input = vars.get_req_str("Input");
20✔
34
         const std::vector<uint8_t> expected = vars.get_req_bin("Output");
20✔
35

36
         std::vector<uint8_t> output(expected.size());
20✔
37
         Botan::expand_message_xmd(hash, output, input, domain);
20✔
38

39
         result.test_eq("XMD output", output, expected);
40✔
40
         return result;
20✔
41
      }
40✔
42
};
43

44
BOTAN_REGISTER_TEST("ec_h2c", "ec_h2c_xmd", ECC_H2C_XMD_Tests);
45

46
#endif
47

48
#if defined(BOTAN_HAS_EC_HASH_TO_CURVE)
49

50
class ECC_H2C_Tests final : public Text_Based_Test {
×
51
   public:
52
      ECC_H2C_Tests() : Text_Based_Test("pubkey/ec_h2c.vec", "Group,Hash,Domain,Input,Point") {}
2✔
53

54
      bool clear_between_callbacks() const override { return false; }
43✔
55

56
      bool skip_this_test(const std::string&, const VarMap& vars) override {
43✔
57
         return !Botan::EC_Group::supports_named_group(vars.get_req_str("Group"));
43✔
58
      }
59

60
      Test::Result run_one_test(const std::string& method, const VarMap& vars) override {
43✔
61
         const std::string group_id = vars.get_req_str("Group");
43✔
62

63
         Test::Result result("ECC hash to curve " + method + " " + group_id);
129✔
64

65
         const std::string hash_fn = vars.get_req_str("Hash");
43✔
66
         const std::string domain_str = vars.get_req_str("Domain");
43✔
67
         const std::vector<uint8_t> input = vars.get_req_bin("Input");
43✔
68
         const std::vector<uint8_t> expected_point = vars.get_req_bin("Point");
43✔
69
         const bool random_oracle = method.find("-RO") != std::string::npos;
43✔
70

71
         auto domain = std::span{reinterpret_cast<const uint8_t*>(domain_str.data()), domain_str.size()};
43✔
72

73
         const auto group = Botan::EC_Group::from_name(group_id);
43✔
74

75
         result.test_eq("Group should support hash to curve", group.hash_to_curve_supported(), true);
43✔
76

77
         try {
43✔
78
            std::vector<uint8_t> pt;
43✔
79
            if(random_oracle) {
43✔
80
               pt = Botan::EC_AffinePoint::hash_to_curve_ro(group, hash_fn, input, domain).serialize_uncompressed();
40✔
81
            } else {
82
               pt = Botan::EC_AffinePoint::hash_to_curve_nu(group, hash_fn, input, domain).serialize_uncompressed();
46✔
83
            }
84

85
            result.test_eq("Generated point serialization", pt, expected_point);
86✔
86
         } catch(Botan::Not_Implemented&) {
43✔
87
            result.test_note("Skipping due to not implemented");
×
88
         }
×
89

90
         return result;
86✔
91
      }
129✔
92
};
93

94
BOTAN_REGISTER_TEST("ec_h2c", "ec_h2c_kat", ECC_H2C_Tests);
95

96
#endif
97

98
}  // namespace
99

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