Virgil Security Crypto library  1.8.2
VirgilPBKDF.h
1 
37 #ifndef VIRGIL_CRYPTO_PBKDF_H
38 #define VIRGIL_CRYPTO_PBKDF_H
39 
40 #include <string>
41 
42 #include <virgil/crypto/VirgilByteArray.h>
43 #include <virgil/crypto/foundation/asn1/VirgilAsn1Compatible.h>
44 
45 namespace virgil { namespace crypto { namespace foundation {
46 
50 class VirgilPBKDFImpl;
53 
58 public:
63  static const unsigned int kIterationCount_Default = 2048;
64 public:
68  typedef enum {
71  } Algorithm;
76  typedef enum {
77  Hash_SHA1 = 1,
82  } Hash;
83 
87 
93  VirgilPBKDF();
94 
101  VirgilPBKDF(const virgil::crypto::VirgilByteArray& salt, unsigned int iterationCount = kIterationCount_Default);
102 
106  virtual ~VirgilPBKDF() throw();
108 
115 
119  VirgilByteArray getSalt() const;
120 
124  unsigned int getIterationCount() const;
125 
130 
135 
139  void setHash(Hash hash);
140 
144  VirgilPBKDF::Hash getHash() const;
145 
151 
158 
161 
169  virgil::crypto::VirgilByteArray derive(const virgil::crypto::VirgilByteArray& pwd, size_t outSize = 0);
171 
193  virtual size_t asn1Write(
195  virgil::crypto::foundation::asn1::VirgilAsn1Writer& asn1Writer,
196  size_t childWrittenBytes = 0) const;
197 
198  virtual void asn1Read(virgil::crypto::foundation::asn1::VirgilAsn1Reader& asn1Reader);
200 private:
204  void checkState() const;
205 
209  void checkRecommendations(const VirgilByteArray& pwd) const;
210 
211 private:
212  VirgilPBKDF::Algorithm algorithm_;
213  VirgilPBKDF::Hash hash_;
214  VirgilByteArray salt_;
215  unsigned int iterationCount_;
216  unsigned int iterationCountMin_;
217  bool checkRecommendations_;
218 };
219 
220 }}}
221 
222 #endif /* VIRGIL_CRYPTO_PBKDF_H */
Algorithm
Defines specific password based key derivation function algorithm.
Definition: VirgilPBKDF.h:68
unsigned int getIterationCount() const
Return iteration count.
virgil::crypto::VirgilByteArray derive(const virgil::crypto::VirgilByteArray &pwd, size_t outSize=0)
Derive key from the given key material.
VirgilByteArray getSalt() const
Return salt.
void disableRecommendationsCheck()
Ignore security check for used parameters.
static const unsigned int kIterationCount_Default
Default iteration count.
Definition: VirgilPBKDF.h:63
This class provides interface that allow to save and restore object state in the ASN.1 structure.
Definition: VirgilAsn1Compatible.h:59
VirgilPBKDF::Hash getHash() const
Returns underlying digest algorithm.
Defines SHA-384 hash algorithm.
Definition: VirgilPBKDF.h:80
Definition: VirgilAsn1Compatible.h:46
virtual void asn1Read(virgil::crypto::foundation::asn1::VirgilAsn1Reader &asn1Reader)
Read object state from the reader.
No algorithm defined.
Definition: VirgilPBKDF.h:69
virtual ~VirgilPBKDF()
Polymorphic destructor.
VirgilPBKDF::Algorithm getAlgorithm() const
Return current algorithm of the password based key derivation function.
void setAlgorithm(VirgilPBKDF::Algorithm alg)
Set specific algorithm of the password based key derivation function.
Defines SHA1 hash algorithm.
Definition: VirgilPBKDF.h:77
Hash
Defines specific underlying hash algorithm for the password based key derivation function algorithm...
Definition: VirgilPBKDF.h:76
VirgilPBKDF()
Create object with undefined algorithms.
Defines SHA-224 hash algorithm.
Definition: VirgilPBKDF.h:78
Defines SHA-256 hash algorithm.
Definition: VirgilPBKDF.h:79
Defines SHA-512 hash algorithm.
Definition: VirgilPBKDF.h:81
Defines PBKDF2 algorithm (https://www.ietf.org/rfc/rfc2898.txt)
Definition: VirgilPBKDF.h:70
virtual size_t asn1Write(virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const
Write object state to the writer.
void enableRecommendationsCheck()
Involve security check for used parameters.
Provides password based key derivation function.
Definition: VirgilPBKDF.h:57
void setHash(Hash hash)
Set underlying digest algorithm.