Coverage Report

Created: 2020-06-30 13:58

/src/botan/build/include/botan/bcrypt_pbkdf.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* (C) 2018,2019 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6
7
#ifndef BOTAN_PBKDF_BCRYPT_H_
8
#define BOTAN_PBKDF_BCRYPT_H_
9
10
#include <botan/pwdhash.h>
11
12
BOTAN_FUTURE_INTERNAL_HEADER(bcrypt_pbkdf.h)
13
14
namespace Botan {
15
16
/**
17
* Bcrypt-PBKDF key derivation function
18
*/
19
class BOTAN_PUBLIC_API(2,11) Bcrypt_PBKDF final : public PasswordHash
20
   {
21
   public:
22
0
      Bcrypt_PBKDF(size_t iterations) : m_iterations(iterations) {}
23
24
      Bcrypt_PBKDF(const Bcrypt_PBKDF& other) = default;
25
      Bcrypt_PBKDF& operator=(const Bcrypt_PBKDF&) = default;
26
27
      /**
28
      * Derive a new key under the current Bcrypt-PBKDF parameter set
29
      */
30
      void derive_key(uint8_t out[], size_t out_len,
31
                      const char* password, size_t password_len,
32
                      const uint8_t salt[], size_t salt_len) const override;
33
34
      std::string to_string() const override;
35
36
0
      size_t iterations() const override { return m_iterations; }
37
38
0
      size_t parallelism() const override { return 0; }
39
40
0
      size_t memory_param() const override { return 0; }
41
42
0
      size_t total_memory_usage() const override { return 4096; }
43
44
   private:
45
      size_t m_iterations;
46
   };
47
48
class BOTAN_PUBLIC_API(2,11) Bcrypt_PBKDF_Family final : public PasswordHashFamily
49
   {
50
   public:
51
0
      Bcrypt_PBKDF_Family() {}
52
53
      std::string name() const override;
54
55
      std::unique_ptr<PasswordHash> tune(size_t output_length,
56
                                         std::chrono::milliseconds msec,
57
                                         size_t max_memory) const override;
58
59
      std::unique_ptr<PasswordHash> default_params() const override;
60
61
      std::unique_ptr<PasswordHash> from_iterations(size_t iter) const override;
62
63
      std::unique_ptr<PasswordHash> from_params(
64
         size_t i, size_t, size_t) const override;
65
   };
66
67
/**
68
* Bcrypt PBKDF compatible with OpenBSD bcrypt_pbkdf
69
*/
70
void BOTAN_UNSTABLE_API bcrypt_pbkdf(uint8_t output[], size_t output_len,
71
                                     const char* pass, size_t pass_len,
72
                                     const uint8_t salt[], size_t salt_len,
73
                                     size_t rounds);
74
75
}
76
77
#endif