Security Scol plugin
|
Scrypt key derivation function. More...
#include <scrypt.h>
Public Member Functions | |
std::string | AlgorithmName () const |
Provides the name of this algorithm. | |
size_t | MaxDerivedKeyLength () const |
Determine maximum number of bytes. | |
size_t | GetValidDerivedLength (size_t keylength) const |
Returns a valid key length for the derivation function. | |
size_t | DeriveKey (byte *derived, size_t derivedLen, const byte *secret, size_t secretLen, const NameValuePairs ¶ms) const |
Derive a key from a seed. | |
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. | |
Public Member Functions inherited from KeyDerivationFunction | |
virtual size_t | MinDerivedKeyLength () const |
Determine minimum number of bytes. | |
virtual bool | IsValidDerivedLength (size_t keylength) const |
Returns whether keylength is a valid key length. | |
virtual void | SetParameters (const NameValuePairs ¶ms) |
Set or change parameters. | |
Public Member Functions inherited from Algorithm | |
Algorithm (bool checkSelfTestStatus=true) | |
Interface for all crypto algorithms. | |
virtual std::string | AlgorithmProvider () const |
Retrieve the provider of this algorithm. | |
Public Member Functions inherited from Clonable | |
virtual Clonable * | Clone () const |
Copies this object. | |
Static Public Member Functions | |
static std::string | StaticAlgorithmName () |
Protected Types | |
enum | { defaultCost =2 , defaultBlockSize =8 , defaultParallelization =1 } |
Protected Member Functions | |
const Algorithm & | GetAlgorithm () const |
Returns the base class Algorithm. | |
void | ValidateParameters (size_t derivedlen, word64 cost, word64 blockSize, word64 parallelization) const |
Protected Member Functions inherited from KeyDerivationFunction | |
void | ThrowIfInvalidDerivedKeyLength (size_t length) const |
Validates the derived key length. | |
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
.
|
inlinevirtual |
Provides the name of this algorithm.
Implements KeyDerivationFunction.
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.
derived | the derived output buffer |
derivedLen | the size of the derived buffer, in bytes |
secret | the seed input buffer |
secretLen | the size of the secret buffer, in bytes |
salt | the salt input buffer |
saltLen | the size of the salt buffer, in bytes |
cost | the CPU/memory cost factor |
blockSize | the block size |
parallelization | the parallelization factor |
InvalidDerivedKeyLength | if 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.
|
virtual |
Derive a key from a seed.
derived | the derived output buffer |
derivedLen | the size of the derived buffer, in bytes |
secret | the seed input buffer |
secretLen | the size of the secret buffer, in bytes |
params | additional initialization parameters to configure this object |
InvalidDerivedKeyLength | if 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.
|
inlineprotectedvirtual |
|
virtual |
Returns a valid key length for the derivation function.
keylength | the size of the derived key, in bytes |
Implements KeyDerivationFunction.
Definition at line 178 of file scrypt.cpp.
|
inlinevirtual |
Determine maximum number of bytes.
Reimplemented from KeyDerivationFunction.
|
inlinestatic |
|
inlineprotected |
Definition at line 185 of file scrypt.cpp.