Botan  2.12.1
Crypto and TLS for C++11
argon2.h
Go to the documentation of this file.
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 
15 
16 class RandomNumberGenerator;
17 
18 /**
19 * Argon2 key derivation function
20 */
22  {
23  public:
24  Argon2(uint8_t family, size_t M, size_t t, size_t p);
25 
26  Argon2(const Argon2& other) = default;
27  Argon2& operator=(const Argon2&) = default;
28 
29  /**
30  * Derive a new key under the current Argon2 parameter set
31  */
32  void derive_key(uint8_t out[], size_t out_len,
33  const char* password, size_t password_len,
34  const uint8_t salt[], size_t salt_len) const override;
35 
36  std::string to_string() const override;
37 
38  size_t M() const { return m_M; }
39  size_t t() const { return m_t; }
40  size_t p() const { return m_p; }
41 
42  size_t iterations() const override { return t(); }
43 
44  size_t parallelism() const override { return p(); }
45 
46  size_t memory_param() const override { return M(); }
47 
48  size_t total_memory_usage() const override { return M() * 1024; }
49 
50  private:
51  uint8_t m_family;
52  size_t m_M, m_t, m_p;
53  };
54 
56  {
57  public:
58  Argon2_Family(uint8_t family);
59 
60  std::string name() const override;
61 
62  std::unique_ptr<PasswordHash> tune(size_t output_length,
63  std::chrono::milliseconds msec,
64  size_t max_memory) const override;
65 
66  std::unique_ptr<PasswordHash> default_params() const override;
67 
68  std::unique_ptr<PasswordHash> from_iterations(size_t iter) const override;
69 
70  std::unique_ptr<PasswordHash> from_params(
71  size_t M, size_t t, size_t p) const override;
72  private:
73  const uint8_t m_family;
74  };
75 
76 /**
77 * Argon2 key derivation function
78 *
79 * @param output the output will be placed here
80 * @param output_len length of output
81 * @param password the user password
82 * @param salt the salt
83 * @param salt_len length of salt
84 * @param y the Argon2 variant (0 = Argon2d, 1 = Argon2i, 2 = Argon2id)
85 * @param p the parallelization parameter
86 * @param M the amount of memory to use in Kb
87 * @param t the number of iterations to use
88 */
89 void BOTAN_PUBLIC_API(2,11) argon2(uint8_t output[], size_t output_len,
90  const char* password, size_t password_len,
91  const uint8_t salt[], size_t salt_len,
92  const uint8_t key[], size_t key_len,
93  const uint8_t ad[], size_t ad_len,
94  uint8_t y, size_t p, size_t M, size_t t);
95 
96 std::string BOTAN_PUBLIC_API(2,11)
97  argon2_generate_pwhash(const char* password, size_t password_len,
99  size_t p, size_t M, size_t t,
100  uint8_t y = 2, size_t salt_len = 16, size_t output_len = 32);
101 
102 /**
103 * Check a previously created password hash
104 * @param password the password to check against
105 * @param hash the stored hash to check against
106 */
107 bool BOTAN_PUBLIC_API(2,11) argon2_check_pwhash(const char* password, size_t password_len,
108  const std::string& hash);
109 
110 }
111 
112 #endif
std::string argon2_generate_pwhash(const char *password, size_t password_len, RandomNumberGenerator &rng, size_t p, size_t M, size_t t, uint8_t y=2, size_t salt_len=16, size_t output_len=32)
Definition: argon2fmt.cpp:26
bool argon2_check_pwhash(const char *password, size_t password_len, const std::string &hash)
Definition: argon2fmt.cpp:57
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: bigint.h:1135
size_t parallelism() const override
Definition: argon2.h:44
size_t M() const
Definition: argon2.h:38
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition: exceptn.cpp:11
std::string name
size_t p() const
Definition: argon2.h:40
size_t total_memory_usage() const override
Definition: argon2.h:48
size_t salt_len
Definition: x509_obj.cpp:25
Definition: alg_id.cpp:13
size_t iterations() const override
Definition: argon2.h:42
void argon2(uint8_t output[], size_t output_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len, const uint8_t key[], size_t key_len, const uint8_t ad[], size_t ad_len, uint8_t mode, size_t threads, size_t M, size_t t)
Definition: argon2.cpp:410
size_t memory_param() const override
Definition: argon2.h:46
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:139
MechanismType hash
size_t t() const
Definition: argon2.h:39