Crypto++ 8.0 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
8 class NullHash : public HashTransformation
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>
23 class TruncatedHashTemplate : public HashTransformation
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
48 typedef TruncatedHashTemplate<HashTransformation &> TruncatedHashModule;
49
50 NAMESPACE_END
51
52 #endif
TruncatedHashTemplate
construct new HashModule with smaller DigestSize() from existing one
Definition: trunhash.h:23
TruncatedHashTemplate::DigestSize
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: trunhash.h:37
NullHash::TruncatedVerify
bool TruncatedVerify(const byte *digest, size_t digestLength)
Verifies the hash of the current message.
Definition: trunhash.h:17
cryptlib.h
Abstract base classes that provide a uniform interface to this library.
TruncatedHashTemplate::TruncatedFinal
void TruncatedFinal(byte *digest, size_t digestSize)
Computes the hash of the current message.
Definition: trunhash.h:38
TruncatedHashTemplate::TruncatedVerify
bool TruncatedVerify(const byte *digest, size_t digestLength)
Verifies the hash of the current message.
Definition: trunhash.h:40
NullHash
Definition: trunhash.h:8
TruncatedHashTemplate::Restart
void Restart()
Restart the hash.
Definition: trunhash.h:33
NullHash::Update
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: trunhash.h:11
NullHash::DigestSize
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: trunhash.h:13
TruncatedHashTemplate::Update
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: trunhash.h:35
HashTransformation
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:1084
NullHash::TruncatedFinal
void TruncatedFinal(byte *digest, size_t digestSize)
Computes the hash of the current message.
Definition: trunhash.h:15
CryptoPP
Crypto++ library namespace.