Virgil Security Crypto library  1.8.2
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_None = 0, Algorithm_PBKDF2 }
 Defines specific password based key derivation function algorithm. More...
 
enum  Hash {
  Hash_SHA1 = 1, Hash_SHA224, Hash_SHA256, Hash_SHA384,
  Hash_SHA512
}
 Defines specific underlying hash algorithm for the 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...
 
virtual ~VirgilPBKDF () throw ()
 Polymorphic destructor.
 
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 setHash (Hash hash)
 Set underlying digest algorithm.
 
VirgilPBKDF::Hash getHash () 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
}
virtual size_t asn1Write (virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const
 Write object state to the writer. More...
 
virtual void asn1Read (virgil::crypto::foundation::asn1::VirgilAsn1Reader &asn1Reader)
 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 () throw ()
 Polymorphic destructor.
 

Static Public Attributes

static const unsigned int kIterationCount_Default = 2048
 Default iteration count.
 

Additional Inherited Members

- Protected Member Functions inherited from virgil::crypto::foundation::asn1::VirgilAsn1Compatible
virtual void checkAsn1ParamNotEmpty (const virgil::crypto::VirgilByteArray &param, const char *paramName=0) 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
Algorithm_None 

No algorithm defined.

Algorithm_PBKDF2 

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

Defines specific underlying hash algorithm for the password based key derivation function algorithm.

Note
Start numbering from 1, 0 is reserved.
Enumerator
Hash_SHA1 

Defines SHA1 hash algorithm.

Hash_SHA224 

Defines SHA-224 hash algorithm.

Hash_SHA256 

Defines SHA-256 hash algorithm.

Hash_SHA384 

Defines SHA-384 hash algorithm.

Hash_SHA512 

Defines SHA-512 hash algorithm.

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

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

Read object state from the reader.

Parameters
asn1Readerreader payloaded with ASN.1 to be read.

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

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

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: