Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::Scrypt Class Referencefinal

`#include <scrypt.h>`

Inheritance diagram for Botan::Scrypt:

## 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
Scrypt & | operator= (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 20 of file scrypt.h.

## Constructor & Destructor Documentation

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

Definition at line 127 of file scrypt.cpp.

References Botan::is_power_of_2().

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 }
Botan::Scrypt::r
size_t r() const
Definition: scrypt.h:38
Botan::is_power_of_2
constexpr bool is_power_of_2(T arg)
Definition: bit_ops.h:43
Botan::Scrypt::N
size_t N() const
Definition: scrypt.h:37
Botan::Scrypt::p
size_t p() const
Definition: scrypt.h:39

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

## Member Function Documentation

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
| override virtual

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(), and Botan::scrypt().

156 {
157 scrypt(output, output_len,
158 password, password_len,
159 salt, salt_len,
160 N(), r(), p());
161 }
Botan::Scrypt::r
size_t r() const
Definition: scrypt.h:38
salt_len
size_t salt_len
Definition: x509_obj.cpp:25
Botan::Scrypt::N
size_t N() const
Definition: scrypt.h:37
Botan::scrypt
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
Botan::Scrypt::p
size_t p() const
Definition: scrypt.h:39

size_t Botan::Scrypt::iterations | ( |  | ) | const
| inline override virtual

Most password hashes have some notion of iterations.

Implements Botan::PasswordHash.

Definition at line 41 of file scrypt.h.

41 { return r(); }
Botan::Scrypt::r
size_t r() const
Definition: scrypt.h:38

size_t Botan::Scrypt::memory_param | ( |  | ) | const
| inline override virtual

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 45 of file scrypt.h.

45 { return N(); }
Botan::Scrypt::N
size_t N() const
Definition: scrypt.h:37

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

Definition at line 37 of file scrypt.h.

Referenced by derive_key().

37 { return m_N; }

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

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

Definition at line 39 of file scrypt.h.

References m_p.

Referenced by derive_key().

39 { return m_p; }

size_t Botan::Scrypt::parallelism | ( |  | ) | const
| inline override virtual

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 43 of file scrypt.h.

43 { return p(); }
Botan::Scrypt::p
size_t p() const
Definition: scrypt.h:39

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

Definition at line 38 of file scrypt.h.

References m_r.

Referenced by derive_key().

38 { return m_r; }

std::string Botan::Scrypt::to_string | ( |  | ) | const
| override virtual

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 }

size_t Botan::Scrypt::total_memory_usage | ( |  | ) | const
| override virtual

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 }
Botan::scrypt_memory_usage
size_t scrypt_memory_usage(size_t N, size_t r, size_t p)
Definition: scrypt.h:120

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

- src/lib/pbkdf/scrypt/scrypt.h
- src/lib/pbkdf/scrypt/scrypt.cpp