CppSecurity  1.1.1.0
C++ Security Library
Public Member Functions | List of all members
CppSecurity::ScryptPasswordHashing Class Reference

'scrypt' password hashing algorithm More...

#include <password_hashing_scrypt.h>

Inheritance diagram for CppSecurity::ScryptPasswordHashing:
CppSecurity::PasswordHashing

Public Member Functions

 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. More...
 
 ScryptPasswordHashing (const ScryptPasswordHashing &)=default
 
 ScryptPasswordHashing (ScryptPasswordHashing &&)=default
 
 ~ScryptPasswordHashing ()=default
 
ScryptPasswordHashingoperator= (const ScryptPasswordHashing &)=default
 
ScryptPasswordHashingoperator= (ScryptPasswordHashing &&)=default
 
uint64_t n () const noexcept
 Get the CPU AND RAM cost. More...
 
uint32_t r () const noexcept
 Get the RAM Cost. More...
 
uint32_t p () const noexcept
 Get the degree of parallelism. More...
 
const std::string & name () const override
 Get the password hashing algorithm name. More...
 
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. More...
 
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. More...
 
- Public Member Functions inherited from CppSecurity::PasswordHashing
 PasswordHashing (size_t hash_length=32, size_t salt_length=32)
 Initialize password hashing with required parameters. More...
 
 PasswordHashing (const PasswordHashing &)=default
 
 PasswordHashing (PasswordHashing &&)=default
 
virtual ~PasswordHashing ()=default
 
PasswordHashingoperator= (const PasswordHashing &)=default
 
PasswordHashingoperator= (PasswordHashing &&)=default
 
size_t hash_length () const noexcept
 Get the strong password hash length. More...
 
size_t salt_length () const noexcept
 Get the unique password salt length. More...
 
virtual std::string GenerateSalt () const
 Generate the unique password salt. More...
 
virtual std::pair< std::string, std::string > GenerateHashAndSalt (std::string_view password) const
 Generate the strong password hash and unique salt for the given user password. More...
 
virtual std::string GenerateDigest (std::string_view password) const
 Generate the secure digest string for the given user password. More...
 
virtual std::string GenerateEncodedDigest (std::string_view password) const
 Generate the secure Base64 digest string for the given user password. More...
 
virtual bool ValidateDigest (std::string_view password, std::string_view digest) const
 Validate the user password over the given secure digest string. More...
 
virtual bool ValidateEncodedDigest (std::string_view password, std::string_view digest) const
 Validate the user password over the given secure Base64 digest string. More...
 

Detailed Description

'scrypt' password hashing algorithm

'scrypt' key derivation function was originally developed for use in the Tarsnap online backup system and is designed to be far more secure against hardware brute-force attacks than alternative functions such as PBKDF2 or bcrypt.

http://www.tarsnap.com/scrypt.html

Thread-safe.

Examples
password_hashing_scrypt.cpp.

Definition at line 26 of file password_hashing_scrypt.h.

Constructor & Destructor Documentation

◆ ScryptPasswordHashing() [1/3]

CppSecurity::ScryptPasswordHashing::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.

Parameters
hash_length- Strong password hash length (default is 32)
salt_length- Unique password salt length (default is 32)
n- CPU AND RAM cost (default is 512)
r- RAM Cost (default is 8)
p- Degree of parallelism (default is 1)

Definition at line 19 of file password_hashing_scrypt.cpp.

◆ ScryptPasswordHashing() [2/3]

CppSecurity::ScryptPasswordHashing::ScryptPasswordHashing ( const ScryptPasswordHashing )
default

◆ ScryptPasswordHashing() [3/3]

CppSecurity::ScryptPasswordHashing::ScryptPasswordHashing ( ScryptPasswordHashing &&  )
default

◆ ~ScryptPasswordHashing()

CppSecurity::ScryptPasswordHashing::~ScryptPasswordHashing ( )
default

Member Function Documentation

◆ GenerateHash()

std::string CppSecurity::ScryptPasswordHashing::GenerateHash ( std::string_view  password,
std::string_view  salt 
) const
overridevirtual

Generate the strong password hash for the given user password and unique salt.

Parameters
password- User password
salt- Unique password salt
Returns
Strong password hash

Implements CppSecurity::PasswordHashing.

Definition at line 25 of file password_hashing_scrypt.cpp.

◆ n()

uint64_t CppSecurity::ScryptPasswordHashing::n ( ) const
inlinenoexcept

Get the CPU AND RAM cost.

Definition at line 46 of file password_hashing_scrypt.h.

◆ name()

const std::string& CppSecurity::ScryptPasswordHashing::name ( ) const
inlineoverridevirtual

Get the password hashing algorithm name.

Implements CppSecurity::PasswordHashing.

Definition at line 53 of file password_hashing_scrypt.h.

◆ operator=() [1/2]

ScryptPasswordHashing& CppSecurity::ScryptPasswordHashing::operator= ( const ScryptPasswordHashing )
default

◆ operator=() [2/2]

ScryptPasswordHashing& CppSecurity::ScryptPasswordHashing::operator= ( ScryptPasswordHashing &&  )
default

◆ p()

uint32_t CppSecurity::ScryptPasswordHashing::p ( ) const
inlinenoexcept

Get the degree of parallelism.

Definition at line 50 of file password_hashing_scrypt.h.

◆ r()

uint32_t CppSecurity::ScryptPasswordHashing::r ( ) const
inlinenoexcept

Get the RAM Cost.

Definition at line 48 of file password_hashing_scrypt.h.

◆ Validate()

bool CppSecurity::ScryptPasswordHashing::Validate ( std::string_view  password,
std::string_view  hash,
std::string_view  salt 
) const
overridevirtual

Validate the user password over the given strong password hash and unique salt.

Parameters
password- User password
hash- Strong password hash
salt- Unique password salt
Returns
'true' if the given user password is valid, 'false' if the given user password is invalid

Implements CppSecurity::PasswordHashing.

Definition at line 34 of file password_hashing_scrypt.cpp.


The documentation for this class was generated from the following files: