43 bool add(
const void* input, uint64_t length)
46 if (!input || length == 0)
49 totalLength += length;
51 const unsigned char* data = (
const unsigned char*)input;
54 if (bufferSize + length < MaxBufferSize)
58 buffer[bufferSize++] = *data++;
63 const unsigned char* stop = data + length;
64 const unsigned char* stopBlock = stop - MaxBufferSize;
70 while (bufferSize < MaxBufferSize)
71 buffer[bufferSize++] = *data++;
74 process(buffer, state[0], state[1], state[2], state[3]);
78 uint64_t s0 = state[0], s1 = state[1], s2 = state[2], s3 = state[3];
80 while (data <= stopBlock)
83 process(data, s0, s1, s2, s3);
87 state[0] = s0; state[1] = s1; state[2] = s2; state[3] = s3;
90 bufferSize = stop - data;
91 for (uint64_t i = 0; i < bufferSize; i++)
104 if (totalLength >= MaxBufferSize)
106 result = rotateLeft(state[0], 1) +
107 rotateLeft(state[1], 7) +
108 rotateLeft(state[2], 12) +
109 rotateLeft(state[3], 18);
110 result = (result ^ processSingle(0, state[0])) * Prime1 + Prime4;
111 result = (result ^ processSingle(0, state[1])) * Prime1 + Prime4;
112 result = (result ^ processSingle(0, state[2])) * Prime1 + Prime4;
113 result = (result ^ processSingle(0, state[3])) * Prime1 + Prime4;
118 result = state[2] + Prime5;
121 result += totalLength;
124 const unsigned char* data = buffer;
126 const unsigned char* stop = data + bufferSize;
129 for (; data + 8 <= stop; data += 8)
130 result = rotateLeft(result ^ processSingle(0, *(uint64_t*)data), 27) * Prime1 + Prime4;
133 if (data + 4 <= stop)
135 result = rotateLeft(result ^ (*(uint32_t*)data) * Prime1, 23) * Prime2 + Prime3;
141 result = rotateLeft(result ^ (*data++) * Prime5, 11) * Prime1;
144 result ^= result >> 33;
146 result ^= result >> 29;
148 result ^= result >> 32;
194 static inline void process(
const void* data, uint64_t& state0, uint64_t& state1, uint64_t& state2, uint64_t& state3)