sha1.h (1416B)
1 /* 2 sha1.h - header of 3 4 ============ 5 SHA-1 in C++ 6 ============ 7 8 100% Public Domain. 9 10 Original C Code 11 -- Steve Reid <steve@edmweb.com> 12 Small changes to fit into bglibs 13 -- Bruce Guenter <bruce@untroubled.org> 14 Translation to simpler C++ Code 15 -- Volker Grabsch <vog@notjusthosting.com> 16 */ 17 18 #ifndef SHA1_HPP 19 #define SHA1_HPP 20 21 22 #include <iostream> 23 #include <string> 24 25 class SHA1 26 { 27 public: 28 SHA1(); 29 void update(const std::string &s); 30 void update(std::istream &is); 31 std::string final(); 32 static std::string from_file(const std::string &filename); 33 34 private: 35 typedef unsigned long int uint32; /* just needs to be at least 32bit */ 36 typedef unsigned long long uint64; /* just needs to be at least 64bit */ 37 38 static const unsigned int DIGEST_INTS = 5; /* number of 32bit integers per SHA1 digest */ 39 static const unsigned int BLOCK_INTS = 16; /* number of 32bit integers per SHA1 block */ 40 static const unsigned int BLOCK_BYTES = BLOCK_INTS * 4; 41 42 uint32 digest[DIGEST_INTS]; 43 std::string buffer; 44 uint64 transforms; 45 46 void reset(); 47 void transform(uint32 block[BLOCK_BYTES]); 48 49 static void buffer_to_block(const std::string &buffer, uint32 block[BLOCK_BYTES]); 50 static void read(std::istream &is, std::string &s, int max); 51 }; 52 53 std::string sha1(const std::string &string); 54 55 56 57 #endif /* SHA1_HPP */