NAWA 0.9
Web Application Framework for C++
nawa::hashing::Argon2HashingEngine Class Reference

#include <nawa/hashing/HashingEngine/impl/Argon2HashingEngine.h>

Inherits nawa::hashing::HashingEngine.

Public Types

enum class  Algorithm { ARGON2I , ARGON2D , ARGON2ID }
 

Public Member Functions

virtual ~Argon2HashingEngine ()
 
 Argon2HashingEngine (Algorithm algorithm=Algorithm::ARGON2ID, uint32_t timeCost=2, uint32_t memoryCost=(1<< 16), uint32_t parallelism=1, std::string salt="", size_t hashLen=32)
 
std::string generateHash (std::string input) const override
 
bool verifyHash (std::string input, std::string hash) const override
 

Detailed Description

Definition at line 32 of file Argon2HashingEngine.h.

Member Enumeration Documentation

◆ Algorithm

The Argon2 flavor to use.

Enumerator
ARGON2I 
ARGON2D 
ARGON2ID 

Definition at line 40 of file Argon2HashingEngine.h.

Constructor & Destructor Documentation

◆ ~Argon2HashingEngine()

virtual nawa::hashing::Argon2HashingEngine::~Argon2HashingEngine ( )
virtual

◆ Argon2HashingEngine()

hashing::Argon2HashingEngine::Argon2HashingEngine ( Algorithm  algorithm = Algorithm::ARGON2ID,
uint32_t  timeCost = 2,
uint32_t  memoryCost = (1 << 16),
uint32_t  parallelism = 1,
std::string  salt = "",
size_t  hashLen = 32 
)
explicit

Create a new Argon2 hash generator and set the parameters.

Parameters
algorithmThe Argon2 flavor to use.
timeCostNumber of iterations.
memoryCostMemory usage in kiB.
parallelismNumber of threads used.
saltUser-defined salt. Please leave this empty, a good salt will be generated automatically.
hashLenDesired hash lenght, 32 by default.

Definition at line 50 of file Argon2HashingEngine.cpp.

Member Function Documentation

◆ generateHash()

std::string hashing::Argon2HashingEngine::generateHash ( std::string  input) const
overridevirtual

Generate a hash of the input string with the given salt or, if empty, with a random one, and taking into account the properties.

This function might throw an exception with error code 10 (hash invalid), or 11 (argon2 error).

Parameters
inputThe input string to hash.
Returns
An Argon2 hash in standard format (starting with $argon2id$, for example, and in base64 format). The hash itself is, by default, 32 bytes (64 hash characters) long.

Implements nawa::hashing::HashingEngine.

Definition at line 56 of file Argon2HashingEngine.cpp.

◆ verifyHash()

bool hashing::Argon2HashingEngine::verifyHash ( std::string  input,
std::string  hash 
) const
overridevirtual

Verify if the given Argon2 hash, given in encoded format ("$argon2..."), has been generated using the input string. This function will create a new engine object according to the properties of the encoded string internally. It is designed in a way that it should not be vulnerable to timing attacks.

Parameters
inputThe input string.
hashThe hash to verify.
Returns
True if it matches, false otherwise.

Implements nawa::hashing::HashingEngine.

Definition at line 124 of file Argon2HashingEngine.cpp.


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