1
2
3
4
5
6 #ifndef SOULNG_UTIL_SHA1_INCLUDED
7 #define SOULNG_UTIL_SHA1_INCLUDED
8 #include <soulng/util/UtilApi.hpp>
9 #include <stdint.h>
10 #include <string>
11
12 namespace soulng { namespace util {
13
14 class Sha1
15 {
16 public:
17 Sha1();
18 void Reset();
19 void Process(uint8_t x)
20 {
21 ProcessByte(x);
22 bitCount = bitCount + 8u;
23 }
24 void Process(void* begin, void* end);
25 void Process(void* buf, int count)
26 {
27 uint8_t* b = static_cast<uint8_t*>(buf);
28 Process(b, b + count);
29 }
30 std::string GetDigest();
31 private:
32 void ProcessByte(uint8_t x)
33 {
34 block[byteIndex++] = x;
35 if (byteIndex == 64u)
36 {
37 byteIndex = 0u;
38 ProcessBlock();
39 }
40 }
41 void ProcessBlock();
42 uint32_t digest[5];
43 uint8_t block[64];
44 uint8_t byteIndex;
45 uint64_t bitCount;
46 };
47
48 std::string GetSha1MessageDigest(const std::string& message);
49
50 } }
51
52 #endif // SOULNG_UTIL_SHA1_INCLUDED