Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# 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, unsigned int length) {}
    00012         unsigned int DigestSize() const {return 0;}
    00013         void TruncatedFinal(byte *digest, unsigned int digestSize) {}
    00014         bool TruncatedVerify(const byte *digest, unsigned int 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, unsigned int keyLength, unsigned int digestSize)
    00025                 : m_hm(key, keyLength), m_digestSize(digestSize) {}
    00026         TruncatedHashTemplate(unsigned int digestSize)
    00027                 : m_digestSize(digestSize) {}
    00028
    00029         void Update(const byte *input, unsigned int length)
    00030                 {m_hm.Update(input, length);}
    00031         unsigned int DigestSize() const {return m_digestSize;}
    00032         void TruncatedFinal(byte *digest, unsigned int digestSize)
    00033                 {m_hm.TruncatedFinal(digest, digestSize);}
    00034         bool TruncatedVerify(const byte *digest, unsigned int digestLength)
    00035                 {return m_hm.TruncatedVerify(digest, digestLength);}
    00036
    00037 private:
    00038         T m_hm;
    00039         unsigned int m_digestSize;
    00040 };
    00041
    00042 typedef TruncatedHashTemplate<HashTransformation &> TruncatedHashModule;
    00043
    00044 NAMESPACE_END
    00045
    00046 #endif