Virgil Security Crypto library  2.0.7
VirgilHash.h
1 
37 #ifndef VIRGIL_CRYPTO_HASH_H
38 #define VIRGIL_CRYPTO_HASH_H
39 
40 #include <string>
41 #include <memory>
42 
43 #include <virgil/crypto/VirgilByteArray.h>
44 #include <virgil/crypto/foundation/asn1/VirgilAsn1Compatible.h>
45 
46 namespace virgil { namespace crypto { namespace foundation {
47 
53 public:
57  enum class Algorithm {
58  MD5,
59  SHA1,
60  SHA224,
61  SHA256,
62  SHA384,
63  SHA512
64  };
65 
69 
75  VirgilHash();
76 
80  explicit VirgilHash(Algorithm alg);
81 
86  explicit VirgilHash(const std::string& name);
87 
92  explicit VirgilHash(const char* name);
94 
101 
106  std::string name() const;
107 
112  int type() const;
114 
119 
130 
137 
141  void start();
142 
152  void update(const virgil::crypto::VirgilByteArray& data);
153 
162 
167 
179  const virgil::crypto::VirgilByteArray& data) const;
181 
188 
194 
198  void hmacReset();
199 
211 
221 
224  size_t asn1Write(
227  size_t childWrittenBytes = 0) const override;
228 
231 
232 public:
234  VirgilHash(VirgilHash&& rhs) noexcept;
235 
236  VirgilHash& operator=(VirgilHash&& rhs) noexcept;
237 
238  virtual ~VirgilHash() noexcept;
240 
241 private:
242  void checkState() const;
243 
244 private:
245  class Impl;
246 
247  std::unique_ptr<Impl> impl_;
248 };
249 
250 }}}
251 
252 namespace std {
259 }
260 
261 #endif /* VIRGIL_CRYPTO_HASH_H */
int type() const
Return underlying hash type.
void start()
Initialize hashing for the new message hash.
Algorithm
Enumerates possible Hash algorithms.
Definition: VirgilHash.h:57
This class provides methods for reading ASN.1 data structure.
Definition: VirgilAsn1Reader.h:53
This class provides interface that allow to save and restore object state in the ASN.1 structure.
Definition: VirgilAsn1Compatible.h:59
Provides hashing (message digest) algorithms.
Definition: VirgilHash.h:52
Definition: VirgilHash.h:252
This class provides methods for writing ASN.1 data structure.
Definition: VirgilAsn1Writer.h:54
VirgilHash()
Create object with undefined algorithm.
Root namespace for all Virgil Security libraries.
Definition: VirgilAsn1Compatible.h:46
void hmacUpdate(const virgil::crypto::VirgilByteArray &data)
Update / process message HMAC hash.
std::vector< unsigned char > VirgilByteArray
This type represents a sequence of bytes.
Definition: VirgilByteArray.h:53
size_t asn1Write(virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const override
Write object state to the writer.
string to_string(virgil::crypto::foundation::VirgilHash::Algorithm alg)
Returns string representation of the Hash algorithm.
void hmacReset()
Reset HMAC hashing for the new message hash.
std::string name() const
Returns name of the hash function.
void update(const virgil::crypto::VirgilByteArray &data)
Update / process message hash.
virgil::crypto::VirgilByteArray hmacFinish()
Return final message HMAC hash.
void hmacStart(const virgil::crypto::VirgilByteArray &key)
Initialize HMAC hashing for the new message hash.
void asn1Read(virgil::crypto::foundation::asn1::VirgilAsn1Reader &asn1Reader) override
Read object state from the reader.
virgil::crypto::VirgilByteArray hmac(const virgil::crypto::VirgilByteArray &key, const virgil::crypto::VirgilByteArray &data) const
Produce HMAC hash.
virgil::crypto::VirgilByteArray hash(const virgil::crypto::VirgilByteArray &data) const
Produce hash.
virgil::crypto::VirgilByteArray finish()
Return final message hash.