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 #ifndef ___SHA1_H___
00019 #define ___SHA1_H___
00020
00021 #include "RakMemoryOverride.h"
00022 #include <stdio.h>
00023 #if !defined(_PS3) && !defined(__PS3__) && !defined(SN_TARGET_PS3)
00024 #include <memory.h>
00025 #endif
00026 #include <string.h>
00027 #include "Export.h"
00028
00029 #define MAX_FILE_READ_BUFFER 8000
00030
00031 #define SHA1_LENGTH 20
00032
00033 class RAK_DLL_EXPORT CSHA1
00034 {
00035
00036 public:
00037
00038 #define ROL32(value, bits) (((value)<<(bits))|((value)>>(32-(bits))))
00039
00040 #ifdef LITTLE_ENDIAN
00041 #define SHABLK0(i) (block->l[i] = (ROL32(block->l[i],24) & 0xFF00FF00) \
00042 | (ROL32(block->l[i],8) & 0x00FF00FF))
00043 #else
00044 #define SHABLK0(i) (block->l[i])
00045 #endif
00046
00047 #define SHABLK(i) (block->l[i&15] = ROL32(block->l[(i+13)&15] ^ block->l[(i+8)&15] \
00048 ^ block->l[(i+2)&15] ^ block->l[i&15],1))
00049
00050
00051 #define R0(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK0(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
00052 #define R1(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
00053 #define R2(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0x6ED9EBA1+ROL32(v,5); w=ROL32(w,30); }
00054 #define R3(v,w,x,y,z,i) { z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5); w=ROL32(w,30); }
00055 #define R4(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5); w=ROL32(w,30); }
00056
00057 typedef union {
00058 unsigned char c[ 64 ];
00059 unsigned int l[ 16 ];
00060 } SHA1_WORKSPACE_BLOCK;
00061
00062
00063 enum { REPORT_HEX = 0,
00064 REPORT_DIGIT = 1};
00065
00066 CSHA1();
00067 virtual ~CSHA1();
00068
00069 unsigned int m_state[ 5 ];
00070 unsigned int m_count[ 2 ];
00071 unsigned char m_buffer[ 64 ];
00072 unsigned char m_digest[ 20 ];
00073 void Reset();
00074 void Update( unsigned char* data, unsigned int len );
00075 bool HashFile( char *szFileName );
00076 void Final();
00077 void ReportHash( char *szReport, unsigned char uReportType = REPORT_HEX );
00078 void GetHash( unsigned char *uDest );
00079 unsigned char * GetHash( void ) const;
00080
00081 private:
00082 void Transform( unsigned int state[ 5 ], unsigned char buffer[ 64 ] );
00083 unsigned char workspace[ 64 ];
00084 };
00085
00086 #endif // ___SHA1_H___
00087