5#ifndef DIGESTPP_PROVIDERS_SHA1_HPP
6#define DIGESTPP_PROVIDERS_SHA1_HPP
19namespace sha1_functions
21 static inline uint32_t
Ch(uint32_t x, uint32_t y, uint32_t z)
23 return (x & y) ^ (~x & z);
26 static inline uint32_t
Parity(uint32_t x, uint32_t y, uint32_t z)
31 static inline uint32_t
Maj(uint32_t x, uint32_t y, uint32_t z)
33 return (x & y) ^ (x & z) ^ (y & z);
62 inline void update(
const unsigned char* data,
size_t len)
65 [
this](
const unsigned char* data,
size_t len) { transform(data, len); });
68 inline void final(
unsigned char*
hash)
74 memset(&m[pos], 0, 64 - pos);
78 memset(&m[0] + pos, 0, 56 - pos);
80 memcpy(&m[0] + (64 - 8), &mlen, 64 / 8);
82 for (
int i = 0; i < 5; i++)
84 memcpy(
hash, H.data(), 160/8);
96 inline void transform(
const unsigned char* data,
size_t num_blks)
98 for (uint64_t blk = 0; blk < num_blks; blk++)
101 for (uint32_t i = 0; i < 64 / 4; i++)
102 M[i] =
byteswap((
reinterpret_cast<const uint32_t*
>(data)[blk * 16 + i]));
105 for (
int t = 0; t <= 15; t++)
107 for (
int t = 16; t <= 79; t++)
108 W[t] =
rotate_left(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
118 for (
int t = 0; t <= 79; t++)
120 uint32_t T =
rotate_left(a, 5) + f(b, c, d) + e + K + W[t];
152 std::array<uint32_t, 5> H;
153 std::array<unsigned char, 64> m;
Definition sha1_provider.hpp:38
sha1_provider()
Definition sha1_provider.hpp:42
~sha1_provider()
Definition sha1_provider.hpp:46
void init()
Definition sha1_provider.hpp:51
void update(const unsigned char *data, size_t len)
Definition sha1_provider.hpp:62
size_t hash_size() const
Definition sha1_provider.hpp:93
void clear()
Definition sha1_provider.hpp:87
static uint32_t Maj(uint32_t x, uint32_t y, uint32_t z)
Definition sha1_provider.hpp:31
static uint32_t Ch(uint32_t x, uint32_t y, uint32_t z)
Definition sha1_provider.hpp:21
static uint32_t Parity(uint32_t x, uint32_t y, uint32_t z)
Definition sha1_provider.hpp:26
uint16_t byteswap(uint16_t val)
Definition functions.hpp:16
uint32_t rotate_left(uint32_t x, unsigned n)
Definition functions.hpp:67
void zero_memory(void *v, size_t n)
Definition functions.hpp:85
void absorb_bytes(const unsigned char *data, size_t len, size_t bs, size_t bschk, unsigned char *m, size_t &pos, T &total, TF transform)
Definition absorb_data.hpp:16
digestpp namespace
Definition ascon.hpp:14
Definition sha1_constants.hpp:16
static const uint32_t K[4]
Definition sha1_constants.hpp:17