00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(AFX_SHA_H__9CC84DD7_E62A_410F_BFE4_B6190C509ACE__INCLUDED_)
00023 #define AFX_SHA_H__9CC84DD7_E62A_410F_BFE4_B6190C509ACE__INCLUDED_
00024
00025 #pragma once
00026
00027 class CSHA
00028 {
00029
00030 public:
00031 CSHA();
00032 ~CSHA();
00033
00034
00035 public:
00036 DWORD m_nCount[2];
00037 DWORD m_nHash[5];
00038 DWORD m_nBuffer[16];
00039
00040
00041 public:
00042 void Reset();
00043 void Add(LPCVOID pData, DWORD nLength);
00044 void Finish();
00045 void GetHash(SHA1* pHash);
00046 CString GetHashString(BOOL bURN = FALSE);
00047 public:
00048 static CString HashToString(const SHA1* pHash, BOOL bURN = FALSE);
00049 static CString HashToHexString(const SHA1* pHash, BOOL bURN = FALSE);
00050 static BOOL HashFromString(LPCTSTR pszHash, SHA1* pHash);
00051 static BOOL HashFromURN(LPCTSTR pszHash, SHA1* pHash);
00052 static BOOL IsNull(SHA1* pHash);
00053 protected:
00054
00055 };
00056
00057 #define SHA1_BLOCK_SIZE 64
00058 #define SHA1_DIGEST_SIZE 20
00059
00060 inline bool operator==(const SHA1& sha1a, const SHA1& sha1b)
00061 {
00062 return memcmp( &sha1a, &sha1b, 20 ) == 0;
00063 }
00064
00065 inline bool operator!=(const SHA1& sha1a, const SHA1& sha1b)
00066 {
00067 return memcmp( &sha1a, &sha1b, 20 ) != 0;
00068 }
00069
00070 #endif // !defined(AFX_SHA_H__9CC84DD7_E62A_410F_BFE4_B6190C509ACE__INCLUDED_)