randombit / botan

@@ -30,6 +30,20 @@
Loading
30 30
          m_family, m_p, m_M, m_t);
31 31
   }
32 32
33 +
void Argon2::derive_key(uint8_t output[], size_t output_len,
34 +
                        const char* password, size_t password_len,
35 +
                        const uint8_t salt[], size_t salt_len,
36 +
                        const uint8_t ad[], size_t ad_len,
37 +
                        const uint8_t key[], size_t key_len) const
38 +
   {
39 +
   argon2(output, output_len,
40 +
          password, password_len,
41 +
          salt, salt_len,
42 +
          key, key_len,
43 +
          ad, ad_len,
44 +
          m_family, m_p, m_M, m_t);
45 +
   }
46 +
33 47
namespace {
34 48
35 49
std::string argon2_family_name(uint8_t f)

@@ -30,6 +30,22 @@
Loading
30 30
31 31
namespace Botan {
32 32
33 +
void PasswordHash::derive_key(uint8_t out[], size_t out_len,
34 +
                              const char* password, size_t password_len,
35 +
                              const uint8_t salt[], size_t salt_len,
36 +
                              const uint8_t ad[], size_t ad_len,
37 +
                              const uint8_t key[], size_t key_len) const
38 +
   {
39 +
   BOTAN_UNUSED(ad, key);
40 +
41 +
   if(ad_len == 0 && key_len == 0)
42 +
      return this->derive_key(out, out_len,
43 +
                              password, password_len,
44 +
                              salt, salt_len);
45 +
   else
46 +
      throw Not_Implemented("PasswordHash " + this->to_string() + " does not support AD or key");
47 +
   }
48 +
33 49
std::unique_ptr<PasswordHashFamily> PasswordHashFamily::create(const std::string& algo_spec,
34 50
                                     const std::string& provider)
35 51
   {

@@ -20,10 +20,6 @@
Loading
20 20
   #include <botan/scrypt.h>
21 21
#endif
22 22
23 -
#if defined(BOTAN_HAS_ARGON2)
24 -
   #include <botan/argon2.h>
25 -
#endif
26 -
27 23
#if defined(BOTAN_HAS_PBKDF_BCRYPT)
28 24
   #include <botan/bcrypt_pbkdf.h>
29 25
#endif
@@ -268,29 +264,8 @@
Loading
268 264
         const std::vector<uint8_t> passphrase = vars.get_req_bin("Passphrase");
269 265
         const std::vector<uint8_t> expected = vars.get_req_bin("Output");
270 266
271 -
         uint8_t family;
272 -
         if(mode == "Argon2d")
273 -
            family = 0;
274 -
         else if(mode == "Argon2i")
275 -
            family = 1;
276 -
         else if(mode == "Argon2id")
277 -
            family = 2;
278 -
         else
279 -
            throw Test_Error("Unknown Argon2 mode");
280 -
281 267
         Test::Result result(mode);
282 268
283 -
         std::vector<uint8_t> output(expected.size());
284 -
         Botan::argon2(output.data(), output.size(),
285 -
                       reinterpret_cast<const char*>(passphrase.data()),
286 -
                       passphrase.size(),
287 -
                       salt.data(), salt.size(),
288 -
                       key.data(), key.size(),
289 -
                       ad.data(), ad.size(),
290 -
                       family, P, M, T);
291 -
292 -
         result.test_eq("derived key", output, expected);
293 -
294 269
         auto pwdhash_fam = Botan::PasswordHashFamily::create(mode);
295 270
296 271
         if(!pwdhash_fam)
@@ -299,18 +274,17 @@
Loading
299 274
            return result;
300 275
            }
301 276
302 -
         if(ad.size() == 0)
303 -
            {
304 -
            auto pwdhash = pwdhash_fam->from_params(M, T, P);
277 +
         auto pwdhash = pwdhash_fam->from_params(M, T, P);
305 278
306 -
            std::vector<uint8_t> pwdhash_derived(expected.size());
307 -
            pwdhash->derive_key(pwdhash_derived.data(), pwdhash_derived.size(),
308 -
                                reinterpret_cast<const char*>(passphrase.data()),
309 -
                                passphrase.size(),
310 -
                                salt.data(), salt.size());
279 +
         std::vector<uint8_t> pwdhash_derived(expected.size());
280 +
         pwdhash->derive_key(pwdhash_derived.data(), pwdhash_derived.size(),
281 +
                             reinterpret_cast<const char*>(passphrase.data()),
282 +
                             passphrase.size(),
283 +
                             salt.data(), salt.size(),
284 +
                             ad.data(), ad.size(),
285 +
                             key.data(), key.size());
311 286
312 -
            result.test_eq("pwdhash derived key", pwdhash_derived, expected);
313 -
            }
287 +
         result.test_eq("pwdhash derived key", pwdhash_derived, expected);
314 288
315 289
         return result;
316 290
         }
Files Coverage
src 92.37%
Project Totals (565 files) 92.37%
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