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

#include <pwdhash.h>

Inheritance diagram for Botan::PasswordHash:
Botan::Argon2 Botan::Bcrypt_PBKDF Botan::PBKDF2 Botan::RFC4880_S2K Botan::Scrypt

Public Member Functions

virtual 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 =0
 
virtual 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
 
virtual size_t iterations () const =0
 
virtual size_t memory_param () const
 
virtual size_t parallelism () const
 
virtual std::string to_string () const =0
 
virtual size_t total_memory_usage () const
 
virtual ~PasswordHash ()=default
 

Detailed Description

Base class for password based key derivation functions.

Converts a password into a key using a salt and iterated hashing to make brute force attacks harder.

Definition at line 24 of file pwdhash.h.

Constructor & Destructor Documentation

◆ ~PasswordHash()

virtual Botan::PasswordHash::~PasswordHash ( )
virtualdefault

Member Function Documentation

◆ derive_key() [1/2]

virtual void Botan::PasswordHash::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
pure virtual

Derive a key from a password

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

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

Implemented in Botan::Argon2, Botan::Bcrypt_PBKDF, Botan::PBKDF2, Botan::RFC4880_S2K, and Botan::Scrypt.

Referenced by derive_key().

◆ derive_key() [2/2]

void Botan::PasswordHash::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
virtual

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 in Botan::Argon2.

Definition at line 33 of file pwdhash.cpp.

38 {
39 BOTAN_UNUSED(ad, key);
40
41 if(ad_len == 0 && key_len == 0)
42 return this->derive_key(out, out_len,
43 password, password_len,
44 salt, salt_len);
45 else
46 throw Not_Implemented("PasswordHash " + this->to_string() + " does not support AD or key");
47 }
#define BOTAN_UNUSED(...)
Definition: assert.h:141
virtual 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 =0
virtual std::string to_string() const =0
size_t salt_len
Definition: x509_obj.cpp:25

References BOTAN_UNUSED, derive_key(), salt_len, and to_string().

◆ iterations()

virtual size_t Botan::PasswordHash::iterations ( ) const
pure virtual

Most password hashes have some notion of iterations.

Implemented in Botan::Argon2, Botan::Bcrypt_PBKDF, Botan::PBKDF2, Botan::RFC4880_S2K, and Botan::Scrypt.

◆ memory_param()

virtual size_t Botan::PasswordHash::memory_param ( ) const
inlinevirtual

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

Reimplemented in Botan::Argon2, Botan::Bcrypt_PBKDF, and Botan::Scrypt.

Definition at line 40 of file pwdhash.h.

40{ return 0; }

◆ parallelism()

virtual size_t Botan::PasswordHash::parallelism ( ) const
inlinevirtual

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 in Botan::Argon2, Botan::Bcrypt_PBKDF, and Botan::Scrypt.

Definition at line 50 of file pwdhash.h.

50{ return 0; }

◆ to_string()

virtual std::string Botan::PasswordHash::to_string ( ) const
pure virtual

◆ total_memory_usage()

virtual size_t Botan::PasswordHash::total_memory_usage ( ) const
inlinevirtual

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 in Botan::Argon2, Botan::Bcrypt_PBKDF, and Botan::Scrypt.

Definition at line 59 of file pwdhash.h.

59{ return 0; }

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