Ejemplo n.º 1
0
template <class T, class BASE> size_t IteratedHashBase<T, BASE>::HashMultipleBlocks(const T *input, size_t length)
{
	unsigned int blockSize = BlockSize();
	bool noReverse = NativeByteOrderIs(GetByteOrder());
	do
	{
		if (noReverse)
			HashEndianCorrectedBlock(input);
		else
		{
			ByteReverse(this->m_data.begin(), input, this->BlockSize());
			HashEndianCorrectedBlock(this->m_data);
		}

		input += blockSize/sizeof(T);
		length -= blockSize;
	}
	while (length >= blockSize);
	return length;
}
Ejemplo n.º 2
0
void PanamaHash<B>::TruncatedFinal(byte *hash, unsigned int size)
{
	this->ThrowIfInvalidTruncatedSize(size);

	PadLastBlock(this->BLOCKSIZE, 0x01);
	
	HashEndianCorrectedBlock(this->m_data);

	this->Iterate(32);	// pull

	ConditionalByteReverse(B::ToEnum(), this->m_state+9, this->m_state+9, DIGESTSIZE);
	memcpy(hash, this->m_state+9, size);

	this->Restart();		// reinit for next use
}
Ejemplo n.º 3
0
template <class T, class BASE> void IteratedHashBase<T, BASE>::TruncatedFinal(byte *digest, size_t size)
{
	this->ThrowIfInvalidTruncatedSize(size);

	PadLastBlock(this->BlockSize() - 2*sizeof(HashWordType));
	ByteOrder order = this->GetByteOrder();
	ConditionalByteReverse<HashWordType>(order, this->m_data, this->m_data, this->BlockSize() - 2*sizeof(HashWordType));

	this->m_data[this->m_data.size()-2] = order ? this->GetBitCountHi() : this->GetBitCountLo();
	this->m_data[this->m_data.size()-1] = order ? this->GetBitCountLo() : this->GetBitCountHi();

	HashEndianCorrectedBlock(this->m_data);
	ConditionalByteReverse<HashWordType>(order, this->m_digest, this->m_digest, this->DigestSize());
	memcpy(digest, this->m_digest, size);

	this->Restart();		// reinit for next use
}
Ejemplo n.º 4
0
void PanamaHash<B>::TruncatedFinal(byte *hash, size_t size)
{
	this->ThrowIfInvalidTruncatedSize(size);

	PadLastBlock(this->BLOCKSIZE, 0x01);
	
	HashEndianCorrectedBlock(this->m_data);

	this->Iterate(32);	// pull

	FixedSizeSecBlock<word32, 8> buf;
	this->Iterate(1, NULL, buf, NULL);

	memcpy(hash, buf, size);

	this->Restart();		// reinit for next use
}
Ejemplo n.º 5
0
void HAVAL::TruncatedFinal(byte *hash, size_t size)
{
    ThrowIfInvalidTruncatedSize(size);

    PadLastBlock(118, 1);	// first byte of padding for HAVAL is 1 instead of 0x80
    CorrectEndianess(m_data, m_data, 120);

    m_data[29] &= 0xffff;
    m_data[29] |= ((word32)digestSize<<25) | ((word32)pass<<19) | ((word32)HAVAL_VERSION<<16);
    m_data[30] = GetBitCountLo();
    m_data[31] = GetBitCountHi();

    HashEndianCorrectedBlock(m_data);
    Tailor(digestSize*8);
    CorrectEndianess(m_digest, m_digest, digestSize);
    memcpy(hash, m_digest, size);

    Restart();		// reinit for next use
}