26 #define SHA1_ROL(value, bits) (((value) << (bits)) | (((value) & 0xffffffff) >> (32 - (bits))))
27 #define SHA1_BLK(i) (block[i&15] = SHA1_ROL(block[(i+13)&15] ^ block[(i+8)&15] ^ block[(i+2)&15] ^ block[i&15],1))
30 #define SHA1_R0(v,w,x,y,z,i) z += ((w&(x^y))^y) + block[i] + 0x5a827999 + SHA1_ROL(v,5); w=SHA1_ROL(w,30);
31 #define SHA1_R1(v,w,x,y,z,i) z += ((w&(x^y))^y) + SHA1_BLK(i) + 0x5a827999 + SHA1_ROL(v,5); w=SHA1_ROL(w,30);
32 #define SHA1_R2(v,w,x,y,z,i) z += (w^x^y) + SHA1_BLK(i) + 0x6ed9eba1 + SHA1_ROL(v,5); w=SHA1_ROL(w,30);
33 #define SHA1_R3(v,w,x,y,z,i) z += (((w|x)&y)|(w&x)) + SHA1_BLK(i) + 0x8f1bbcdc + SHA1_ROL(v,5); w=SHA1_ROL(w,30);
34 #define SHA1_R4(v,w,x,y,z,i) z += (w^x^y) + SHA1_BLK(i) + 0xca62c1d6 + SHA1_ROL(v,5); w=SHA1_ROL(w,30);
44 std::istringstream is(s);
51 std::string rest_of_buffer;
76 unsigned int orig_size =
buffer.size();
88 for (
unsigned int i = 0; i <
BLOCK_INTS - 2; i++)
100 std::ostringstream result;
103 result << std::hex << std::setfill(
'0') << std::setw(8);
104 result << (
digest[i] & 0xffffffff);
116 std::ifstream stream(filename.c_str(), std::ios::binary);
119 return checksum.final();
251 block[i] = (buffer[4*i+3] & 0xff)
252 | (buffer[4*i+2] & 0xff)<<8
253 | (buffer[4*i+1] & 0xff)<<16
254 | (buffer[4*i+0] & 0xff)<<24;
259 void SHA1::read(std::istream &is, std::string &s,
size_t max)
261 char* sbuf =
new char[max];
264 s.assign(sbuf, is.gcount());
270 std::string
sha1(
const std::string &
string)
274 return checksum.
final();
#define SHA1_R4(v, w, x, y, z, i)
void transform(uint32_t block[BLOCK_BYTES])
static void read(std::istream &is, std::string &s, size_t max)
uint32_t digest[DIGEST_INTS]
#define SHA1_R1(v, w, x, y, z, i)
static const unsigned int BLOCK_INTS
static const unsigned int DIGEST_INTS
static std::string from_file(const std::string &filename)
std::string sha1(const std::string &string)
static const unsigned int BLOCK_BYTES
#define SHA1_R0(v, w, x, y, z, i)
static void buffer_to_block(const std::string &buffer, uint32_t block[BLOCK_INTS])
#define SHA1_R2(v, w, x, y, z, i)
void update(const std::string &s)
#define SHA1_R3(v, w, x, y, z, i)