45 inline const unsigned int rol(
const unsigned int value,
46 const unsigned int steps)
48 return ((value << steps) | (value >> (32 - steps)));
53 inline void clearWBuffert(
unsigned int* buffert)
55 for (
int pos = 16; --pos >= 0;)
61 inline void innerHash(
unsigned int* result,
unsigned int* w)
63 unsigned int a = result[0];
64 unsigned int b = result[1];
65 unsigned int c = result[2];
66 unsigned int d = result[3];
67 unsigned int e = result[4];
71 #define sha1macro(func,val) \
73 const unsigned int t = rol(a, 5) + (func) + e + val + w[round]; \
83 sha1macro((b & c) | (~b & d), 0x5a827999)
88 w[round] = rol((w[round - 3] ^ w[round - 8] ^ w[round - 14] ^ w[round - 16]), 1);
89 sha1macro((b & c) | (~b & d), 0x5a827999)
94 w[round] = rol((w[round - 3] ^ w[round - 8] ^ w[round - 14] ^ w[round - 16]), 1);
95 sha1macro(b ^ c ^ d, 0x6ed9eba1)
100 w[round] = rol((w[round - 3] ^ w[round - 8] ^ w[round - 14] ^ w[round - 16]), 1);
101 sha1macro((b & c) | (b & d) | (c & d), 0x8f1bbcdc)
106 w[round] = rol((w[round - 3] ^ w[round - 8] ^ w[round - 14] ^ w[round - 16]), 1);
107 sha1macro(b ^ c ^ d, 0xca62c1d6)
126 inline void calc(
const void* src,
const int bytelength,
unsigned char* hash) {
128 unsigned int result[5] = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 };
131 const unsigned char* sarray = (
const unsigned char*) src;
137 const int endOfFullBlocks = bytelength - 64;
139 int currentBlock = 0;
141 while (currentBlock <= endOfFullBlocks)
143 endCurrentBlock = currentBlock + 64;
146 for (
int roundPos = 0; currentBlock < endCurrentBlock; currentBlock += 4)
149 w[roundPos++] = (
unsigned int) sarray[currentBlock + 3]
150 | (((
unsigned int) sarray[currentBlock + 2]) << 8)
151 | (((
unsigned int) sarray[currentBlock + 1]) << 16)
152 | (((
unsigned int) sarray[currentBlock]) << 24);
154 innerHash(result, w);
158 endCurrentBlock = bytelength - currentBlock;
160 int lastBlockBytes = 0;
161 for (;lastBlockBytes < endCurrentBlock; ++lastBlockBytes)
163 w[lastBlockBytes >> 2] |= (
unsigned int) sarray[lastBlockBytes + currentBlock] << ((3 - (lastBlockBytes & 3)) << 3);
165 w[lastBlockBytes >> 2] |= 0x80 << ((3 - (lastBlockBytes & 3)) << 3);
166 if (endCurrentBlock >= 56)
168 innerHash(result, w);
171 w[15] = bytelength << 3;
172 innerHash(result, w);
175 for (
int hashByte = 20; --hashByte >= 0;)
177 hash[hashByte] = (result[hashByte >> 2] >> (((3 - hashByte) & 0x3) << 3)) & 0xff;
184 #endif // SHA1_DEFINED
uint16_t value
The type of a close code value.
Namespace for the WebSocket++ project.