/*************************************************
* MDx Hash Function Source File                  *
* (C) 1999-2003 The Botan Project                *
*************************************************/

#include <botan/mdx_hash.h>

namespace Botan {

/*************************************************
* MDx_HashFunction Constructor                   *
*************************************************/
MDx_HashFunction::MDx_HashFunction(u32bit hash_len, u32bit block_len) :
   HashFunction(hash_len, block_len), buffer(block_len)
   {
   count = position = 0;
   }

/*************************************************
* Update the hash                                *
*************************************************/
void MDx_HashFunction::add_data(const byte input[], u32bit length)
   {
   count += length;
   buffer.copy(position, input, length);
   if(position + length >= HASH_BLOCK_SIZE)
      {
      hash(buffer);
      input += (HASH_BLOCK_SIZE - position);
      length -= (HASH_BLOCK_SIZE - position);
      while(length >= HASH_BLOCK_SIZE)
         {
         hash(input);
         input += HASH_BLOCK_SIZE;
         length -= HASH_BLOCK_SIZE;
         }
      buffer.copy(input, length);
      position = 0;
      }
   position += length;
   }

}
