SHA1.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #ifndef ___SHA1_HDR___
00029 #define ___SHA1_HDR___
00030
00031 #include <omnetpp.h>
00032
00033 #if !defined(SHA1_UTILITY_FUNCTIONS) && !defined(SHA1_NO_UTILITY_FUNCTIONS)
00034 #define SHA1_UTILITY_FUNCTIONS
00035 #endif
00036
00037 #include <memory.h>
00038
00039 #ifdef SHA1_UTILITY_FUNCTIONS
00040 #include <stdio.h>
00041 #include <string.h>
00042 #endif
00043
00044 #ifdef _MSC_VER
00045 #include <stdlib.h>
00046 #endif
00047
00048
00049
00050
00051
00052
00053 #if !defined(SHA1_LITTLE_ENDIAN) && !defined(SHA1_BIG_ENDIAN)
00054 #define SHA1_LITTLE_ENDIAN
00055 #endif
00056
00057
00058
00059
00060
00061 #if !defined(SHA1_WIPE_VARIABLES) && !defined(SHA1_NO_WIPE_VARIABLES)
00062 #define SHA1_WIPE_VARIABLES
00063 #endif
00064
00066
00067
00068 #ifndef UINT_32
00069
00070 #ifdef _MSC_VER
00071
00072 #define UINT_8 unsigned __int8
00073 #define UINT_32 unsigned __int32
00074
00075 #else
00076
00077 #define UINT_8 unsigned char
00078
00079 #if (ULONG_MAX == 0xFFFFFFFF)
00080 #define UINT_32 unsigned long
00081 #else
00082 #define UINT_32 unsigned int
00083 #endif
00084
00085 #endif
00086 #endif
00087
00089
00090
00091 typedef union
00092 {
00093 UINT_8 c[64];
00094 UINT_32 l[16];
00095 } SHA1_WORKSPACE_BLOCK;
00096
00097 class CSHA1
00098 {
00099 public:
00100 #ifdef SHA1_UTILITY_FUNCTIONS
00101
00102 enum
00103 {
00104 REPORT_HEX = 0,
00105 REPORT_DIGIT = 1
00106 };
00107 #endif
00108
00109
00110 CSHA1();
00111 ~CSHA1();
00112
00113 UINT_32 m_state[5];
00114 UINT_32 m_count[2];
00115 UINT_32 __reserved1[1];
00116 UINT_8 m_buffer[64];
00117 UINT_8 m_digest[20];
00118 UINT_32 __reserved2[3];
00119
00120 void Reset();
00121
00122
00123 void Update(UINT_8 *data, UINT_32 len);
00124 #ifdef SHA1_UTILITY_FUNCTIONS
00125
00126 bool HashFile(char *szFileName);
00127 #endif
00128
00129
00130 void Final();
00131
00132
00133 #ifdef SHA1_UTILITY_FUNCTIONS
00134
00135 void ReportHash(char *szReport, unsigned char uReportType = REPORT_HEX);
00136 #endif
00137
00138 void GetHash(UINT_8 *puDest);
00139
00140 private:
00141
00142 void Transform(UINT_32 *state, UINT_8 *buffer);
00143
00144
00145 UINT_8 m_workspace[64];
00146 SHA1_WORKSPACE_BLOCK *m_block;
00147 };
00148
00149 #endif