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

randombit / botan / 19012754211

02 Nov 2025 01:10PM UTC coverage: 90.677% (+0.006%) from 90.671%
19012754211

push

github

web-flow
Merge pull request #5137 from randombit/jack/clang-tidy-includes

Remove various unused includes flagged by clang-tidy misc-include-cleaner

100457 of 110786 relevant lines covered (90.68%)

12189873.8 hits per line

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

78.26
/src/tests/unit_ecdsa.cpp
1
/*
2
* ECDSA Tests
3
*
4
* (C) 2007 Falko Strenzke
5
*     2007 Manuel Hartl
6
*     2008,2015 Jack Lloyd
7
*
8
* Botan is released under the Simplified BSD License (see license.txt)
9
*/
10

11
#include "tests.h"
12

13
#if defined(BOTAN_HAS_ECDSA)
14
   #include <botan/data_src.h>
15
   #include <botan/ec_group.h>
16
   #include <botan/ecdsa.h>
17
   #include <botan/hash.h>
18
   #include <botan/pkcs8.h>
19
#endif
20

21
#if defined(BOTAN_HAS_X509_CERTIFICATES)
22
   #include <botan/x509cert.h>
23
#endif
24

25
namespace Botan_Tests {
26

27
namespace {
28

29
#if defined(BOTAN_HAS_ECDSA)
30

31
   #if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
32
Test::Result test_decode_ecdsa_X509() {
1✔
33
   Test::Result result("Parse CSCA cert");
1✔
34

35
   if(Botan::EC_Group::supports_application_specific_group()) {
1✔
36
      try {
1✔
37
         Botan::X509_Certificate cert(Test::data_file("x509/ecc/CSCA.CSCA.csca-germany.1.crt"));
2✔
38

39
         result.test_eq(
3✔
40
            "correct signature oid", cert.signature_algorithm().oid().to_formatted_string(), "ECDSA/SHA-224");
2✔
41

42
         result.test_eq("serial number", cert.serial_number(), std::vector<uint8_t>{1});
2✔
43
         result.test_eq("authority key id", cert.authority_key_id(), cert.subject_key_id());
2✔
44
         result.test_eq(
3✔
45
            "key fingerprint",
46
            cert.fingerprint("SHA-256"),
2✔
47
            "3B:6C:99:1C:D6:5A:51:FC:EB:17:E3:AA:F6:3C:1A:DA:14:1F:82:41:30:6F:64:EE:FF:63:F3:1F:D6:07:14:9F");
48

49
         auto pubkey = cert.subject_public_key();
1✔
50
         result.test_eq("verify self-signed signature", cert.check_signature(*pubkey), true);
2✔
51
      } catch(Botan::Exception& e) {
1✔
52
         result.test_failure(e.what());
×
53
      }
×
54
   }
55

56
   return result;
1✔
57
}
×
58

59
Test::Result test_decode_ver_link_SHA256() {
1✔
60
   Test::Result result("Check ECDSA signature");
1✔
61

62
   if(Botan::EC_Group::supports_application_specific_group()) {
1✔
63
      try {
1✔
64
         Botan::X509_Certificate root_cert(Test::data_file("x509/ecc/root2_SHA256.cer"));
2✔
65
         Botan::X509_Certificate link_cert(Test::data_file("x509/ecc/link_SHA256.cer"));
2✔
66

67
         auto pubkey = root_cert.subject_public_key();
1✔
68
         result.confirm("verified self-signed signature", link_cert.check_signature(*pubkey));
2✔
69
      } catch(Botan::Exception& e) {
1✔
70
         result.test_failure(e.what());
×
71
      }
×
72
   }
73

74
   return result;
1✔
75
}
×
76

77
Test::Result test_decode_ver_link_SHA1() {
1✔
78
   Test::Result result("Check ECDSA signature SHA-1");
1✔
79

80
   if(Botan::EC_Group::supports_application_specific_group()) {
1✔
81
      try {
1✔
82
         Botan::X509_Certificate root_cert(Test::data_file("x509/ecc/root_SHA1.163.crt"));
2✔
83
         Botan::X509_Certificate link_cert(Test::data_file("x509/ecc/link_SHA1.166.crt"));
2✔
84

85
         auto pubkey = root_cert.subject_public_key();
1✔
86

87
         auto sha1 = Botan::HashFunction::create("SHA-1");
1✔
88

89
         if(!sha1) {
1✔
90
            result.confirm("verification of self-signed signature failed due to missing SHA-1",
×
91
                           !link_cert.check_signature(*pubkey));
×
92
            return result;
×
93
         }
94
         result.confirm("verified self-signed signature", link_cert.check_signature(*pubkey));
2✔
95
      } catch(Botan::Exception& e) {
2✔
96
         result.test_failure(e.what());
×
97
      }
×
98
   }
99

100
   return result;
101
}
×
102
   #endif
103

104
Test::Result test_encoding_options() {
1✔
105
   Test::Result result("ECDSA encoding");
1✔
106

107
   try {
1✔
108
      auto rng = Test::new_rng("ecdsa_encoding_options");
1✔
109

110
      for(const auto& group_id : Botan::EC_Group::known_named_groups()) {
29✔
111
         const auto group = Botan::EC_Group::from_name(group_id);
28✔
112
         Botan::ECDSA_PrivateKey key(*rng, group);
28✔
113

114
         result.confirm("Default encoding is uncompressed",
56✔
115
                        key.point_encoding() == Botan::EC_Point_Format::Uncompressed);
28✔
116

117
         const std::vector<uint8_t> enc_uncompressed = key.public_key_bits();
28✔
118
         key.set_point_encoding(Botan::EC_Point_Format::Compressed);
28✔
119

120
         result.confirm("set_point_encoding works", key.point_encoding() == Botan::EC_Point_Format::Compressed);
56✔
121

122
         const std::vector<uint8_t> enc_compressed = key.public_key_bits();
28✔
123
         result.test_lt("Compressed points are smaller", enc_compressed.size(), enc_uncompressed.size());
28✔
124
         size_t size_diff = enc_uncompressed.size() - enc_compressed.size();
28✔
125
         result.test_gte("Compressed points smaller by group size", size_diff, group.get_p_bytes());
28✔
126
         key.set_point_encoding(Botan::EC_Point_Format::Hybrid);
28✔
127
         result.confirm("set_point_encoding works", key.point_encoding() == Botan::EC_Point_Format::Hybrid);
56✔
128
         const std::vector<uint8_t> enc_hybrid = key.public_key_bits();
28✔
129
         result.test_eq("Hybrid point same size as uncompressed", enc_uncompressed.size(), enc_hybrid.size());
56✔
130
      }
84✔
131
   } catch(Botan::Exception& e) {
1✔
132
      result.test_failure(e.what());
×
133
   }
×
134

135
   return result;
1✔
136
}
×
137

138
   #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
139

140
Test::Result test_ecc_key_with_rfc5915_extensions() {
1✔
141
   Test::Result result("ECDSA Unit");
1✔
142

143
   try {
1✔
144
      if(Botan::EC_Group::supports_named_group("secp256r1")) {
1✔
145
         Botan::DataSource_Stream key_stream(Test::data_file("x509/ecc/ecc_private_with_rfc5915_ext.pem"));
2✔
146
         auto pkcs8 = Botan::PKCS8::load_key(key_stream);
1✔
147

148
         result.confirm("loaded RFC 5915 key", pkcs8 != nullptr);
2✔
149
         result.test_eq("key is ECDSA", pkcs8->algo_name(), "ECDSA");
2✔
150
         result.confirm("key type is ECDSA", dynamic_cast<Botan::ECDSA_PrivateKey*>(pkcs8.get()) != nullptr);
2✔
151
      }
1✔
152
   } catch(std::exception& e) {
×
153
      result.test_failure("load_rfc5915_ext", e.what());
×
154
   }
×
155

156
   return result;
1✔
157
}
×
158

159
Test::Result test_ecc_key_with_rfc5915_parameters() {
1✔
160
   Test::Result result("ECDSA Unit");
1✔
161

162
   try {
1✔
163
      if(Botan::EC_Group::supports_named_group("secp256r1")) {
1✔
164
         Botan::DataSource_Stream key_stream(Test::data_file("x509/ecc/ecc_private_with_rfc5915_parameters.pem"));
2✔
165
         auto pkcs8 = Botan::PKCS8::load_key(key_stream);
1✔
166

167
         result.confirm("loaded RFC 5915 key", pkcs8 != nullptr);
2✔
168
         result.test_eq("key is ECDSA", pkcs8->algo_name(), "ECDSA");
2✔
169
         result.confirm("key type is ECDSA", dynamic_cast<Botan::ECDSA_PrivateKey*>(pkcs8.get()) != nullptr);
2✔
170
      }
1✔
171
   } catch(std::exception& e) {
×
172
      result.test_failure("load_rfc5915_params", e.what());
×
173
   }
×
174

175
   return result;
1✔
176
}
×
177

178
   #endif
179

180
class ECDSA_Unit_Tests final : public Test {
×
181
   public:
182
      std::vector<Test::Result> run() override {
1✔
183
         std::vector<Test::Result> results;
1✔
184

185
   #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
186
         results.push_back(test_ecc_key_with_rfc5915_extensions());
2✔
187
         results.push_back(test_ecc_key_with_rfc5915_parameters());
2✔
188

189
      #if defined(BOTAN_HAS_X509_CERTIFICATES)
190
         results.push_back(test_decode_ecdsa_X509());
2✔
191
         results.push_back(test_decode_ver_link_SHA256());
2✔
192
         results.push_back(test_decode_ver_link_SHA1());
2✔
193
      #endif
194

195
   #endif
196

197
         results.push_back(test_encoding_options());
2✔
198
         return results;
1✔
199
      }
×
200
};
201

202
BOTAN_REGISTER_TEST("pubkey", "ecdsa_unit", ECDSA_Unit_Tests);
203
#endif
204

205
}  // namespace
206

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