aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pbkdf
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2021-04-07 11:43:58 -0400
committerJack Lloyd <[email protected]>2021-04-07 11:44:07 -0400
commit69c0bd859c19a33e44e6874f3ceae343332b28a9 (patch)
treef73e507ee637f9d447a900276b6cb2ac03a0db3b /src/lib/pbkdf
parent833aa251c7ebf0011699ca8d3d854ed118a17af4 (diff)
Move Argon2 formatting to argon2fmt module
Diffstat (limited to 'src/lib/pbkdf')
-rw-r--r--src/lib/pbkdf/argon2/argon2.h19
-rw-r--r--src/lib/pbkdf/argon2/argon2fmt.cpp125
-rw-r--r--src/lib/pbkdf/argon2/info.txt4
3 files changed, 5 insertions, 143 deletions
diff --git a/src/lib/pbkdf/argon2/argon2.h b/src/lib/pbkdf/argon2/argon2.h
index 3a1b859f0..82880031a 100644
--- a/src/lib/pbkdf/argon2/argon2.h
+++ b/src/lib/pbkdf/argon2/argon2.h
@@ -9,6 +9,10 @@
#include <botan/pwdhash.h>
+#if defined(BOTAN_HAS_ARGON2_FMT)
+ #include <botan/argon2fmt.h>
+#endif
+
//BOTAN_FUTURE_INTERNAL_HEADER(argon2.h)
namespace Botan {
@@ -98,21 +102,6 @@ void BOTAN_PUBLIC_API(2,11) argon2(uint8_t output[], size_t output_len,
const uint8_t ad[], size_t ad_len,
uint8_t y, size_t p, size_t M, size_t t);
-std::string BOTAN_PUBLIC_API(2,11)
- 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);
-
-/**
-* Check a previously created password hash
-* @param password the password to check against
-* @param password_len the length of password
-* @param hash the stored hash to check against
-*/
-bool BOTAN_PUBLIC_API(2,11) argon2_check_pwhash(const char* password, size_t password_len,
- const std::string& hash);
-
}
#endif
diff --git a/src/lib/pbkdf/argon2/argon2fmt.cpp b/src/lib/pbkdf/argon2/argon2fmt.cpp
deleted file mode 100644
index 974710b29..000000000
--- a/src/lib/pbkdf/argon2/argon2fmt.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/**
-* (C) 2019 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#include <botan/argon2.h>
-#include <botan/rng.h>
-#include <botan/base64.h>
-#include <botan/internal/parsing.h>
-#include <sstream>
-
-namespace Botan {
-
-namespace {
-
-std::string strip_padding(std::string s)
- {
- while(s.size() > 0 && s[s.size()-1] == '=')
- s.resize(s.size() - 1);
- return s;
- }
-
-}
-
-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, size_t salt_len, size_t output_len)
- {
- std::vector<uint8_t> salt(salt_len);
- rng.randomize(salt.data(), salt.size());
-
- std::vector<uint8_t> output(output_len);
- argon2(output.data(), output.size(),
- password, password_len,
- salt.data(), salt.size(),
- nullptr, 0,
- nullptr, 0,
- y, p, M, t);
-
- std::ostringstream oss;
-
- if(y == 0)
- oss << "$argon2d$";
- else if(y == 1)
- oss << "$argon2i$";
- else
- oss << "$argon2id$";
-
- oss << "v=19$m=" << M << ",t=" << t << ",p=" << p << "$";
- oss << strip_padding(base64_encode(salt)) << "$" << strip_padding(base64_encode(output));
-
- return oss.str();
- }
-
-bool argon2_check_pwhash(const char* password, size_t password_len,
- const std::string& input_hash)
- {
- const std::vector<std::string> parts = split_on(input_hash, '$');
-
- if(parts.size() != 5)
- return false;
-
- uint8_t family = 0;
-
- if(parts[0] == "argon2d")
- family = 0;
- else if(parts[0] == "argon2i")
- family = 1;
- else if(parts[0] == "argon2id")
- family = 2;
- else
- return false;
-
- if(parts[1] != "v=19")
- return false;
-
- const std::vector<std::string> params = split_on(parts[2], ',');
-
- if(params.size() != 3)
- return false;
-
- size_t M = 0, t = 0, p = 0;
-
- for(auto param_str : params)
- {
- const std::vector<std::string> param = split_on(param_str, '=');
-
- if(param.size() != 2)
- return false;
-
- const std::string key = param[0];
- const size_t val = to_u32bit(param[1]);
- if(key == "m")
- M = val;
- else if(key == "t")
- t = val;
- else if(key == "p")
- p = val;
- else
- return false;
- }
-
- std::vector<uint8_t> salt(base64_decode_max_output(parts[3].size()));
- salt.resize(base64_decode(salt.data(), parts[3], false));
-
- std::vector<uint8_t> hash(base64_decode_max_output(parts[4].size()));
- hash.resize(base64_decode(hash.data(), parts[4], false));
-
- if(hash.size() < 4)
- return false;
-
- std::vector<uint8_t> generated(hash.size());
- argon2(generated.data(), generated.size(),
- password, password_len,
- salt.data(), salt.size(),
- nullptr, 0,
- nullptr, 0,
- family, p, M, t);
-
- return constant_time_compare(generated.data(), hash.data(), generated.size());
- }
-
-}
diff --git a/src/lib/pbkdf/argon2/info.txt b/src/lib/pbkdf/argon2/info.txt
index c0a33f580..c2eff1936 100644
--- a/src/lib/pbkdf/argon2/info.txt
+++ b/src/lib/pbkdf/argon2/info.txt
@@ -1,13 +1,11 @@
<defines>
-ARGON2 -> 20190824
+ARGON2 -> 20210407
</defines>
<requires>
blake2
-base64
</requires>
-
<header:public>
argon2.h
</header:public>