Exemplo n.º 1
0
/**
* Hash additional inputs
*/
void GOST_34_11::add_data(const uint8_t input[], size_t length)
{
    m_count += length;

    if(m_position)
    {
        buffer_insert(m_buffer, m_position, input, length);

        if(m_position + length >= hash_block_size())
        {
            compress_n(m_buffer.data(), 1);
            input += (hash_block_size() - m_position);
            length -= (hash_block_size() - m_position);
            m_position = 0;
        }
    }

    const size_t full_blocks = length / hash_block_size();
    const size_t remaining   = length % hash_block_size();

    if(full_blocks)
        compress_n(input, full_blocks);

    buffer_insert(m_buffer, m_position, input + full_blocks * hash_block_size(), remaining);
    m_position += remaining;
}
Exemplo n.º 2
0
/**
* Hash additional inputs
*/
void GOST_34_11::add_data(const byte input[], u32bit length)
   {
   count += length;

   if(position)
      {
      buffer.copy(position, input, length);

      if(position + length >= HASH_BLOCK_SIZE)
         {
         compress_n(buffer.begin(), 1);
         input += (HASH_BLOCK_SIZE - position);
         length -= (HASH_BLOCK_SIZE - position);
         position = 0;
         }
      }

   const u32bit full_blocks = length / HASH_BLOCK_SIZE;
   const u32bit remaining   = length % HASH_BLOCK_SIZE;

   if(full_blocks)
      compress_n(input, full_blocks);

   buffer.copy(position, input + full_blocks * HASH_BLOCK_SIZE, remaining);
   position += remaining;
   }
Exemplo n.º 3
0
/*
* Update the hash
*/
void MDx_HashFunction::add_data(const uint8_t input[], size_t length)
   {
   m_count += length;

   if(m_position)
      {
      buffer_insert(m_buffer, m_position, input, length);

      if(m_position + length >= m_buffer.size())
         {
         compress_n(m_buffer.data(), 1);
         input += (m_buffer.size() - m_position);
         length -= (m_buffer.size() - m_position);
         m_position = 0;
         }
      }

   const size_t full_blocks = length / m_buffer.size();
   const size_t remaining   = length % m_buffer.size();

   if(full_blocks)
      compress_n(input, full_blocks);

   buffer_insert(m_buffer, m_position, input + full_blocks * m_buffer.size(), remaining);
   m_position += remaining;
   }
Exemplo n.º 4
0
/*
* Finalize a hash
*/
void MDx_HashFunction::final_result(uint8_t output[])
   {
   m_buffer[m_position] = (BIG_BIT_ENDIAN ? 0x80 : 0x01);
   for(size_t i = m_position+1; i != m_buffer.size(); ++i)
      m_buffer[i] = 0;

   if(m_position >= m_buffer.size() - COUNT_SIZE)
      {
      compress_n(m_buffer.data(), 1);
      zeroise(m_buffer);
      }

   write_count(&m_buffer[m_buffer.size() - COUNT_SIZE]);

   compress_n(m_buffer.data(), 1);
   copy_out(output);
   clear();
   }
Exemplo n.º 5
0
/**
* Produce the final GOST 34.11 output
*/
void GOST_34_11::final_result(uint8_t out[])
{
    if(m_position)
    {
        clear_mem(m_buffer.data() + m_position, m_buffer.size() - m_position);
        compress_n(m_buffer.data(), 1);
    }

    secure_vector<uint8_t> length_buf(32);
    const uint64_t bit_count = m_count * 8;
    store_le(bit_count, length_buf.data());

    secure_vector<uint8_t> sum_buf = m_sum;

    compress_n(length_buf.data(), 1);
    compress_n(sum_buf.data(), 1);

    copy_mem(out, m_hash.data(), 32);

    clear();
}
Exemplo n.º 6
0
/**
* Produce the final GOST 34.11 output
*/
void GOST_34_11::final_result(byte out[])
   {
   if(position)
      {
      clear_mem(buffer.begin() + position, buffer.size() - position);
      compress_n(buffer, 1);
      }

   SecureBuffer<byte, 32> length_buf;
   const u64bit bit_count = count * 8;
   store_le(bit_count, length_buf);

   SecureBuffer<byte, 32> sum_buf(sum);

   compress_n(length_buf, 1);
   compress_n(sum_buf, 1);

   copy_mem(out, hash.begin(), 32);

   clear();
   }