117 uint32_t t, msb, lsb;
128 if ((lsb += count) < t)
138 ibuffer[count++] = 0x80;
140 ibuffer[count++] = 0;
144 ibuffer[count++] = 0x80;
146 ibuffer[count++] = 0;
148 memset(ibuffer, 0, 56);
151 ibuffer[56] = msb >> 24;
152 ibuffer[57] = msb >> 16;
153 ibuffer[58] = msb >> 8;
155 ibuffer[60] = lsb >> 24;
156 ibuffer[61] = lsb >> 16;
157 ibuffer[62] = lsb >> 8;
163 #if (LIBXCKS_BYTE_ORDER == LIBXCKS_BIG_ENDIAN)
164 #define X(a) do { *(uint32_t*)p = h##a ; p += 4; } while(0)
166 #define X(a) do { *p++ = h##a >> 24; *p++ = h##a >> 16; \
167 *p++ = h##a >> 8; *p++ = h##a; } while(0)
182 void SHA1::update(
const uint8_t* buf,
size_t len)
196 for (; len && count < 64; len--)
197 ibuffer[count++] = *buf++;
205 uint8_t tmpBuf[
sizeof(uint32_t) * 16];
206 memcpy(tmpBuf, buf,
sizeof(uint32_t) * 16);
214 for(; len && count < 64; len--)
215 ibuffer[count++] = *buf++;
223 void SHA1::transform(uint8_t* data)
225 uint32_t a, b, c, d, e, tm;
235 #if (LIBXCKS_BYTE_ORDER == LIBXCKS_BIG_ENDIAN)
241 for (i = 0, p2 = (uint8_t*)x; i < 16; i++, p2 += 4)
251 #define K1 0x5A827999L
252 #define K2 0x6ED9EBA1L
253 #define K3 0x8F1BBCDCL
254 #define K4 0xCA62C1D6L
255 #define F1(x,y,z) ( z ^ ( x & ( y ^ z ) ) )
256 #define F2(x,y,z) ( x ^ y ^ z )
257 #define F3(x,y,z) ( ( x & y ) | ( z & ( x | y ) ) )
258 #define F4(x,y,z) ( x ^ y ^ z )
260 #define M(i) ( tm = x[i & 0x0f] ^ x[(i - 14) & 0x0f] \
261 ^ x[(i - 8) & 0x0f] ^ x[(i - 3) & 0x0f] \
262 , (x[i & 0x0f] = rol(tm, 1)) )
264 #define R(a,b,c,d,e,f,k,m) do { e += rol(a, 5) \
271 R(a, b, c, d, e,
F1,
K1, x[ 0]);
272 R(e, a, b, c, d,
F1,
K1, x[ 1]);
273 R(d, e, a, b, c,
F1,
K1, x[ 2]);
274 R(c, d, e, a, b,
F1,
K1, x[ 3]);
275 R(b, c, d, e, a,
F1,
K1, x[ 4]);
276 R(a, b, c, d, e,
F1,
K1, x[ 5]);
277 R(e, a, b, c, d,
F1,
K1, x[ 6]);
278 R(d, e, a, b, c,
F1,
K1, x[ 7]);
279 R(c, d, e, a, b,
F1,
K1, x[ 8]);
280 R(b, c, d, e, a,
F1,
K1, x[ 9]);
281 R(a, b, c, d, e,
F1,
K1, x[10]);
282 R(e, a, b, c, d,
F1,
K1, x[11]);
283 R(d, e, a, b, c,
F1,
K1, x[12]);
284 R(c, d, e, a, b,
F1,
K1, x[13]);
285 R(b, c, d, e, a,
F1,
K1, x[14]);
286 R(a, b, c, d, e,
F1,
K1, x[15]);
287 R(e, a, b, c, d,
F1,
K1,
M(16));
288 R(d, e, a, b, c,
F1,
K1,
M(17));
289 R(c, d, e, a, b,
F1,
K1,
M(18));
290 R(b, c, d, e, a,
F1,
K1,
M(19));
291 R(a, b, c, d, e,
F2,
K2,
M(20));
292 R(e, a, b, c, d,
F2,
K2,
M(21));
293 R(d, e, a, b, c,
F2,
K2,
M(22));
294 R(c, d, e, a, b,
F2,
K2,
M(23));
295 R(b, c, d, e, a,
F2,
K2,
M(24));
296 R(a, b, c, d, e,
F2,
K2,
M(25));
297 R(e, a, b, c, d,
F2,
K2,
M(26));
298 R(d, e, a, b, c,
F2,
K2,
M(27));
299 R(c, d, e, a, b,
F2,
K2,
M(28));
300 R(b, c, d, e, a,
F2,
K2,
M(29));
301 R(a, b, c, d, e,
F2,
K2,
M(30));
302 R(e, a, b, c, d,
F2,
K2,
M(31));
303 R(d, e, a, b, c,
F2,
K2,
M(32));
304 R(c, d, e, a, b,
F2,
K2,
M(33));
305 R(b, c, d, e, a,
F2,
K2,
M(34));
306 R(a, b, c, d, e,
F2,
K2,
M(35));
307 R(e, a, b, c, d,
F2,
K2,
M(36));
308 R(d, e, a, b, c,
F2,
K2,
M(37));
309 R(c, d, e, a, b,
F2,
K2,
M(38));
310 R(b, c, d, e, a,
F2,
K2,
M(39));
311 R(a, b, c, d, e,
F3,
K3,
M(40));
312 R(e, a, b, c, d,
F3,
K3,
M(41));
313 R(d, e, a, b, c,
F3,
K3,
M(42));
314 R(c, d, e, a, b,
F3,
K3,
M(43));
315 R(b, c, d, e, a,
F3,
K3,
M(44));
316 R(a, b, c, d, e,
F3,
K3,
M(45));
317 R(e, a, b, c, d,
F3,
K3,
M(46));
318 R(d, e, a, b, c,
F3,
K3,
M(47));
319 R(c, d, e, a, b,
F3,
K3,
M(48));
320 R(b, c, d, e, a,
F3,
K3,
M(49));
321 R(a, b, c, d, e,
F3,
K3,
M(50));
322 R(e, a, b, c, d,
F3,
K3,
M(51));
323 R(d, e, a, b, c,
F3,
K3,
M(52));
324 R(c, d, e, a, b,
F3,
K3,
M(53));
325 R(b, c, d, e, a,
F3,
K3,
M(54));
326 R(a, b, c, d, e,
F3,
K3,
M(55));
327 R(e, a, b, c, d,
F3,
K3,
M(56));
328 R(d, e, a, b, c,
F3,
K3,
M(57));
329 R(c, d, e, a, b,
F3,
K3,
M(58));
330 R(b, c, d, e, a,
F3,
K3,
M(59));
331 R(a, b, c, d, e,
F4,
K4,
M(60));
332 R(e, a, b, c, d,
F4,
K4,
M(61));
333 R(d, e, a, b, c,
F4,
K4,
M(62));
334 R(c, d, e, a, b,
F4,
K4,
M(63));
335 R(b, c, d, e, a,
F4,
K4,
M(64));
336 R(a, b, c, d, e,
F4,
K4,
M(65));
337 R(e, a, b, c, d,
F4,
K4,
M(66));
338 R(d, e, a, b, c,
F4,
K4,
M(67));
339 R(c, d, e, a, b,
F4,
K4,
M(68));
340 R(b, c, d, e, a,
F4,
K4,
M(69));
341 R(a, b, c, d, e,
F4,
K4,
M(70));
342 R(e, a, b, c, d,
F4,
K4,
M(71));
343 R(d, e, a, b, c,
F4,
K4,
M(72));
344 R(c, d, e, a, b,
F4,
K4,
M(73));
345 R(b, c, d, e, a,
F4,
K4,
M(74));
346 R(a, b, c, d, e,
F4,
K4,
M(75));
347 R(e, a, b, c, d,
F4,
K4,
M(76));
348 R(d, e, a, b, c,
F4,
K4,
M(77));
349 R(c, d, e, a, b,
F4,
K4,
M(78));
350 R(b, c, d, e, a,
F4,
K4,
M(79));
365 uint8_t* SHA1::getValue(uint8_t* buffer)
const
370 memcpy(buffer, sha1.
ibuffer, getSize());
Computes the SHA1 (or SHA160) hash from a byte stream.
uint8_t ibuffer[64]
Input buffer.
void finish()
Process the remaining bytes in the internal buffer and the usual prolog according to the standard.
#define F1(x, y, z)
Helper value for SHA1's computing.
#define R(a, b, c, d, e, f, k, m)
Helper value for SHA1's computing.
#define F4(x, y, z)
Helper value for SHA1's computing.
#define M(i)
Helper value for SHA1's computing.
#define F3(x, y, z)
Helper value for SHA1's computing.
#define K3
Helper value for SHA1's computing.
#define K1
Helper value for SHA1's computing.
#define K4
Helper value for SHA1's computing.
#define K2
Helper value for SHA1's computing.
#define X(a)
Helper value for SHA1's computing.
#define F2(x, y, z)
Helper value for SHA1's computing.
std::vector< std::string > ArrayString
Array of strings.