Virgil Security Crypto library  2.0.7
VirgilPBKDF.h
1 
37 #ifndef VIRGIL_CRYPTO_PBKDF_H
38 #define VIRGIL_CRYPTO_PBKDF_H
39 
40 #include <string>
41 #include <memory>
42 
43 #include <virgil/crypto/VirgilByteArray.h>
44 #include <virgil/crypto/foundation/VirgilHash.h>
45 #include <virgil/crypto/foundation/asn1/VirgilAsn1Compatible.h>
46 
47 namespace virgil { namespace crypto { namespace foundation {
48 
53 public:
58  static constexpr unsigned int kIterationCount_Default = 2048;
59 public:
63  enum class Algorithm {
64  PBKDF2
65  };
69 
75  VirgilPBKDF();
76 
83  VirgilPBKDF(const virgil::crypto::VirgilByteArray& salt, unsigned int iterationCount = kIterationCount_Default);
85 
92 
96  VirgilByteArray getSalt() const;
97 
101  unsigned int getIterationCount() const;
102 
107 
112 
117 
122 
128 
135 
138 
148 
170  size_t asn1Write(asn1::VirgilAsn1Writer& asn1Writer, size_t childWrittenBytes = 0) const override;
172 
173  void asn1Read(asn1::VirgilAsn1Reader& asn1Reader) override;
175 public:
177  VirgilPBKDF(VirgilPBKDF&& rhs) noexcept;
178 
179  VirgilPBKDF& operator=(VirgilPBKDF&& rhs) noexcept;
180 
181  virtual ~VirgilPBKDF() noexcept;
183 
184 private:
188  void checkRecommendations(const VirgilByteArray& pwd) const;
189 
190 private:
191  class Impl;
192 
193  std::unique_ptr<Impl> impl_;
194 };
195 
196 }}}
197 
198 #endif /* VIRGIL_CRYPTO_PBKDF_H */
Algorithm
Defines specific password based key derivation function algorithm.
Definition: VirgilPBKDF.h:63
unsigned int getIterationCount() const
Return iteration count.
Algorithm
Enumerates possible Hash algorithms.
Definition: VirgilHash.h:57
virgil::crypto::VirgilByteArray derive(const virgil::crypto::VirgilByteArray &pwd, size_t outSize=0)
Derive key from the given key material.
This class provides methods for reading ASN.1 data structure.
Definition: VirgilAsn1Reader.h:53
VirgilByteArray getSalt() const
Return salt.
void disableRecommendationsCheck()
Ignore security check for used parameters.
static constexpr unsigned int kIterationCount_Default
Default iteration count.
Definition: VirgilPBKDF.h:58
This class provides interface that allow to save and restore object state in the ASN.1 structure.
Definition: VirgilAsn1Compatible.h:59
void asn1Read(asn1::VirgilAsn1Reader &asn1Reader) override
Read object state from the reader.
void setHashAlgorithm(VirgilHash::Algorithm hash)
Set underlying digest algorithm.
Definition: VirgilHash.h:252
This class provides methods for writing ASN.1 data structure.
Definition: VirgilAsn1Writer.h:54
Root namespace for all Virgil Security libraries.
Definition: VirgilAsn1Compatible.h:46
std::vector< unsigned char > VirgilByteArray
This type represents a sequence of bytes.
Definition: VirgilByteArray.h:53
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.
VirgilPBKDF()
Create object with undefined algorithms.
Defines PBKDF2 algorithm (https://www.ietf.org/rfc/rfc2898.txt)
void enableRecommendationsCheck()
Involve security check for used parameters.
VirgilHash::Algorithm getHashAlgorithm() const
Returns underlying digest algorithm.
Provides password based key derivation function.
Definition: VirgilPBKDF.h:52
size_t asn1Write(asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const override
Write object state to the writer.