11 #include "errors/exceptions.h"
13 #include <libscrypt.h>
17 std::string ScryptPasswordHashing::_name =
"scrypt";
29 if (libscrypt_scrypt((
const uint8_t*)password.data(), password.size(), (
const uint8_t*)salt.data(), salt.size(),
n(),
r(),
p(), (uint8_t*)hash.data(), hash.size()) != 0)
30 throwex CppCommon::SecurityException(
"Cannot generate 'scrypt' hash!");
37 std::string digest(hash.size(), 0);
38 if (libscrypt_scrypt((
const uint8_t*)password.data(), password.size(), (
const uint8_t*)salt.data(), salt.size(),
n(),
r(),
p(), (uint8_t*)digest.data(), digest.size()) != 0)
39 throwex CppCommon::SecurityException(
"Cannot calculate 'scrypt' hash!");
42 return (digest == hash);
Password hashing interface.
size_t hash_length() const noexcept
Get the strong password hash length.
uint32_t r() const noexcept
Get the RAM Cost.
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.
ScryptPasswordHashing(size_t hash_length=32, size_t salt_length=32, uint64_t n=512, uint32_t r=8, uint32_t p=1)
Initialize 'scrypt' password hashing with required parameters.
uint32_t p() const noexcept
Get the degree of parallelism.
uint64_t n() const noexcept
Get the CPU AND RAM cost.
'scrypt' password hashing algorithm definition