Crypto++ 8.7
Free C++ class library of cryptographic schemes
trunhash.h
Go to the documentation of this file.
1// trunhash.h - originally written and placed in the public domain by Wei Dai
2
3/// \file trunhash.h
4/// \brief Classes for truncated hashes
5
6#ifndef CRYPTOPP_TRUNHASH_H
7#define CRYPTOPP_TRUNHASH_H
8
9#include "cryptlib.h"
10
11NAMESPACE_BEGIN(CryptoPP)
12
13/// \brief Null hash
14/// \details A null hash that conforms to HashTransformation interface
16{
17public:
18 void Update(const byte *input, size_t length)
19 {CRYPTOPP_UNUSED(input);CRYPTOPP_UNUSED(length);}
20 unsigned int DigestSize() const
21 {return 0;}
22 void TruncatedFinal(byte *digest, size_t digestSize)
23 {CRYPTOPP_UNUSED(digest);CRYPTOPP_UNUSED(digestSize);}
24 bool TruncatedVerify(const byte *digest, size_t digestLength)
25 {CRYPTOPP_UNUSED(digest);CRYPTOPP_UNUSED(digestLength);return true;}
26};
27
28/// \brief Construct new HashModule with smaller digest size from an existing one
29/// \tparam T HashTransformation derived class
30template <class T>
32{
33public:
34 /// \brief Construct a TruncatedHashTemplate
35 TruncatedHashTemplate(T hm, unsigned int digestSize)
36 : m_hm(hm), m_digestSize(digestSize) {}
37 /// \brief Construct a TruncatedHashTemplate
38 TruncatedHashTemplate(const byte *key, size_t keyLength, unsigned int digestSize)
39 : m_hm(key, keyLength), m_digestSize(digestSize) {}
40 /// \brief Construct a TruncatedHashTemplate
41 TruncatedHashTemplate(size_t digestSize)
42 : m_digestSize(digestSize) {}
43
44 void Restart()
45 {m_hm.Restart();}
46 void Update(const byte *input, size_t length)
47 {m_hm.Update(input, length);}
48 unsigned int DigestSize() const {return m_digestSize;}
49 void TruncatedFinal(byte *digest, size_t digestSize)
50 {m_hm.TruncatedFinal(digest, digestSize);}
51 bool TruncatedVerify(const byte *digest, size_t digestLength)
52 {return m_hm.TruncatedVerify(digest, digestLength);}
53
54private:
55 T m_hm;
56 unsigned int m_digestSize;
57};
58
60
61NAMESPACE_END
62
63#endif
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:1113
Null hash.
Definition: trunhash.h:16
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: trunhash.h:20
bool TruncatedVerify(const byte *digest, size_t digestLength)
Verifies the hash of the current message.
Definition: trunhash.h:24
void TruncatedFinal(byte *digest, size_t digestSize)
Computes the hash of the current message.
Definition: trunhash.h:22
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: trunhash.h:18
Construct new HashModule with smaller digest size from an existing one.
Definition: trunhash.h:32
void Restart()
Restart the hash.
Definition: trunhash.h:44
TruncatedHashTemplate(const byte *key, size_t keyLength, unsigned int digestSize)
Construct a TruncatedHashTemplate.
Definition: trunhash.h:38
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: trunhash.h:48
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: trunhash.h:46
TruncatedHashTemplate(size_t digestSize)
Construct a TruncatedHashTemplate.
Definition: trunhash.h:41
void TruncatedFinal(byte *digest, size_t digestSize)
Computes the hash of the current message.
Definition: trunhash.h:49
TruncatedHashTemplate(T hm, unsigned int digestSize)
Construct a TruncatedHashTemplate.
Definition: trunhash.h:35
bool TruncatedVerify(const byte *digest, size_t digestLength)
Verifies the hash of the current message.
Definition: trunhash.h:51
Abstract base classes that provide a uniform interface to this library.
Crypto++ library namespace.