Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:10

0001 // trunhash.h - originally written and placed in the public domain by Wei Dai

0002 
0003 /// \file trunhash.h

0004 /// \brief Classes for truncated hashes

0005 
0006 #ifndef CRYPTOPP_TRUNHASH_H
0007 #define CRYPTOPP_TRUNHASH_H
0008 
0009 #include "cryptlib.h"
0010 
0011 NAMESPACE_BEGIN(CryptoPP)
0012 
0013 /// \brief Null hash

0014 /// \details A null hash that conforms to HashTransformation interface

0015 class NullHash : public HashTransformation
0016 {
0017 public:
0018     void Update(const byte *input, size_t length)
0019         {CRYPTOPP_UNUSED(input);CRYPTOPP_UNUSED(length);}
0020     unsigned int DigestSize() const
0021         {return 0;}
0022     void TruncatedFinal(byte *digest, size_t digestSize)
0023         {CRYPTOPP_UNUSED(digest);CRYPTOPP_UNUSED(digestSize);}
0024     bool TruncatedVerify(const byte *digest, size_t digestLength)
0025         {CRYPTOPP_UNUSED(digest);CRYPTOPP_UNUSED(digestLength);return true;}
0026 };
0027 
0028 /// \brief Construct new HashModule with smaller digest size from an existing one

0029 /// \tparam T HashTransformation derived class

0030 template <class T>
0031 class TruncatedHashTemplate : public HashTransformation
0032 {
0033 public:
0034     /// \brief Construct a TruncatedHashTemplate

0035     TruncatedHashTemplate(T hm, unsigned int digestSize)
0036         : m_hm(hm), m_digestSize(digestSize) {}
0037     /// \brief Construct a TruncatedHashTemplate

0038     TruncatedHashTemplate(const byte *key, size_t keyLength, unsigned int digestSize)
0039         : m_hm(key, keyLength), m_digestSize(digestSize) {}
0040     /// \brief Construct a TruncatedHashTemplate

0041     TruncatedHashTemplate(size_t digestSize)
0042         : m_digestSize(digestSize) {}
0043 
0044     void Restart()
0045         {m_hm.Restart();}
0046     void Update(const byte *input, size_t length)
0047         {m_hm.Update(input, length);}
0048     unsigned int DigestSize() const {return m_digestSize;}
0049     void TruncatedFinal(byte *digest, size_t digestSize)
0050         {m_hm.TruncatedFinal(digest, digestSize);}
0051     bool TruncatedVerify(const byte *digest, size_t digestLength)
0052         {return m_hm.TruncatedVerify(digest, digestLength);}
0053 
0054 private:
0055     T m_hm;
0056     unsigned int m_digestSize;
0057 };
0058 
0059 typedef TruncatedHashTemplate<HashTransformation &> TruncatedHashModule;
0060 
0061 NAMESPACE_END
0062 
0063 #endif