/* ***** BEGIN LICENSE BLOCK ***** * Copyright (C) 2012-2014, Peter Hatina * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ***** END LICENSE BLOCK ***** */ #ifndef SHA1_HEADER #define SHA1_HEADER #include #include class SHA1 { public: SHA1(); void update(const std::string &s); void update(std::istream &is); std::string final(); static std::string sumString(const std::string &str); private: typedef unsigned long int uint32; /* just needs to be at least 32bit */ typedef unsigned long long uint64; /* just needs to be at least 64bit */ static const unsigned int DIGEST_INTS = 5; /* number of 32bit integers per SHA1 digest */ static const unsigned int BLOCK_INTS = 16; /* number of 32bit integers per SHA1 block */ static const unsigned int BLOCK_BYTES = BLOCK_INTS * 4; uint32 m_digest[DIGEST_INTS]; std::string m_buffer; uint64 m_transforms; void reset(); void transform(uint32 block[BLOCK_BYTES]); static void buffer_to_block(const std::string &buffer, uint32 block[BLOCK_BYTES]); static void read(std::istream &is, std::string &s, const int max); }; #endif