00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef ___SHA1_HDR___
00025 #define ___SHA1_HDR___
00026
00027 #if !defined(SHA1_UTILITY_FUNCTIONS) && !defined(SHA1_NO_UTILITY_FUNCTIONS)
00028 #define SHA1_UTILITY_FUNCTIONS
00029 #endif
00030
00031 #include <memory.h>
00032 #include <boost/cstdint.hpp>
00033
00034 #ifdef SHA1_UTILITY_FUNCTIONS
00035 #include <stdio.h>
00036 #include <string.h>
00037 #endif
00038
00039
00040
00041
00042
00043
00044
00045 #if !defined(SHA1_LITTLE_ENDIAN) && !defined(SHA1_BIG_ENDIAN)
00046 #define SHA1_LITTLE_ENDIAN
00047 #endif
00048
00049
00050
00051
00052
00053 #if !defined(SHA1_WIPE_VARIABLES) && !defined(SHA1_NO_WIPE_VARIABLES)
00054 #define SHA1_WIPE_VARIABLES
00055 #endif
00056
00058
00059
00060 #define UINT_8 uint8_t
00061 #define UINT_32 uint32_t
00062
00064
00065
00066 typedef union
00067 {
00068 UINT_8 c[64];
00069 UINT_32 l[16];
00070 } SHA1_WORKSPACE_BLOCK;
00071
00072 class CSHA1
00073 {
00074 public:
00075 #ifdef SHA1_UTILITY_FUNCTIONS
00076
00077 enum
00078 {
00079 REPORT_HEX = 0,
00080 REPORT_DIGIT = 1
00081 };
00082 #endif
00083
00084
00085 CSHA1();
00086 ~CSHA1();
00087
00088 UINT_32 m_state[5];
00089 UINT_32 m_count[2];
00090 UINT_32 __reserved1[1];
00091 UINT_8 m_buffer[64];
00092 UINT_8 m_digest[20];
00093 UINT_32 __reserved2[3];
00094
00095 void Reset();
00096
00097
00098 void Update(UINT_8 *data, UINT_32 len);
00099 #ifdef SHA1_UTILITY_FUNCTIONS
00100
00101 bool HashFile(char *szFileName);
00102 #endif
00103
00104
00105 void Final();
00106
00107
00108 #ifdef SHA1_UTILITY_FUNCTIONS
00109
00110 void ReportHash(char *szReport, unsigned char uReportType = REPORT_HEX);
00111 #endif
00112
00113 void GetHash(UINT_8 *puDest);
00114
00115 private:
00116
00117 void Transform(UINT_32 *state, UINT_8 *buffer);
00118
00119
00120 UINT_8 m_workspace[64];
00121 SHA1_WORKSPACE_BLOCK *m_block;
00122 };
00123
00124 #endif