aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pbkdf/argon2/argon2.h
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-05-29 10:30:53 -0400
committerJack Lloyd <[email protected]>2019-05-29 10:30:53 -0400
commitbbc6fc46949c4db5ecd0ef720b32b8fa90ed9a8d (patch)
treedd8bdc05f3b537626d74ddace0ed507b36d35666 /src/lib/pbkdf/argon2/argon2.h
parente6775cf25394e2c3333facd060d3951ee30389b5 (diff)
Argon2: PasswordHash, documentation, hash formatting
Diffstat (limited to 'src/lib/pbkdf/argon2/argon2.h')
-rw-r--r--src/lib/pbkdf/argon2/argon2.h78
1 files changed, 76 insertions, 2 deletions
diff --git a/src/lib/pbkdf/argon2/argon2.h b/src/lib/pbkdf/argon2/argon2.h
index 27a6a3220..e0fe1d83d 100644
--- a/src/lib/pbkdf/argon2/argon2.h
+++ b/src/lib/pbkdf/argon2/argon2.h
@@ -1,5 +1,5 @@
/**
-* (C) 2018 Jack Lloyd
+* (C) 2018,2019 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
@@ -7,10 +7,70 @@
#ifndef BOTAN_ARGON2_H_
#define BOTAN_ARGON2_H_
-#include <botan/types.h>
+#include <botan/pwdhash.h>
namespace Botan {
+class RandomNumberGenerator;
+
+/**
+* Argon2 key derivation function
+*/
+class BOTAN_PUBLIC_API(2,11) Argon2 final : public PasswordHash
+ {
+ public:
+ Argon2(uint8_t family, size_t M, size_t t, size_t p);
+
+ Argon2(const Argon2& other) = default;
+ Argon2& operator=(const Argon2&) = default;
+
+ /**
+ * Derive a new key under the current Argon2 parameter set
+ */
+ void derive_key(uint8_t out[], size_t out_len,
+ const char* password, const size_t password_len,
+ const uint8_t salt[], size_t salt_len) const override;
+
+ std::string to_string() const override;
+
+ size_t M() const { return m_M; }
+ size_t t() const { return m_t; }
+ size_t p() const { return m_p; }
+
+ size_t iterations() const override { return t(); }
+
+ size_t parallelism() const override { return p(); }
+
+ size_t memory_param() const override { return M(); }
+
+ size_t total_memory_usage() const override { return M() * 1024; }
+
+ private:
+ uint8_t m_family;
+ size_t m_M, m_t, m_p;
+ };
+
+class BOTAN_PUBLIC_API(2,11) Argon2_Family final : public PasswordHashFamily
+ {
+ public:
+ Argon2_Family(uint8_t family);
+
+ std::string name() const override;
+
+ std::unique_ptr<PasswordHash> tune(size_t output_length,
+ std::chrono::milliseconds msec,
+ size_t max_memory) const override;
+
+ std::unique_ptr<PasswordHash> default_params() const override;
+
+ std::unique_ptr<PasswordHash> from_iterations(size_t iter) const override;
+
+ std::unique_ptr<PasswordHash> from_params(
+ size_t M, size_t t, size_t p) const override;
+ private:
+ const uint8_t m_family;
+ };
+
/**
* Argon2 key derivation function
*
@@ -31,6 +91,20 @@ void BOTAN_PUBLIC_API(2,11) argon2(uint8_t output[], size_t output_len,
const uint8_t ad[], size_t ad_len,
size_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,
+ size_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 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