sha1transform.h

Go to the documentation of this file.
00001 /**
00002  *  \file sha1transform.h
00003  *
00004  *      This is the header file for code which implements the Secure
00005  *      Hashing Algorithm 1 as defined in FIPS PUB 180-1 published
00006  *      April 17, 1995.
00007  *
00008  *      Many of the variable names in this code, especially the
00009  *      single character names, were used because those were the names
00010  *      used in the publication.
00011  *
00012  *      Please read the file sha1transform.cpp for more information.
00013  *
00014  */
00015 
00016 #ifndef __SHA1TRANSFORM_H__
00017 #define __SHA1TRANSFORM_H__
00018 
00019 #include <hn/hash.h>
00020 
00021 #define SHA1HashSize 20
00022 enum
00023 {
00024     shaSuccess = 0,
00025     shaNull,            //!< Null pointer parameter
00026     shaInputTooLong,    //!< input data too long
00027     shaStateError       //!< called Input after Result
00028 };
00029 
00030 /**
00031  * Perform SHA-1 Checksumming on data
00032  */
00033 class DLLEXPORT Sha1Transform {
00034 public:
00035         //! Constructor
00036         Sha1Transform();
00037 
00038         //! Destructor
00039         ~Sha1Transform();
00040 
00041         //! Checksum data
00042         int sumUp(const char *data, uint32_t length);
00043 
00044         //! Checksum data
00045         int sumUp(const unsigned char *data, uint32_t length);
00046 
00047         //! Retrieve results. Note that this object should be destroyed
00048         //! after retrieving hash - continueing to calculate hash will result
00049         //! in abnormal program termination (in debug mode).
00050         Hash<SHA1Hash> getHash();
00051 private:
00052         //! Message Digest
00053         uint32_t Intermediate_Hash[SHA1HashSize/4];
00054 
00055         //! Message length in bits
00056         uint32_t Length_Low;
00057 
00058         //! Message length in bits
00059         uint32_t Length_High;
00060 
00061         //! Index into message block array
00062         int Message_Block_Index;
00063 
00064         //! 512-bit message blocks
00065         uint8_t Message_Block[64];
00066 
00067         //! Is the digest computed?
00068         int Computed;
00069 
00070         //! Is the message digest corrupted?
00071         int Corrupted;
00072 
00073         void SHA1ProcessMessageBlock();
00074         void SHA1PadMessage();
00075 };
00076 
00077 #endif