Botan 3.0.0-alpha0
Crypto and TLS for C&
Public Member Functions | List of all members
Botan::Argon2 Class Referencefinal

#include <argon2.h>

Inheritance diagram for Botan::Argon2:
Botan::PasswordHash

Public Member Functions

 Argon2 (const Argon2 &other)=default
 
 Argon2 (uint8_t family, size_t M, size_t t, size_t p)
 
void derive_key (uint8_t out[], size_t out_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len) const override
 
void derive_key (uint8_t out[], size_t out_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len, const uint8_t ad[], size_t ad_len, const uint8_t key[], size_t key_len) const override
 
size_t iterations () const override
 
size_t M () const
 
size_t memory_param () const override
 
Argon2operator= (const Argon2 &)=default
 
size_t p () const
 
size_t parallelism () const override
 
size_t t () const
 
std::string to_string () const override
 
size_t total_memory_usage () const override
 

Detailed Description

Argon2 key derivation function

Definition at line 26 of file argon2.h.

Constructor & Destructor Documentation

◆ Argon2() [1/2]

Botan::Argon2::Argon2 ( uint8_t  family,
size_t  M,
size_t  t,
size_t  p 
)

Definition at line 14 of file argon2pwhash.cpp.

14 :
15 m_family(family),
16 m_M(M),
17 m_t(t),
18 m_p(p)
19 {
20 BOTAN_ARG_CHECK(m_p >= 1 && m_p <= 128, "Invalid Argon2 threads parameter");
21 BOTAN_ARG_CHECK(m_M >= 8*m_p && m_M <= 8192*1024, "Invalid Argon2 M parameter");
22 BOTAN_ARG_CHECK(m_t >= 1, "Invalid Argon2 t parameter");
23 }
#define BOTAN_ARG_CHECK(expr, msg)
Definition: assert.h:36
size_t p() const
Definition: argon2.h:51
size_t t() const
Definition: argon2.h:50
size_t M() const
Definition: argon2.h:49

◆ Argon2() [2/2]

Botan::Argon2::Argon2 ( const Argon2 other)
default

Member Function Documentation

◆ derive_key() [1/2]

void Botan::Argon2::derive_key ( uint8_t  out[],
size_t  out_len,
const char *  password,
size_t  password_len,
const uint8_t  salt[],
size_t  salt_len 
) const
overridevirtual

Derive a new key under the current Argon2 parameter set

Implements Botan::PasswordHash.

Definition at line 25 of file argon2pwhash.cpp.

28 {
29 argon2(output, output_len,
30 password, password_len,
31 salt, salt_len,
32 nullptr, 0,
33 nullptr, 0);
34 }
size_t salt_len
Definition: x509_obj.cpp:25

References salt_len.

◆ derive_key() [2/2]

void Botan::Argon2::derive_key ( uint8_t  out[],
size_t  out_len,
const char *  password,
size_t  password_len,
const uint8_t  salt[],
size_t  salt_len,
const uint8_t  ad[],
size_t  ad_len,
const uint8_t  key[],
size_t  key_len 
) const
overridevirtual

Derive a key from a password plus additional data and/or a secret key

Currently this is only supported for Argon2. Using a non-empty AD or key with other algorithms will cause a Not_Implemented exception.

Parameters
outbuffer to store the derived key, must be of out_len bytes
out_lenthe desired length of the key to produce
passwordthe password to derive the key from
password_lenthe length of password in bytes
salta randomly chosen salt
salt_lenlength of salt in bytes
adsome additional data
ad_lenlength of ad in bytes
keya secret key
key_lenlength of key in bytes

This function is const, but is not thread safe. Different threads should either use unique objects, or serialize all access.

Reimplemented from Botan::PasswordHash.

Definition at line 36 of file argon2pwhash.cpp.

41 {
42 argon2(output, output_len,
43 password, password_len,
44 salt, salt_len,
45 key, key_len,
46 ad, ad_len);
47 }

References salt_len.

◆ iterations()

size_t Botan::Argon2::iterations ( ) const
inlineoverridevirtual

Most password hashes have some notion of iterations.

Implements Botan::PasswordHash.

Definition at line 53 of file argon2.h.

53{ return t(); }

◆ M()

size_t Botan::Argon2::M ( ) const
inline

Definition at line 49 of file argon2.h.

49{ return m_M; }

◆ memory_param()

size_t Botan::Argon2::memory_param ( ) const
inlineoverridevirtual

Some password hashing algorithms have a parameter which controls how much memory is used. If not supported by some algorithm, returns 0.

Reimplemented from Botan::PasswordHash.

Definition at line 57 of file argon2.h.

57{ return M(); }

◆ operator=()

Argon2 & Botan::Argon2::operator= ( const Argon2 )
default

◆ p()

size_t Botan::Argon2::p ( ) const
inline

Definition at line 51 of file argon2.h.

51{ return m_p; }

◆ parallelism()

size_t Botan::Argon2::parallelism ( ) const
inlineoverridevirtual

Some password hashing algorithms have a parallelism parameter. If the algorithm does not support this notion, then the function returns zero. This allows distinguishing between a password hash which just does not support parallel operation, vs one that does support parallel operation but which has been configured to use a single lane.

Reimplemented from Botan::PasswordHash.

Definition at line 55 of file argon2.h.

55{ return p(); }

◆ t()

size_t Botan::Argon2::t ( ) const
inline

Definition at line 50 of file argon2.h.

50{ return m_t; }

◆ to_string()

std::string Botan::Argon2::to_string ( ) const
overridevirtual

Implements Botan::PasswordHash.

Definition at line 68 of file argon2pwhash.cpp.

69 {
70 return argon2_family_name(m_family) + "(" +
71 std::to_string(m_M) + "," +
72 std::to_string(m_t) + "," +
73 std::to_string(m_p) + ")";
74 }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:209

References Botan::ASN1::to_string().

◆ total_memory_usage()

size_t Botan::Argon2::total_memory_usage ( ) const
inlineoverridevirtual

Returns an estimate of the total number of bytes required to perform this key derivation.

If this algorithm uses a small and constant amount of memory, with no effort made towards being memory hard, this function returns 0.

Reimplemented from Botan::PasswordHash.

Definition at line 59 of file argon2.h.

59{ return M() * 1024; }

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