23 #ifndef ICL_CORE_CRYPT_SHA2_HPP_INCLUDED 24 #define ICL_CORE_CRYPT_SHA2_HPP_INCLUDED 33 #define TEMPLATEM template <typename T, T t_h0, T t_h1, T t_h2, T t_h3, T t_h4, T t_h5, T t_h6, T t_h7, size_t t_len> 34 #define CLASSM Sha2<T, t_h0, t_h1, t_h2, t_h3, t_h4, t_h5, t_h6, t_h7, t_len> 35 #define IMPLM Sha2Impl<T, t_h0, t_h1, t_h2, t_h3, t_h4, t_h5, t_h6, t_h7, t_len> 44 CLASSM& CLASSM::process(
const char *data)
46 for (; *data != 0; ++data)
48 if (m_buffer_fill == cMESSAGE_BLOCK_SIZE)
53 m_buffer[m_buffer_fill++] = *data;
60 CLASSM& CLASSM::process(
const void *data,
size_t size)
66 while (rest >= cMESSAGE_BLOCK_SIZE-m_buffer_fill)
68 size_t amount = cMESSAGE_BLOCK_SIZE-m_buffer_fill;
69 ::memcpy(&m_buffer[m_buffer_fill], ptr, amount);
73 m_message_size += amount;
77 ::memcpy(&m_buffer[m_buffer_fill], ptr, rest);
78 m_message_size += rest;
79 m_buffer_fill += rest;
86 finalizeBuffer(m_buffer_fill);
90 #define bswap64(i) ((i) >> 56 | \ 91 (((i) >> 40) & 0x000000000000ff00ull) | \ 92 (((i) >> 24) & 0x0000000000ff0000ull) | \ 93 (((i) >> 8) & 0x00000000ff000000ull) | \ 94 (((i) << 8) & 0x000000ff00000000ull) | \ 95 (((i) << 24) & 0x0000ff0000000000ull) | \ 96 (((i) << 40) & 0x00ff000000000000ull) | \ 100 void CLASSM::finalizeBuffer(
size_t size)
102 uint64_t message_size_bits = m_message_size*8;
105 if (size < cMESSAGE_BLOCK_SIZE)
107 m_buffer[size++] = 0x80;
118 if (size <= cMESSAGE_PAD_POSITION)
120 for (
size_t i = size; i < cMESSAGE_BLOCK_SIZE-8; ++i)
124 m_buffer[cMESSAGE_BLOCK_SIZE-8] =
uint8_t((message_size_bits >> 56) & 0xff);
125 m_buffer[cMESSAGE_BLOCK_SIZE-7] =
uint8_t((message_size_bits >> 48) & 0xff);
126 m_buffer[cMESSAGE_BLOCK_SIZE-6] =
uint8_t((message_size_bits >> 40) & 0xff);
127 m_buffer[cMESSAGE_BLOCK_SIZE-5] =
uint8_t((message_size_bits >> 32) & 0xff);
128 m_buffer[cMESSAGE_BLOCK_SIZE-4] =
uint8_t((message_size_bits >> 24) & 0xff);
129 m_buffer[cMESSAGE_BLOCK_SIZE-3] =
uint8_t((message_size_bits >> 16) & 0xff);
130 m_buffer[cMESSAGE_BLOCK_SIZE-2] =
uint8_t((message_size_bits >> 8) & 0xff);
131 m_buffer[cMESSAGE_BLOCK_SIZE-1] =
uint8_t((message_size_bits ) & 0xff);
138 for (
size_t i = size; i < cMESSAGE_BLOCK_SIZE; ++i)
145 for (
size_t i = 0; i < cMESSAGE_BLOCK_SIZE-8; ++i)
149 m_buffer[cMESSAGE_BLOCK_SIZE-8] =
uint8_t((message_size_bits >> 56) & 0xff);
150 m_buffer[cMESSAGE_BLOCK_SIZE-7] =
uint8_t((message_size_bits >> 48) & 0xff);
151 m_buffer[cMESSAGE_BLOCK_SIZE-6] =
uint8_t((message_size_bits >> 40) & 0xff);
152 m_buffer[cMESSAGE_BLOCK_SIZE-5] =
uint8_t((message_size_bits >> 32) & 0xff);
153 m_buffer[cMESSAGE_BLOCK_SIZE-4] =
uint8_t((message_size_bits >> 24) & 0xff);
154 m_buffer[cMESSAGE_BLOCK_SIZE-3] =
uint8_t((message_size_bits >> 16) & 0xff);
155 m_buffer[cMESSAGE_BLOCK_SIZE-2] =
uint8_t((message_size_bits >> 8) & 0xff);
156 m_buffer[cMESSAGE_BLOCK_SIZE-1] =
uint8_t((message_size_bits ) & 0xff);
void * memcpy(void *dest, void *src, size_t count)
unsigned __int64 uint64_t