diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-30 23:06:13 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-30 23:06:13 +0200 |
commit | 539364846a89987ac2679988653f50332cb91d26 (patch) | |
tree | f1695473c1f493a19c5fbdb70f7f1faccf99d7f3 /CryptoPP/cbcmac.cpp | |
parent | Updated to V6 - "Stop" and "Progress report" functionality (diff) | |
download | cuberite-539364846a89987ac2679988653f50332cb91d26.tar cuberite-539364846a89987ac2679988653f50332cb91d26.tar.gz cuberite-539364846a89987ac2679988653f50332cb91d26.tar.bz2 cuberite-539364846a89987ac2679988653f50332cb91d26.tar.lz cuberite-539364846a89987ac2679988653f50332cb91d26.tar.xz cuberite-539364846a89987ac2679988653f50332cb91d26.tar.zst cuberite-539364846a89987ac2679988653f50332cb91d26.zip |
Diffstat (limited to '')
-rw-r--r-- | CryptoPP/cbcmac.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/CryptoPP/cbcmac.cpp b/CryptoPP/cbcmac.cpp new file mode 100644 index 000000000..6b0e8858e --- /dev/null +++ b/CryptoPP/cbcmac.cpp @@ -0,0 +1,62 @@ +#include "pch.h" + +#ifndef CRYPTOPP_IMPORTS + +#include "cbcmac.h" + +NAMESPACE_BEGIN(CryptoPP) + +void CBC_MAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) +{ + AccessCipher().SetKey(key, length, params); + m_reg.CleanNew(AccessCipher().BlockSize()); + m_counter = 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(); + } +} + +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 CBC_MAC_Base::ProcessBuf() +{ + AccessCipher().ProcessBlock(m_reg); + m_counter = 0; +} + +NAMESPACE_END + +#endif |