Beispiel #1
0
template <class T, class BASE> size_t IteratedHashBase<T, BASE>::HashMultipleBlocks(const T *input, size_t length)
{
	const unsigned int blockSize = this->BlockSize();
	bool noReverse = NativeByteOrderIs(this->GetByteOrder());
	T* dataBuf = this->DataBuf();

	// Alignment checks due to http://github.com/weidai11/cryptopp/issues/690.
	// Sparc requires 8-byte aligned buffer when HashWordType is word64.
	// We also had to provide a GetAlignmentOf specialization for word64 on Sparc.

	do
	{
		if (noReverse)
		{
			if (IsAligned<HashWordType>(input))
			{
				// Sparc bus error with non-aligned input.
				this->HashEndianCorrectedBlock(input);
			}
			else
			{
				std::memcpy(dataBuf, input, blockSize);
				this->HashEndianCorrectedBlock(dataBuf);
			}
		}
		else
		{
			if (IsAligned<HashWordType>(input))
			{
				// Sparc bus error with non-aligned input.
				ByteReverse(dataBuf, input, blockSize);
				this->HashEndianCorrectedBlock(dataBuf);
			}
			else
			{
				std::memcpy(dataBuf, input, blockSize);
				ByteReverse(dataBuf, dataBuf, blockSize);
				this->HashEndianCorrectedBlock(dataBuf);
			}
		}

		input += blockSize/sizeof(T);
		length -= blockSize;
	}
	while (length >= blockSize);
	return length;
}
Beispiel #2
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;
}
Beispiel #3
0
template <class T, class BASE> size_t IteratedHashBase<T, BASE>::HashMultipleBlocks(const T *input, size_t length)
{
	// Hardware based SHA1 and SHA256 correct blocks themselves due to hardware requirements.
	//  For Intel, SHA1 will effectively call ByteReverse(). SHA256 formats data to Intel
	//  requirements, which means eight words ABCD EFGH are transformed to ABEF CDGH.
	unsigned int blockSize = this->BlockSize();
	bool noReverse = NativeByteOrderIs(this->GetByteOrder());
	T* dataBuf = this->DataBuf();
	do
	{
		if (noReverse)
			this->HashEndianCorrectedBlock(input);
		else
		{
			ByteReverse(dataBuf, input, this->BlockSize());
			this->HashEndianCorrectedBlock(dataBuf);
		}

		input += blockSize/sizeof(T);
		length -= blockSize;
	}
	while (length >= blockSize);
	return length;
}