@@ -278,6 +278,63 @@
Loading
278 278
   return result;
279 279
   }
280 280
281 +
std::vector<Test::Result>
282 +
PK_Sign_Verify_DER_Test::run()
283 +
   {
284 +
   const std::vector<uint8_t> message = {'f', 'o', 'o', 'b', 'a', 'r'};
285 +
   const std::string padding = m_padding;
286 +
287 +
   std::unique_ptr<Botan::Private_Key> privkey = key();
288 +
289 +
   Test::Result result(algo_name() + "/" + padding + " signature sign/verify using DER format");
290 +
291 +
   for(auto const& provider : possible_providers(algo_name()))
292 +
      {
293 +
      std::unique_ptr<Botan::PK_Signer> signer;
294 +
      std::unique_ptr<Botan::PK_Verifier> verifier;
295 +
296 +
      try
297 +
         {
298 +
         signer.reset(new Botan::PK_Signer(*privkey, Test::rng(), padding, Botan::DER_SEQUENCE, provider));
299 +
         verifier.reset(new Botan::PK_Verifier(*privkey, padding, Botan::DER_SEQUENCE, provider));
300 +
         }
301 +
      catch(Botan::Lookup_Error& e)
302 +
         {
303 +
         result.test_note("Skipping sign/verify with " + provider, e.what());
304 +
         }
305 +
306 +
      if(signer && verifier)
307 +
         {
308 +
         try
309 +
            {
310 +
            std::vector<uint8_t> generated_signature = signer->sign_message(message, Test::rng());
311 +
            const bool verified = verifier->verify_message(message, generated_signature);
312 +
313 +
            result.test_eq("correct signature valid with " + provider, verified, true);
314 +
315 +
            if(test_random_invalid_sigs())
316 +
               {
317 +
               check_invalid_signatures(result, *verifier, message, generated_signature);
318 +
               }
319 +
            }
320 +
         catch(std::exception& e)
321 +
            {
322 +
            result.test_failure("verification threw exception", e.what());
323 +
            }
324 +
         }
325 +
      }
326 +
327 +
   return {result};
328 +
   }
329 +
330 +
std::vector<std::string> PK_Sign_Verify_DER_Test::possible_providers(
331 +
   const std::string& algo)
332 +
   {
333 +
   std::vector<std::string> pk_provider =
334 +
      Botan::probe_provider_private_key(algo, { "base", "commoncrypto", "openssl", "tpm" });
335 +
   return Test::provider_filter(pk_provider);
336 +
   }
