#define SHA1_API #include "SHA1.h" #include namespace CryptoCPP { namespace SHA1 { SHA1_API char * digest(char * data, size_t data_size) { // Initialize buffers unsigned int h0 = 0x67452301; unsigned int h1 = 0xEFCDAB89; unsigned int h2 = 0x98BADCFE; unsigned int h3 = 0x10325476; unsigned int h4 = 0xC3D2E1F0; // Pad message size_t ml = data_size + 1; size_t full_size = ml + ((960 - (ml * 8 % 512)) % 512) / 8 + 8; char * msg = new char[full_size]; memcpy(msg, data, data_size); memset(msg + data_size, 0, full_size - data_size); msg[data_size] = 0x80; size_t len = data_size * 8; for (int i = 0; i < 8; ++i) msg[full_size - 1 - i] = (len >> (i * 8)) & 255; unsigned int chunks = full_size / 64; // Perform hashing for each 512-bit block for (size_t i = 0; i> (32 - by)); } SHA1_API void write_reverse_endian(char* to, unsigned int value, size_t offset) { for (size_t t = 0; t < 4; ++t) to[offset + 4 - t] = (value >> (t * 8)) & 255; } } }