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(); } }
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()); }
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++); }
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++); }
void CBCPaddedDecryptor::Put(byte inByte) { if (counter == S) ProcessBuf(); buffer[counter++] = inByte; }
void CBCPaddedEncryptor::Put(byte inByte) { reg[counter++] ^= inByte; if (counter == S) ProcessBuf(); }