22 #ifndef VIENNACL_TOOLS_SHA1_HPP_
23 #define VIENNACL_TOOLS_SHA1_HPP_
58 return (value << count) ^ (value >> (32-count));
64 memcpy(m_digest, s.m_digest, 5 *
sizeof(uint32_t));
65 memcpy(m_block, s.m_block, 64);
66 m_blockByteIndex = s.m_blockByteIndex;
67 m_byteCount = s.m_byteCount;
71 m_digest[0] = 0x67452301;
72 m_digest[1] = 0xEFCDAB89;
73 m_digest[2] = 0x98BADCFE;
74 m_digest[3] = 0x10325476;
75 m_digest[4] = 0xC3D2E1F0;
81 this->m_block[this->m_blockByteIndex++] = octet;
83 if (m_blockByteIndex == 64) {
84 this->m_blockByteIndex = 0;
90 const uint8_t* begin =
static_cast<const uint8_t*
>(
start);
91 const uint8_t*
finish =
static_cast<const uint8_t*
>(end);
92 while (begin != finish) {
99 const uint8_t* block =
static_cast<const uint8_t*
>(data);
106 if (this->m_blockByteIndex > 56) {
107 while (m_blockByteIndex != 0) {
110 while (m_blockByteIndex < 56) {
114 while (m_blockByteIndex < 56) {
122 processByte( static_cast<unsigned char>((bitCount>>24) & 0xFF));
123 processByte( static_cast<unsigned char>((bitCount>>16) & 0xFF));
124 processByte( static_cast<unsigned char>((bitCount>>8 ) & 0xFF));
125 processByte( static_cast<unsigned char>((bitCount) & 0xFF));
127 memcpy(digest, m_digest, 5 *
sizeof(uint32_t));
134 digest[di++] =
static_cast<uint8_t
>((d32[0] >> 24) & 0xFF);
135 digest[di++] =
static_cast<uint8_t
>((d32[0] >> 16) & 0xFF);
136 digest[di++] =
static_cast<uint8_t
>((d32[0] >> 8) & 0xFF);
137 digest[di++] =
static_cast<uint8_t
>((d32[0]) & 0xFF);
139 digest[di++] =
static_cast<uint8_t
>((d32[1] >> 24) & 0xFF);
140 digest[di++] =
static_cast<uint8_t
>((d32[1] >> 16) & 0xFF);
141 digest[di++] =
static_cast<uint8_t
>((d32[1] >> 8) & 0xFF);
142 digest[di++] =
static_cast<uint8_t
>((d32[1]) & 0xFF);
144 digest[di++] =
static_cast<uint8_t
>((d32[2] >> 24) & 0xFF);
145 digest[di++] =
static_cast<uint8_t
>((d32[2] >> 16) & 0xFF);
146 digest[di++] =
static_cast<uint8_t
>((d32[2] >> 8) & 0xFF);
147 digest[di++] =
static_cast<uint8_t
>((d32[2]) & 0xFF);
149 digest[di++] =
static_cast<uint8_t
>((d32[3] >> 24) & 0xFF);
150 digest[di++] =
static_cast<uint8_t
>((d32[3] >> 16) & 0xFF);
151 digest[di++] =
static_cast<uint8_t
>((d32[3] >> 8) & 0xFF);
152 digest[di++] =
static_cast<uint8_t
>((d32[3]) & 0xFF);
154 digest[di++] =
static_cast<uint8_t
>((d32[4] >> 24) & 0xFF);
155 digest[di++] =
static_cast<uint8_t
>((d32[4] >> 16) & 0xFF);
156 digest[di++] =
static_cast<uint8_t
>((d32[4] >> 8) & 0xFF);
157 digest[di++] =
static_cast<uint8_t
>((d32[4]) & 0xFF);
165 w[i] =
static_cast<uint32_t
>(m_block[i*4 + 0] << 24);
166 w[i] |=
static_cast<uint32_t
>(m_block[i*4 + 1] << 16);
167 w[i] |=
static_cast<uint32_t
>(m_block[i*4 + 2] << 8);
168 w[i] |=
static_cast<uint32_t
>(m_block[i*4 + 3]);
171 w[i] =
LeftRotate((w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16]), 1);
174 uint32_t a = m_digest[0];
175 uint32_t b = m_digest[1];
176 uint32_t c = m_digest[2];
177 uint32_t d = m_digest[3];
178 uint32_t e = m_digest[4];
185 f = (b & c) | (~b & d);
191 f = (b & c) | (b & d) | (c & d);
197 uint32_t temp =
LeftRotate(a, 5) + f + e + k + w[i];
220 inline std::string
sha1(std::string
const & src)
228 std::ostringstream oss;
229 for (
int i = 0; i < 5; ++i)
230 oss << std::hex << std::setfill(
'0') << std::setw(8) << hash[i];
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
This file provides the forward declarations for the main types used within ViennaCL.
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
result_of::size_type< T >::type start(T const &obj)