- Main Page
- Namespaces
- Classes
- Files

# trunhash.h

    00001 #ifndef CRYPTOPP_TRUNHASH_H
    00002 #define CRYPTOPP_TRUNHASH_H
    00003
    00004 #include "cryptlib.h"
    00005
    00006 NAMESPACE_BEGIN(CryptoPP)
    00007
    00008 class NullHash : public HashTransformation
    00009 {
    00010 public:
    00011         void Update(const byte *input, size_t length) {}
    00012         unsigned int DigestSize() const {return 0;}
    00013         void TruncatedFinal(byte *digest, size_t digestSize) {}
    00014         bool TruncatedVerify(const byte *digest, size_t digestLength) {return true;}
    00015 };
    00016
    00017 //! construct new HashModule with smaller DigestSize() from existing one
    00018 template <class T>
    00019 class TruncatedHashTemplate : public HashTransformation
    00020 {
    00021 public:
    00022         TruncatedHashTemplate(T hm, unsigned int digestSize)
    00023                 : m_hm(hm), m_digestSize(digestSize) {}
    00024         TruncatedHashTemplate(const byte *key, size_t keyLength, unsigned int digestSize)
    00025                 : m_hm(key, keyLength), m_digestSize(digestSize) {}
    00026         TruncatedHashTemplate(size_t digestSize)
    00027                 : m_digestSize(digestSize) {}
    00028
    00029         void Restart()
    00030                 {m_hm.Restart();}
    00031         void Update(const byte *input, size_t length)
    00032                 {m_hm.Update(input, length);}
    00033         unsigned int DigestSize() const {return m_digestSize;}
    00034         void TruncatedFinal(byte *digest, size_t digestSize)
    00035                 {m_hm.TruncatedFinal(digest, digestSize);}
    00036         bool TruncatedVerify(const byte *digest, size_t digestLength)
    00037                 {return m_hm.TruncatedVerify(digest, digestLength);}
    00038
    00039 private:
    00040         T m_hm;
    00041         unsigned int m_digestSize;
    00042 };
    00043
    00044 typedef TruncatedHashTemplate<HashTransformation &> TruncatedHashModule;
    00045
    00046 NAMESPACE_END
    00047
    00048 #endif