Crypto++  5.6.3
Free C++ class library of cryptographic schemes
trunhash.h
1 #ifndef CRYPTOPP_TRUNHASH_H
2 #define CRYPTOPP_TRUNHASH_H
3 
4 #include "cryptlib.h"
5 
6 NAMESPACE_BEGIN(CryptoPP)
7 
9 {
10 public:
11  void Update(const byte *input, size_t length)
12  {CRYPTOPP_UNUSED(input);CRYPTOPP_UNUSED(length);}
13  unsigned int DigestSize() const
14  {return 0;}
15  void TruncatedFinal(byte *digest, size_t digestSize)
16  {CRYPTOPP_UNUSED(digest);CRYPTOPP_UNUSED(digestSize);}
17  bool TruncatedVerify(const byte *digest, size_t digestLength)
18  {CRYPTOPP_UNUSED(digest);CRYPTOPP_UNUSED(digestLength);return true;}
19 };
20 
21 //! construct new HashModule with smaller DigestSize() from existing one
22 template <class T>
24 {
25 public:
26  TruncatedHashTemplate(T hm, unsigned int digestSize)
27  : m_hm(hm), m_digestSize(digestSize) {}
28  TruncatedHashTemplate(const byte *key, size_t keyLength, unsigned int digestSize)
29  : m_hm(key, keyLength), m_digestSize(digestSize) {}
30  TruncatedHashTemplate(size_t digestSize)
31  : m_digestSize(digestSize) {}
32 
33  void Restart()
34  {m_hm.Restart();}
35  void Update(const byte *input, size_t length)
36  {m_hm.Update(input, length);}
37  unsigned int DigestSize() const {return m_digestSize;}
38  void TruncatedFinal(byte *digest, size_t digestSize)
39  {m_hm.TruncatedFinal(digest, digestSize);}
40  bool TruncatedVerify(const byte *digest, size_t digestLength)
41  {return m_hm.TruncatedVerify(digest, digestLength);}
42 
43 private:
44  T m_hm;
45  unsigned int m_digestSize;
46 };
47 
49 
50 NAMESPACE_END
51 
52 #endif
construct new HashModule with smaller DigestSize() from existing one
Definition: trunhash.h:23
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: trunhash.h:37
bool TruncatedVerify(const byte *digest, size_t digestLength)
Verifies the hash of the current message.
Definition: trunhash.h:17
Abstract base classes that provide a uniform interface to this library.
void TruncatedFinal(byte *digest, size_t digestSize)
Computes the hash of the current message.
Definition: trunhash.h:38
bool TruncatedVerify(const byte *digest, size_t digestLength)
Verifies the hash of the current message.
Definition: trunhash.h:40
void Restart()
Restart the hash.
Definition: trunhash.h:33
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: trunhash.h:13
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: trunhash.h:11
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: trunhash.h:35
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:922
void TruncatedFinal(byte *digest, size_t digestSize)
Computes the hash of the current message.
Definition: trunhash.h:15
Crypto++ library namespace.