00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __PANA_SHA1_H__
00035 #define __PANA_SHA1_H__
00036
00037 #ifndef LITTLE_ENDIAN
00038 #define LITTLE_ENDIAN
00039 #endif // LITTLE_ENDIAN
00040
00041 class PANA_Sha1
00042 {
00043 public:
00047 PANA_Sha1();
00048
00052 virtual ~PANA_Sha1();
00053
00054
00055 #define ROL32(value, bits) (((value)<<(bits))|((value)>>(32-(bits))))
00056
00057 #ifdef LITTLE_ENDIAN
00058 #define SHABLK0(i) (m_block->l[i] = \
00059 (ROL32(m_block->l[i],24) & 0xFF00FF00) | (ROL32(m_block->l[i],8) & 0x00FF00FF))
00060 #else
00061 #define SHABLK0(i) (m_block->l[i])
00062 #endif
00063
00064 #define SHABLK(i) (m_block->l[i&15] = ROL32(m_block->l[(i+13)&15] ^ m_block->l[(i+8)&15] \
00065 ^ m_block->l[(i+2)&15] ^ m_block->l[i&15],1))
00066
00067
00068 #define R0(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK0(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
00069 #define R1(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
00070 #define R2(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0x6ED9EBA1+ROL32(v,5); w=ROL32(w,30); }
00071 #define R3(v,w,x,y,z,i) { z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5); w=ROL32(w,30); }
00072 #define R4(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5); w=ROL32(w,30); }
00073
00074 typedef union {
00075 unsigned char c[64];
00076 unsigned long l[16];
00077 } SHA1_WORKSPACE_BLOCK;
00078
00079
00080 enum {
00081 REPORT_HEX = 0,
00082 REPORT_DIGIT = 1
00083 };
00084
00085 unsigned long m_state[5];
00086 unsigned long m_count[2];
00087 unsigned char m_buffer[64];
00088 unsigned char m_digest[20];
00089
00093 void Reset();
00094
00101 void Update(unsigned char* data, unsigned int len);
00102
00106 void Final();
00107
00114 void ReportHash(char *report, unsigned char type = REPORT_HEX);
00115
00121 void GetHash(unsigned char *uDest);
00122
00123 private:
00127 void Transform(unsigned long state[5], unsigned char buffer[64]);
00128
00129 unsigned char m_workspace[64];
00131 SHA1_WORKSPACE_BLOCK* m_block;
00132 };
00133
00134 #endif // __PANA_SHA1_H__