summaryrefslogtreecommitdiffstats
path: root/cryptopp562/cbcmac.cpp
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2016-04-13 21:05:14 -0400
committerMalf Furious <m@lfurio.us>2016-04-13 21:05:14 -0400
commit490d36e65ac24e34e3021c2a0947384aee138c88 (patch)
tree418a229fa60708d7796bc61f90794626aefed9d5 /cryptopp562/cbcmac.cpp
downloadcompass-490d36e65ac24e34e3021c2a0947384aee138c88.tar.gz
compass-490d36e65ac24e34e3021c2a0947384aee138c88.zip
Root commit for new Compass repository
This is the Alpha version of ComPASS, originally developed sometime in 2014.
Diffstat (limited to 'cryptopp562/cbcmac.cpp')
-rw-r--r--cryptopp562/cbcmac.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/cryptopp562/cbcmac.cpp b/cryptopp562/cbcmac.cpp
new file mode 100644
index 0000000..6b0e885
--- /dev/null
+++ b/cryptopp562/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 &params)
+{
+ 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