Botan  2.11.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::Scrypt Class Referencefinal

#include <scrypt.h>

Inheritance diagram for Botan::Scrypt:
Botan::PasswordHash

Public Member Functions

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
 
size_t iterations () const override
 
size_t memory_param () const override
 
size_t N () const
 
Scryptoperator= (const Scrypt &)=default
 
size_t p () const
 
size_t parallelism () const override
 
size_t r () const
 
 Scrypt (size_t N, size_t r, size_t p)
 
 Scrypt (const Scrypt &other)=default
 
std::string to_string () const override
 
size_t total_memory_usage () const override
 

Detailed Description

Scrypt key derivation function (RFC 7914)

Definition at line 18 of file scrypt.h.

Constructor & Destructor Documentation

◆ Scrypt() [1/2]

Botan::Scrypt::Scrypt ( size_t  N,
size_t  r,
size_t  p 
)

Definition at line 127 of file scrypt.cpp.

127  :
128  m_N(N), m_r(r), m_p(p)
129  {
130  if(!is_power_of_2(N))
131  throw Invalid_Argument("Scrypt N parameter must be a power of 2");
132 
133  if(p == 0 || p > 1024)
134  throw Invalid_Argument("Invalid or unsupported scrypt p");
135  if(r == 0 || r > 256)
136  throw Invalid_Argument("Invalid or unsupported scrypt r");
137  if(N < 1 || N > 4194304)
138  throw Invalid_Argument("Invalid or unsupported scrypt N");
139  }
size_t p() const
Definition: scrypt.h:37
size_t r() const
Definition: scrypt.h:36
size_t N() const
Definition: scrypt.h:35
constexpr bool is_power_of_2(T arg)
Definition: bit_ops.h:43

◆ Scrypt() [2/2]

Botan::Scrypt::Scrypt ( const Scrypt other)
default

Member Function Documentation

◆ derive_key()

void Botan::Scrypt::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 Scrypt parameter set

Implements Botan::PasswordHash.

Definition at line 153 of file scrypt.cpp.

References N(), p(), r(), salt_len, and Botan::scrypt().

156  {
157  scrypt(output, output_len,
158  password, password_len,
159  salt, salt_len,
160  N(), r(), p());
161  }
size_t p() const
Definition: scrypt.h:37
size_t r() const
Definition: scrypt.h:36
size_t N() const
Definition: scrypt.h:35
size_t salt_len
Definition: x509_obj.cpp:26
void scrypt(uint8_t output[], size_t output_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len, size_t N, size_t r, size_t p)
Definition: scrypt.cpp:211

◆ iterations()

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

Most password hashes have some notion of iterations.

Implements Botan::PasswordHash.

Definition at line 39 of file scrypt.h.

39 { return r(); }
size_t r() const
Definition: scrypt.h:36

◆ memory_param()

size_t Botan::Scrypt::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 43 of file scrypt.h.

43 { return N(); }
size_t N() const
Definition: scrypt.h:35

◆ N()

size_t Botan::Scrypt::N ( ) const
inline

Definition at line 35 of file scrypt.h.

Referenced by derive_key().

35 { return m_N; }

◆ operator=()

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

◆ p()

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

Definition at line 37 of file scrypt.h.

Referenced by derive_key().

37 { return m_p; }

◆ parallelism()

size_t Botan::Scrypt::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 41 of file scrypt.h.

41 { return p(); }
size_t p() const
Definition: scrypt.h:37

◆ r()

size_t Botan::Scrypt::r ( ) const
inline

Definition at line 36 of file scrypt.h.

Referenced by derive_key().

36 { return m_r; }

◆ to_string()

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

Implements Botan::PasswordHash.

Definition at line 141 of file scrypt.cpp.

142  {
143  std::ostringstream oss;
144  oss << "Scrypt(" << m_N << "," << m_r << "," << m_p << ")";
145  return oss.str();
146  }

◆ total_memory_usage()

size_t Botan::Scrypt::total_memory_usage ( ) const
overridevirtual

Returns an estimate of the total memory usage 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 148 of file scrypt.cpp.

References Botan::scrypt_memory_usage().

149  {
150  return scrypt_memory_usage(m_N, m_r, m_p);
151  }
size_t scrypt_memory_usage(size_t N, size_t r, size_t p)
Definition: scrypt.h:118

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