add arbitrary number of bytes
| 204 | |
| 205 | /// add arbitrary number of bytes |
| 206 | void MD5::add( const void* data, size_t numBytes ) |
| 207 | { |
| 208 | const uint8_t* current = (const uint8_t*)data; |
| 209 | |
| 210 | if( m_bufferSize > 0 ) |
| 211 | { |
| 212 | while( numBytes > 0 && m_bufferSize < BlockSize ) |
| 213 | { |
| 214 | m_buffer[m_bufferSize++] = *current++; |
| 215 | numBytes--; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | // full buffer |
| 220 | if( m_bufferSize == BlockSize ) |
| 221 | { |
| 222 | processBlock( m_buffer ); |
| 223 | m_numBytes += BlockSize; |
| 224 | m_bufferSize = 0; |
| 225 | } |
| 226 | |
| 227 | // no more data ? |
| 228 | if( numBytes == 0 ) |
| 229 | return; |
| 230 | |
| 231 | // process full blocks |
| 232 | while( numBytes >= BlockSize ) |
| 233 | { |
| 234 | processBlock( current ); |
| 235 | current += BlockSize; |
| 236 | m_numBytes += BlockSize; |
| 237 | numBytes -= BlockSize; |
| 238 | } |
| 239 | |
| 240 | // keep remaining bytes in buffer |
| 241 | while( numBytes > 0 ) |
| 242 | { |
| 243 | m_buffer[m_bufferSize++] = *current++; |
| 244 | numBytes--; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | |
| 249 | /// process final block, less than 64 bytes |