Virgil Security Crypto library  1.8.2
VirgilHash.h
1 
37 #ifndef VIRGIL_CRYPTO_HASH_H
38 #define VIRGIL_CRYPTO_HASH_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 VirgilHashImpl;
53 
58 public:
63  static VirgilHash md5();
65 
66  static VirgilHash sha256();
67 
68  static VirgilHash sha384();
69 
70  static VirgilHash sha512();
71 
72  static VirgilHash withName(const virgil::crypto::VirgilByteArray& name);
74 
77 
83  VirgilHash();
84 
88  virtual ~VirgilHash() throw();
90 
97 
102  std::string name() const;
103 
108  int type() const;
110 
115 
124  virgil::crypto::VirgilByteArray hash(const virgil::crypto::VirgilByteArray& bytes) const;
126 
133 
137  void start();
138 
148  void update(const virgil::crypto::VirgilByteArray& bytes);
149 
156  virgil::crypto::VirgilByteArray finish();
158 
163 
173  virgil::crypto::VirgilByteArray hmac(
174  const virgil::crypto::VirgilByteArray& key,
175  const virgil::crypto::VirgilByteArray& bytes) const;
177 
184 
189  void hmacStart(const virgil::crypto::VirgilByteArray& key);
190 
194  void hmacReset();
195 
206  void hmacUpdate(const virgil::crypto::VirgilByteArray& bytes);
207 
215  virgil::crypto::VirgilByteArray hmacFinish();
217 
223  VirgilHash(const VirgilHash& other);
225 
226  VirgilHash& operator=(const VirgilHash& rhs);
228 
231  virtual size_t asn1Write(
234  size_t childWrittenBytes = 0) const;
235 
238 private:
239  explicit VirgilHash(int type);
240 
241  explicit VirgilHash(const char* name);
242 
243  void checkState() const;
244 
245 private:
246  VirgilHashImpl* impl_;
247 };
248 
249 }}}
250 
251 #endif /* VIRGIL_CRYPTO_HASH_H */
int type() const
Return underlying hash type.
void start()
Initialize hashing for the new message hash.
virgil::crypto::VirgilByteArray hmac(const virgil::crypto::VirgilByteArray &key, const virgil::crypto::VirgilByteArray &bytes) const
Produce HMAC hash.
This class provides methods for reading ASN.1 data structure.
Definition: VirgilAsn1Reader.h:53
void update(const virgil::crypto::VirgilByteArray &bytes)
Update / process message hash.
virtual ~VirgilHash()
Polymorphic destructor.
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:57
virtual void asn1Read(virgil::crypto::foundation::asn1::VirgilAsn1Reader &asn1Reader)
Read object state from the reader.
This class provides methods for writing ASN.1 data structure.
Definition: VirgilAsn1Writer.h:54
VirgilHash()
Create object with undefined algorithm.
Definition: VirgilAsn1Compatible.h:46
void hmacReset()
Reset HMAC hashing for the new message hash.
std::string name() const
Returns name of the hash function.
virgil::crypto::VirgilByteArray hmacFinish()
Return final message HMAC hash.
virgil::crypto::VirgilByteArray hash(const virgil::crypto::VirgilByteArray &bytes) const
Produce hash.
void hmacStart(const virgil::crypto::VirgilByteArray &key)
Initialize HMAC hashing for the new message hash.
void hmacUpdate(const virgil::crypto::VirgilByteArray &bytes)
Update / process message HMAC hash.
virgil::crypto::VirgilByteArray finish()
Return final message hash.
virtual size_t asn1Write(virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const
Write object state to the writer.