Esempio n. 1
0
void CBC_MAC_Base::Update(const byte *input, size_t length)
{
	unsigned int blockSize = AccessCipher().BlockSize();

	while (m_counter && length)
	{
		m_reg[m_counter++] ^= *input++;
		if (m_counter == blockSize)
			ProcessBuf();
		length--;
	}

	if (length >= blockSize)
	{
		size_t leftOver = AccessCipher().AdvancedProcessBlocks(m_reg, input, m_reg, length, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
		input += (length - leftOver);
		length = leftOver;
	}

	while (length--)
	{
		m_reg[m_counter++] ^= *input++;
		if (m_counter == blockSize)
			ProcessBuf();
	}
}
Esempio n. 2
0
void CBC_MAC_Base::TruncatedFinal(byte *mac, size_t size)
{
	ThrowIfInvalidTruncatedSize(size);

	if (m_counter)
		ProcessBuf();

	memcpy(mac, m_reg, size);
	memset(m_reg, 0, AccessCipher().BlockSize());
}
Esempio n. 3
0
void CBCPaddedEncryptor::Put(const byte *inString, unsigned int length)
{
	while (counter && length)
	{
		CBCPaddedEncryptor::Put(*inString++);
		length--;
	}

	while (length >= S)
	{
		xorbuf(reg, inString, S);
		ProcessBuf();
		inString += S;
		length -= S;
	}

	while (length--)
		CBCPaddedEncryptor::Put(*inString++);
}
Esempio n. 4
0
void CBCPaddedDecryptor::Put(const byte *inString, unsigned int length)
{
	while (counter!=S && length)
	{
		CBCPaddedDecryptor::Put(*inString++);
		length--;
	}

	while (length >= S)
	{
		ProcessBuf();
		memcpy(buffer, inString, S);
		counter = S;
		inString += S;
		length -= S;
	}

	while (length--)
		CBCPaddedDecryptor::Put(*inString++);
}
Esempio n. 5
0
void CBCPaddedDecryptor::Put(byte inByte)
{
	if (counter == S)
		ProcessBuf();
	buffer[counter++] = inByte;
}
Esempio n. 6
0
void CBCPaddedEncryptor::Put(byte inByte)
{
	reg[counter++] ^= inByte;
	if (counter == S)
		ProcessBuf();
}