7#include <botan/argon2.h>
9#include <botan/base64.h>
10#include <botan/parsing.h>
17std::string strip_padding(std::string s)
19 while(s.size() > 0 && s[s.size()-1] ==
'=')
20 s.resize(s.size() - 1);
28 size_t p,
size_t M,
size_t t,
29 uint8_t y,
size_t salt_len,
size_t output_len)
34 std::vector<uint8_t> output(output_len);
35 argon2(output.data(), output.size(),
36 password, password_len,
37 salt.data(), salt.size(),
42 std::ostringstream oss;
51 oss <<
"v=19$m=" << M <<
",t=" << t <<
",p=" << p <<
"$";
58 const std::string& input_hash)
60 const std::vector<std::string> parts =
split_on(input_hash,
'$');
67 if(parts[0] ==
"argon2d")
69 else if(parts[0] ==
"argon2i")
71 else if(parts[0] ==
"argon2id")
76 if(parts[1] !=
"v=19")
79 const std::vector<std::string> params =
split_on(parts[2],
',');
81 if(params.size() != 3)
84 size_t M = 0, t = 0, p = 0;
86 for(
auto param_str : params)
88 const std::vector<std::string> param =
split_on(param_str,
'=');
93 const std::string key = param[0];
114 std::vector<uint8_t> generated(
hash.size());
115 argon2(generated.data(), generated.size(),
116 password, password_len,
117 salt.data(), salt.size(),
virtual void randomize(uint8_t output[], size_t length)=0
std::vector< std::string > split_on(const std::string &str, char delim)
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)
size_t base64_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
size_t base64_decode(uint8_t out[], const char in[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
bool constant_time_compare(const uint8_t x[], const uint8_t y[], size_t len)
bool argon2_check_pwhash(const char *password, size_t password_len, const std::string &hash)
size_t base64_decode_max_output(size_t input_length)
uint32_t to_u32bit(const std::string &str)
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)