Crypto++ 8.7
Free C++ class library of cryptographic schemes
Public Member Functions | Static Public Member Functions | List of all members
Scrypt Class Reference

Scrypt key derivation function. More...

#include <scrypt.h>

+ Inheritance diagram for Scrypt:

Public Member Functions

std::string AlgorithmName () const
 Provides the name of this algorithm. More...
 
size_t MaxDerivedKeyLength () const
 Determine maximum number of bytes. More...
 
size_t GetValidDerivedLength (size_t keylength) const
 Returns a valid key length for the derivation function. More...
 
size_t DeriveKey (byte *derived, size_t derivedLen, const byte *secret, size_t secretLen, const NameValuePairs &params) const
 Derive a key from a seed. More...
 
size_t DeriveKey (byte *derived, size_t derivedLen, const byte *secret, size_t secretLen, const byte *salt, size_t saltLen, word64 cost=2, word64 blockSize=8, word64 parallelization=1) const
 Derive a key from a seed. More...
 
- Public Member Functions inherited from KeyDerivationFunction
virtual std::string AlgorithmName () const =0
 Provides the name of this algorithm. More...
 
virtual size_t MinDerivedKeyLength () const
 Determine minimum number of bytes. More...
 
virtual size_t MaxDerivedKeyLength () const
 Determine maximum number of bytes. More...
 
virtual size_t GetValidDerivedLength (size_t keylength) const =0
 Returns a valid key length for the derivation function. More...
 
virtual bool IsValidDerivedLength (size_t keylength) const
 Returns whether keylength is a valid key length. More...
 
virtual size_t DeriveKey (byte *derived, size_t derivedLen, const byte *secret, size_t secretLen, const NameValuePairs &params=g_nullNameValuePairs) const =0
 Derive a key from a seed. More...
 
virtual void SetParameters (const NameValuePairs &params)
 Set or change parameters. More...
 
- Public Member Functions inherited from Algorithm
 Algorithm (bool checkSelfTestStatus=true)
 Interface for all crypto algorithms. More...
 
virtual std::string AlgorithmName () const
 Provides the name of this algorithm. More...
 
virtual std::string AlgorithmProvider () const
 Retrieve the provider of this algorithm. More...
 
- Public Member Functions inherited from Clonable
virtual ClonableClone () const
 Copies this object. More...
 

Static Public Member Functions

static std::string StaticAlgorithmName ()
 

Detailed Description

Scrypt key derivation function.

The Crypto++ implementation uses OpenMP to accelerate the derivation when available.

The Crypto++ implementation of Scrypt is limited by C++ datatypes. For example, the library is limited to a derived key length of SIZE_MAX, and not (2^32 - 1) * 32.

See also
Stronger Key Derivation via Sequential Memory-Hard Functions, The scrypt key derivation function and RFC 7914, The scrypt Password-Based Key Derivation Function
Since
Crypto++ 7.0

Definition at line 33 of file scrypt.h.

Constructor & Destructor Documentation

◆ ~Scrypt()

virtual Scrypt::~Scrypt ( )
inlinevirtual

Definition at line 36 of file scrypt.h.

Member Function Documentation

◆ StaticAlgorithmName()

static std::string Scrypt::StaticAlgorithmName ( )
inlinestatic

Definition at line 38 of file scrypt.h.

◆ AlgorithmName()

std::string Scrypt::AlgorithmName ( ) const
inlinevirtual

Provides the name of this algorithm.

Returns
the standard algorithm name

Implements KeyDerivationFunction.

Definition at line 43 of file scrypt.h.

◆ MaxDerivedKeyLength()

size_t Scrypt::MaxDerivedKeyLength ( ) const
inlinevirtual

Determine maximum number of bytes.

Returns
Maximum number of bytes which can be derived

Reimplemented from KeyDerivationFunction.

Definition at line 48 of file scrypt.h.

◆ GetValidDerivedLength()

size_t Scrypt::GetValidDerivedLength ( size_t  keylength) const
virtual

Returns a valid key length for the derivation function.

Parameters
keylengththe size of the derived key, in bytes
Returns
the valid key length, in bytes

Implements KeyDerivationFunction.

Definition at line 178 of file scrypt.cpp.

◆ DeriveKey() [1/2]

size_t Scrypt::DeriveKey ( byte derived,
size_t  derivedLen,
const byte secret,
size_t  secretLen,
const NameValuePairs params 
) const
virtual

Derive a key from a seed.

Parameters
derivedthe derived output buffer
derivedLenthe size of the derived buffer, in bytes
secretthe seed input buffer
secretLenthe size of the secret buffer, in bytes
paramsadditional initialization parameters to configure this object
Returns
the number of iterations performed
Exceptions
InvalidDerivedKeyLengthif derivedLen is invalid for the scheme

DeriveKey() provides a standard interface to derive a key from a secret seed and other parameters. Each class that derives from KeyDerivationFunction provides an overload that accepts most parameters used by the derivation function.

the number of iterations performed by DeriveKey() may be 1. For example, a scheme like HKDF does not use the iteration count so it returns 1.

Implements KeyDerivationFunction.

Definition at line 259 of file scrypt.cpp.

◆ DeriveKey() [2/2]

size_t Scrypt::DeriveKey ( byte derived,
size_t  derivedLen,
const byte secret,
size_t  secretLen,
const byte salt,
size_t  saltLen,
word64  cost = 2,
word64  blockSize = 8,
word64  parallelization = 1 
) const

Derive a key from a seed.

Parameters
derivedthe derived output buffer
derivedLenthe size of the derived buffer, in bytes
secretthe seed input buffer
secretLenthe size of the secret buffer, in bytes
saltthe salt input buffer
saltLenthe size of the salt buffer, in bytes
costthe CPU/memory cost factor
blockSizethe block size
parallelizationthe parallelization factor
Returns
the number of iterations performed
Exceptions
InvalidDerivedKeyLengthif derivedLen is invalid for the scheme

DeriveKey() provides a standard interface to derive a key from a seed and other parameters. Each class that derives from KeyDerivationFunction provides an overload that accepts most parameters used by the derivation function.

The CPU/Memory cost parameter ("N" in the documents) must be larger than 1, a power of 2, and less than 2^(128 * r / 8).

The parameter blockSize ("r" in the documents) specifies the block size.

The parallelization parameter ("p" in the documents) is a positive integer less than or equal to ((2^32-1) * 32) / (128 * r). Due to Microsoft and its OpenMP 2.0 implementation parallelization is limited to std::numeric_limits<int>::max().

Scrypt always returns 1 because it only performs 1 iteration. Other derivation functions, like PBKDF's, will return more interesting values.

The Crypto++ implementation of Scrypt is limited by C++ datatypes. For example, the library is limited to a derived key length of SIZE_MAX, and not (2^32 - 1) * 32.

Definition at line 282 of file scrypt.cpp.


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