2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
20#ifndef DOXYGEN_SHOULD_SKIP_THIS
22#include "utils/sha1.h"
33#define SHA1_ROL(value, bits) (((value) << (bits)) | (((value) & 0xffffffff
) >> (32
- (bits))))
34#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
))
37#define SHA1_R0(v, w, x, y, z, i)
38 z += ((w & (x ^ y)) ^ y) + block[i] + 0x5a827999
+ SHA1_ROL(v, 5
);
40#define SHA1_R1(v, w, x, y, z, i)
43#define SHA1_R2(v, w, x, y, z, i)
46#define SHA1_R3(v, w, x, y, z, i)
49#define SHA1_R4(v, w, x, y, z, i)
58 std::istringstream is(s);
63 std::string rest_of_buffer;
76
77
84 buffer +=
static_cast<std::string::value_type>(0x80);
85 const std::size_t orig_size =
buffer.size();
87 buffer +=
static_cast<
char>(0x00);
95 for (
unsigned int i = 0; i <
BLOCK_INTS - 2; i++) {
101 block[
BLOCK_INTS - 1] =
static_cast<uint32_t>(total_bits & 0x00000000FFFFFFFF);
102 block[
BLOCK_INTS - 2] =
static_cast<uint32_t>((total_bits >> 32) & 0x00000000FFFFFFFF);
106 std::ostringstream result;
108 result << std::hex << std::setfill(
'0') << std::setw(8);
109 result << (
digest[i] & 0xffffffff);
132
133
238 for (
unsigned int i = 0; i <
BLOCK_INTS; i++) {
239 block[i] =
static_cast<uint32_t>((buffer[4 * i + 3] & 0xff) | (buffer[4 * i + 2] & 0xff) << 8 |
240 (buffer[4 * i + 1] & 0xff) << 16 | (buffer[4 * i + 0] & 0xff) << 24);
244 void SHA1::
read(std::istream& is, std::string& s, std::size_t max) {
245 char* sbuf =
new char[max];
246 is.read(sbuf,
static_cast<std::streamsize>(max));
247 s.assign(sbuf,
static_cast<
unsigned long>(is.gcount()));
252 std::vector<
unsigned char> buf;
257 for (std::size_t i = 0, j = 0; i < string.size(); i += 2, j += 1) {
258 hex_byte[0] = string.at(i);
259 hex_byte[1] = string.at(i + 1);
260 char* end_ptr =
nullptr;
261 buf.push_back(
static_cast<
unsigned char>(strtoul(hex_byte, &end_ptr, 16)));
267 std::vector<
unsigned char>
sha1(
const std::string& string) {
static const unsigned int BLOCK_INTS
uint32_t digest[DIGEST_INTS]
static const unsigned int BLOCK_BYTES
static const unsigned int DIGEST_INTS
void transform(uint32_t block[BLOCK_BYTES])
static void read(std::istream &is, std::string &s, std::size_t max)
void update(std::istream &is)
static void buffer_to_block(const std::string &buffer, uint32_t block[BLOCK_BYTES])
void update(const std::string &s)
std::vector< unsigned char > sha1(const std::string &string)
static std::vector< unsigned char > transform_to_binary(const std::string &string)
#define SHA1_ROL(value, bits)
#define SHA1_R2(v, w, x, y, z, i)
#define SHA1_R3(v, w, x, y, z, i)
#define SHA1_R4(v, w, x, y, z, i)
#define SHA1_R1(v, w, x, y, z, i)
#define SHA1_R0(v, w, x, y, z, i)