11 #include "errors/exceptions.h"
17 std::string Argon2dPasswordHashing::_name =
"Argon2d";
18 std::string Argon2iPasswordHashing::_name =
"Argon2i";
19 std::string Argon2idPasswordHashing::_name =
"Argon2id";
31 if (argon2d_hash_raw(
t(),
m(),
p(), password.data(), password.size(), salt.data(), salt.size(), hash.data(), hash.size()) != ARGON2_OK)
32 throwex CppCommon::SecurityException(
"Cannot generate 'Argon2d' hash!");
39 std::string digest(hash.size(), 0);
40 if (argon2d_hash_raw(
t(),
m(),
p(), password.data(), password.size(), salt.data(), salt.size(), digest.data(), digest.size()) != ARGON2_OK)
41 throwex CppCommon::SecurityException(
"Cannot calculate 'Argon2d' hash!");
44 return (digest == hash);
51 if (argon2i_hash_raw(
t(),
m(),
p(), password.data(), password.size(), salt.data(), salt.size(), hash.data(), hash.size()) != ARGON2_OK)
52 throwex CppCommon::SecurityException(
"Cannot generate 'Argon2i' hash!");
59 std::string digest(hash.size(), 0);
60 if (argon2i_hash_raw(
t(),
m(),
p(), password.data(), password.size(), salt.data(), salt.size(), digest.data(), digest.size()) != ARGON2_OK)
61 throwex CppCommon::SecurityException(
"Cannot calculate 'Argon2i' hash!");
64 return (digest == hash);
71 if (argon2id_hash_raw(
t(),
m(),
p(), password.data(), password.size(), salt.data(), salt.size(), hash.data(), hash.size()) != ARGON2_OK)
72 throwex CppCommon::SecurityException(
"Cannot generate 'Argon2id' hash!");
79 std::string digest(hash.size(), 0);
80 if (argon2id_hash_raw(
t(),
m(),
p(), password.data(), password.size(), salt.data(), salt.size(), digest.data(), digest.size()) != ARGON2_OK)
81 throwex CppCommon::SecurityException(
"Cannot calculate 'Argon2id' hash!");
84 return (digest == hash);
std::string GenerateHash(std::string_view password, std::string_view salt) const override
Generate the strong password hash for the given user password and unique salt.
Argon2dPasswordHashing(size_t hash_length=32, size_t salt_length=32, uint32_t t=3, uint32_t m=512, uint32_t p=1)
Initialize 'Argon2' password hashing with required parameters.
bool Validate(std::string_view password, std::string_view hash, std::string_view salt) const override
Validate the user password over the given strong password hash and unique salt.
uint32_t p() const noexcept
Get the degree of parallelism.
uint32_t t() const noexcept
Get the number of iterations.
uint32_t m() const noexcept
Get the memory usage in kibibytes.
std::string GenerateHash(std::string_view password, std::string_view salt) const override
Generate the strong password hash for the given user password and unique salt.
bool Validate(std::string_view password, std::string_view hash, std::string_view salt) const override
Validate the user password over the given strong password hash and unique salt.
std::string GenerateHash(std::string_view password, std::string_view salt) const override
Generate the strong password hash for the given user password and unique salt.
bool Validate(std::string_view password, std::string_view hash, std::string_view salt) const override
Validate the user password over the given strong password hash and unique salt.
Password hashing interface.
size_t hash_length() const noexcept
Get the strong password hash length.
'Argon2' password hashing algorithm definition