summaryrefslogtreecommitdiff
path: root/cbcmac.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-07-04 00:17:37 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-07-04 00:17:37 +0000
commit572fe07633123ce38abf28c6426356e37aef3a99 (patch)
tree0536d87e504a82920156c239bc5ae6aa43e70ebc /cbcmac.cpp
parent3e8c979ddc194e043567c036321e67c89f847362 (diff)
downloadcryptopp-572fe07633123ce38abf28c6426356e37aef3a99.tar.gz
create DLL version, fix GetNextIV() bug in CTR and OFB modes
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@87 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'cbcmac.cpp')
-rw-r--r--cbcmac.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/cbcmac.cpp b/cbcmac.cpp
new file mode 100644
index 0000000..cc0a993
--- /dev/null
+++ b/cbcmac.cpp
@@ -0,0 +1,63 @@
+#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+
+#include "cbcmac.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+void CBC_MAC_Base::CheckedSetKey(void *, Empty empty, 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, unsigned int length)
+{
+ unsigned int blockSize = AccessCipher().BlockSize();
+
+ while (m_counter && length)
+ {
+ m_reg[m_counter++] ^= *input++;
+ if (m_counter == blockSize)
+ ProcessBuf();
+ length--;
+ }
+
+ while (length >= blockSize)
+ {
+ xorbuf(m_reg, input, blockSize);
+ ProcessBuf();
+ input += blockSize;
+ length -= blockSize;
+ }
+
+ while (length--)
+ {
+ m_reg[m_counter++] ^= *input++;
+ if (m_counter == blockSize)
+ ProcessBuf();
+ }
+}
+
+void CBC_MAC_Base::TruncatedFinal(byte *mac, unsigned int 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