Virgil Security Crypto library  2.6.3
Public Types | Static Public Attributes | List of all members
virgil::crypto::foundation::VirgilPBKDF Class Reference

Provides password based key derivation function. More...

#include <VirgilPBKDF.h>

Inheritance diagram for virgil::crypto::foundation::VirgilPBKDF:
virgil::crypto::foundation::asn1::VirgilAsn1Compatible

Public Types

enum  Algorithm { Algorithm::PBKDF2 }
 Defines specific password based key derivation function algorithm. More...
 

Public Member Functions

Constructor / Destructor
 VirgilPBKDF ()
 Create object with undefined algorithms. More...
 
 VirgilPBKDF (const virgil::crypto::VirgilByteArray &salt, unsigned int iterationCount=kIterationCount_Default)
 Create object with default algorithm. More...
 
Configuration / Info

Provide methods that allow precise algorithm configuration and get information about it.

VirgilByteArray getSalt () const
 Return salt.
 
unsigned int getIterationCount () const
 Return iteration count.
 
void setAlgorithm (VirgilPBKDF::Algorithm alg)
 Set specific algorithm of the password based key derivation function.
 
VirgilPBKDF::Algorithm getAlgorithm () const
 Return current algorithm of the password based key derivation function.
 
void setHashAlgorithm (VirgilHash::Algorithm hash)
 Set underlying digest algorithm.
 
VirgilHash::Algorithm getHashAlgorithm () const
 Returns underlying digest algorithm.
 
void enableRecommendationsCheck ()
 Involve security check for used parameters. More...
 
void disableRecommendationsCheck ()
 Ignore security check for used parameters. More...
 
Process password based key derivation
virgil::crypto::VirgilByteArray derive (const virgil::crypto::VirgilByteArray &pwd, size_t outSize=0)
 Derive key from the given key material. More...
 
VirgilAsn1Compatible implementation
Marshalling format:
KeyDerivationFunction ::= AlgorithmIdentifier {{ PBKDFAlgorithms }}
PBKDFAlgorithms AlgorithmIdentifier ::= {
{ OID id-PBKDF2 PARMS BKDF2-params },
... -- additional algorithms ---
}
PBKDF2-params ::= SEQUENCE {
salt CHOICE {
specified OCTET STRING,
otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}}
},
iterationCount INTEGER (1..MAX),
keyLength INTEGER (1..MAX) OPTIONAL,
prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT
algid-hmacWithSHA1
}
size_t asn1Write (asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const override
 Write object state to the writer. More...
 
void asn1Read (asn1::VirgilAsn1Reader &asn1Reader) override
 Read object state from the reader. More...
 
- Public Member Functions inherited from virgil::crypto::foundation::asn1::VirgilAsn1Compatible
virgil::crypto::VirgilByteArray toAsn1 () const
 Save object state to the ASN.1 structure.
 
void fromAsn1 (const virgil::crypto::VirgilByteArray &asn1)
 Restore object state from the ASN.1 structure.
 
virtual ~VirgilAsn1Compatible () noexcept
 Polymorphic destructor.
 

Static Public Attributes

static constexpr unsigned int kIterationCount_Default = 2048
 Default iteration count.
 

Additional Inherited Members

- Protected Member Functions inherited from virgil::crypto::foundation::asn1::VirgilAsn1Compatible
virtual void checkRequiredField (const VirgilByteArray &param) const
 If given parameter is empty exception will be thrown. More...
 

Detailed Description

Provides password based key derivation function.

Member Enumeration Documentation

Defines specific password based key derivation function algorithm.

Enumerator
PBKDF2 

Defines PBKDF2 algorithm (https://www.ietf.org/rfc/rfc2898.txt)

Constructor & Destructor Documentation

virgil::crypto::foundation::VirgilPBKDF::VirgilPBKDF ( )

Create object with undefined algorithms.

Warning
SHOULD be used in conjunction with VirgilAsn1Compatible interface, i.e. VirgilPBKDF pbkdf = VirgilPBKDF().fromAsn1(asn1);
virgil::crypto::foundation::VirgilPBKDF::VirgilPBKDF ( const virgil::crypto::VirgilByteArray salt,
unsigned int  iterationCount = kIterationCount_Default 
)

Create object with default algorithm.

Parameters
salt- salt to use when generating key, the best practice is to pass random value.
iterationCount- iteration count, the best practice is to pass random value.

Member Function Documentation

void virgil::crypto::foundation::VirgilPBKDF::asn1Read ( asn1::VirgilAsn1Reader asn1Reader)
overridevirtual

Read object state from the reader.

Parameters
asn1Readerreader payloaded with ASN.1 to be read.

Implements virgil::crypto::foundation::asn1::VirgilAsn1Compatible.

size_t virgil::crypto::foundation::VirgilPBKDF::asn1Write ( asn1::VirgilAsn1Writer asn1Writer,
size_t  childWrittenBytes = 0 
) const
overridevirtual

Write object state to the writer.

Parameters
asn1Writerwriter that should be payloaded by subclasses.
childWrittenBytescount of bytes that was written by subclasses.
Returns
Writen bytes count.

Implements virgil::crypto::foundation::asn1::VirgilAsn1Compatible.

virgil::crypto::VirgilByteArray virgil::crypto::foundation::VirgilPBKDF::derive ( const virgil::crypto::VirgilByteArray pwd,
size_t  outSize = 0 
)

Derive key from the given key material.

Parameters
pwd- password to use when generating key.
outSize- size of the output sequence, if 0 - then size of the underlying hash will be used.
Returns
Output sequence.
void virgil::crypto::foundation::VirgilPBKDF::disableRecommendationsCheck ( )

Ignore security check for used parameters.

Warning
It's strongly recommended do not disable recommendations check.
void virgil::crypto::foundation::VirgilPBKDF::enableRecommendationsCheck ( )

Involve security check for used parameters.

Note
Enabled by default.

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