337 +
281 338
Test::Result
282 339
PK_Encryption_Decryption_Test::run_one_test(const std::string& pad_hdr, const VarMap& vars)
283 340
   {

@@ -12,6 +12,7 @@
Loading
12 12
#if defined(BOTAN_HAS_ECDSA)
13 13
   #include "test_pubkey.h"
14 14
   #include <botan/ecdsa.h>
15 +
   #include <botan/pk_algs.h>
15 16
#endif
16 17
17 18
namespace Botan_Tests {
@@ -138,6 +139,18 @@
Loading
138 139
#endif
139 140
   };
140 141
142 +
class ECDSA_Sign_Verify_DER_Test final : public PK_Sign_Verify_DER_Test
143 +
   {
144 +
   public:
145 +
      ECDSA_Sign_Verify_DER_Test() :
146 +
         PK_Sign_Verify_DER_Test("ECDSA", "EMSA1(SHA-512)") {}
147 +
148 +
      std::unique_ptr<Botan::Private_Key> key() const override
149 +
         {
150 +
         return Botan::create_private_key( "ECDSA",  Test::rng(), "secp256r1" );
151 +
         }
152 +
   };
153 +
141 154
class ECDSA_Keygen_Tests final : public PK_Key_Generation_Test
142 155
   {
143 156
   public:
@@ -245,6 +258,7 @@
Loading
245 258
BOTAN_REGISTER_TEST("ecdsa_verify", ECDSA_Verification_Tests);
246 259
BOTAN_REGISTER_TEST("ecdsa_verify_wycheproof", ECDSA_Wycheproof_Verification_Tests);
247 260
BOTAN_REGISTER_TEST("ecdsa_sign", ECDSA_Signature_KAT_Tests);
261 +
BOTAN_REGISTER_TEST("ecdsa_sign_verify_der", ECDSA_Sign_Verify_DER_Test);
248 262
BOTAN_REGISTER_TEST("ecdsa_keygen", ECDSA_Keygen_Tests);
249 263
BOTAN_REGISTER_TEST("ecdsa_invalid", ECDSA_Invalid_Key_Tests);
250 264

@@ -223,6 +223,12 @@
Loading
223 223
   return m_op->agree(key_len, in, in_len, salt, salt_len);
224 224
   }
225 225
226 +
static void check_der_format_supported(Signature_Format format, size_t parts)
227 +
   {
228 +
      if(format != IEEE_1363 && parts == 1)
229 +
         throw Invalid_Argument("PK: This algorithm does not support DER encoding");
230 +
   }
231 +
226 232
PK_Signer::PK_Signer(const Private_Key& key,
227 233
                     RandomNumberGenerator& rng,
228 234
                     const std::string& emsa,
@@ -235,6 +241,7 @@
Loading
235 241
   m_sig_format = format;
236 242
   m_parts = key.message_parts();
237 243
   m_part_size = key.message_part_size();
244 +
   check_der_format_supported(format, m_parts);
238 245
   }
239 246
240 247
PK_Signer::~PK_Signer() { /* for unique_ptr */ }
@@ -310,14 +317,14 @@
Loading
310 317
   m_sig_format = format;
311 318
   m_parts = key.message_parts();
312 319
   m_part_size = key.message_part_size();
320 +
   check_der_format_supported(format, m_parts);
313 321
   }
314 322
315 323
PK_Verifier::~PK_Verifier() { /* for unique_ptr */ }
316 324
317 325
void PK_Verifier::set_input_format(Signature_Format format)
318 326
   {
319 -
   if(format != IEEE_1363 && m_parts == 1)
320 -
      throw Invalid_Argument("PK_Verifier: This algorithm does not support DER encoding");
327 +
   check_der_format_supported(format, m_parts);
321 328
   m_sig_format = format;
322 329
   }
323 330

@@ -104,6 +104,32 @@
Loading
104 104
      Test::Result run_one_test(const std::string& header, const VarMap& vars) override final;
105 105
   };
106 106
107 +
class PK_Sign_Verify_DER_Test : public Test
108 +
   {
109 +
   public:
110 +
      PK_Sign_Verify_DER_Test(const std::string& algo,
111 +
                              const std::string& padding)
112 +
         : m_algo(algo), m_padding(padding) {}
113 +
114 +
      std::string algo_name() const
115 +
         {
116 +
         return m_algo;
117 +
         }
118 +
119 +
   protected:
120 +
      std::vector<Test::Result> run() override final;
121 +
122 +
      virtual std::unique_ptr<Botan::Private_Key> key() const = 0;
123 +
124 +
      virtual bool test_random_invalid_sigs() const { return true; }
125 +
126 +
      std::vector<std::string> possible_providers(const std::string& params) override;
127 +
128 +
   private:
129 +
      std::string m_algo;
130 +
      std::string m_padding;
131 +
   };
132 +
107 133
class PK_Encryption_Decryption_Test : public PK_Test
108 134
   {
109 135
   public:
Files Coverage
src 92.61%
Project Totals (557 files) 92.61%
6451.3
TRAVIS_OS_NAME=linux
1
---
2

3
# Documentation
4
# https://github.com/codecov/support/wiki/Codecov-Yaml#full-yaml
5
#
6
# Validate this file
7
# curl --data-binary @codecov.yml https://codecov.io/validate
8

9
coverage:
10
  status:
11
    project:
12
      default:
13
        # Random seeds in tests lead to a +/-0.05% coverage span even for PRs
14
        # that do not change source code
15
        threshold: 0.05
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading