CMSDK  2.0.1
sha1.h
1 // //////////////////////////////////////////////////////////
2 // sha1.h
3 // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved.
4 // see http://create.stephan-brumme.com/disclaimer.html
5 //
6 
7 #pragma once
8 
9 //#include "hash.h"
10 #include <string>
11 
12 // define fixed size integer types
13 #ifdef _MSC_VER
14 // Windows
15 typedef unsigned __int8 uint8_t;
16 typedef unsigned __int32 uint32_t;
17 typedef unsigned __int64 uint64_t;
18 #else
19 // GCC
20 #include <stdint.h>
21 #endif
22 
23 
25 
37 class SHA1 //: public Hash
38 {
39 public:
41  enum { BlockSize = 512 / 8, HashBytes = 20 };
42 
44  SHA1();
45 
47  std::string operator()(const void* data, size_t numBytes);
49  std::string operator()(const std::string& text);
50 
52  void add(const void* data, size_t numBytes);
53 
55  std::string getHash();
57  void getHash(unsigned char buffer[HashBytes]);
58 
60  void reset();
61 
62 private:
64  void processBlock(const void* data);
66  void processBuffer();
67 
69  uint64_t m_numBytes;
71  size_t m_bufferSize;
73  uint8_t m_buffer[BlockSize];
74 
75  enum { HashValues = HashBytes / 4 };
77  uint32_t m_hash[HashValues];
78 };
std::string getHash()
return latest hash as 40 hex characters
Definition: sha1.cpp:266
void add(const void *data, size_t numBytes)
add arbitrary number of bytes
Definition: sha1.cpp:156
std::string operator()(const void *data, size_t numBytes)
compute SHA1 of a memory block
Definition: sha1.cpp:312
compute SHA1 hash
Definition: sha1.h:37
void reset()
restart
Definition: sha1.cpp:23
SHA1()
same as reset()
Definition: sha1.cpp:16