MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / add

Method add

src/sha3.cpp:172–213  ·  view source on GitHub ↗

add arbitrary number of bytes

Source from the content-addressed store, hash-verified

170
171/// add arbitrary number of bytes
172void SHA3::add(const void* data, size_t numBytes)
173{
174 const uint8_t* current = (const uint8_t*) data;
175
176 // copy data to buffer
177 if (m_bufferSize > 0)
178 {
179 while (numBytes > 0 && m_bufferSize < m_blockSize)
180 {
181 m_buffer[m_bufferSize++] = *current++;
182 numBytes--;
183 }
184 }
185
186 // full buffer
187 if (m_bufferSize == m_blockSize)
188 {
189 processBlock((void*)m_buffer);
190 m_numBytes += m_blockSize;
191 m_bufferSize = 0;
192 }
193
194 // no more data ?
195 if (numBytes == 0)
196 return;
197
198 // process full blocks
199 while (numBytes >= m_blockSize)
200 {
201 processBlock(current);
202 current += m_blockSize;
203 m_numBytes += m_blockSize;
204 numBytes -= m_blockSize;
205 }
206
207 // keep remaining bytes in buffer
208 while (numBytes > 0)
209 {
210 m_buffer[m_bufferSize++] = *current++;
211 numBytes--;
212 }
213}
214
215
216/// process everything left in the internal buffer

Callers 10

mainFunction · 0.45
ResetStateMethod · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls

no outgoing calls

Tested by 2

ResetStateMethod · 0.36