Coverage Report

Created: 2020-02-14 15:38

/src/botan/build/include/botan/argon2.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_ARGON2_H_
8
#define BOTAN_ARGON2_H_
9
10
#include <botan/pwdhash.h>
11
12
namespace Botan {
13
14
class RandomNumberGenerator;
15
16
/**
17
* Argon2 key derivation function
18
*/
19
class BOTAN_PUBLIC_API(2,11) Argon2 final : public PasswordHash
20
   {
21
   public:
22
      Argon2(uint8_t family, size_t M, size_t t, size_t p);
23
24
      Argon2(const Argon2& other) = default;
25
      Argon2& operator=(const Argon2&) = default;
26
27
      /**
28
      * Derive a new key under the current Argon2 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 M() const { return m_M; }
37
0
      size_t t() const { return m_t; }
38
0
      size_t p() const { return m_p; }
39
40
0
      size_t iterations() const override { return t(); }
41
42
0
      size_t parallelism() const override { return p(); }
43
44
0
      size_t memory_param() const override { return M(); }
45
46
0
      size_t total_memory_usage() const override { return M() * 1024; }
47
48
   private:
49
      uint8_t m_family;
50
      size_t m_M, m_t, m_p;
51
   };
52
53
class BOTAN_PUBLIC_API(2,11) Argon2_Family final : public PasswordHashFamily
54
   {
55
   public:
56
      Argon2_Family(uint8_t family);
57
58
      std::string name() const override;
59
60
      std::unique_ptr<PasswordHash> tune(size_t output_length,
61
                                         std::chrono::milliseconds msec,
62
                                         size_t max_memory) const override;
63
64
      std::unique_ptr<PasswordHash> default_params() const override;
65
66
      std::unique_ptr<PasswordHash> from_iterations(size_t iter) const override;
67
68
      std::unique_ptr<PasswordHash> from_params(
69
         size_t M, size_t t, size_t p) const override;
70
   private:
71
      const uint8_t m_family;
72
   };
73
74
/**
75
* Argon2 key derivation function
76
*
77
* @param output the output will be placed here
78
* @param output_len length of output
79
* @param password the user password
80
* @param password_len the length of password
81
* @param salt the salt
82
* @param salt_len length of salt
83
* @param key an optional secret key
84
* @param key_len the length of key
85
* @param ad an optional additional input
86
* @param ad_len the length of ad
87
* @param y the Argon2 variant (0 = Argon2d, 1 = Argon2i, 2 = Argon2id)
88
* @param p the parallelization parameter
89
* @param M the amount of memory to use in Kb
90
* @param t the number of iterations to use
91
*/
92
void BOTAN_PUBLIC_API(2,11) argon2(uint8_t output[], size_t output_len,
93
                                   const char* password, size_t password_len,
94
                                   const uint8_t salt[], size_t salt_len,
95
                                   const uint8_t key[], size_t key_len,
96
                                   const uint8_t ad[], size_t ad_len,
97
                                   uint8_t y, size_t p, size_t M, size_t t);
98
99
std::string BOTAN_PUBLIC_API(2,11)
100
   argon2_generate_pwhash(const char* password, size_t password_len,
101
                          RandomNumberGenerator& rng,
102
                          size_t p, size_t M, size_t t,
103
                          uint8_t y = 2, size_t salt_len = 16, size_t output_len = 32);
104
105
/**
106
* Check a previously created password hash
107
* @param password the password to check against
108
* @param password_len the length of password
109
* @param hash the stored hash to check against
110
*/
111
bool BOTAN_PUBLIC_API(2,11) argon2_check_pwhash(const char* password, size_t password_len,
112
                                                const std::string& hash);
113
114
}
115
116
#endif