<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Crypto++: cbcmac.cpp Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.3 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">Crypto++</div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="header"> <div class="headertitle"> <h1>cbcmac.cpp</h1> </div> </div> <div class="contents"> <div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include "pch.h"</span> <a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="preprocessor">#ifndef CRYPTOPP_IMPORTS</span> <a name="l00004"></a>00004 <span class="preprocessor"></span> <a name="l00005"></a>00005 <span class="preprocessor">#include "cbcmac.h"</span> <a name="l00006"></a>00006 <a name="l00007"></a>00007 NAMESPACE_BEGIN(CryptoPP) <a name="l00008"></a>00008 <a name="l00009"></a>00009 void <a class="code" href="class_c_b_c___m_a_c___base.html" title="_">CBC_MAC_Base</a>::UncheckedSetKey(const byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length, const <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &params) <a name="l00010"></a>00010 { <a name="l00011"></a>00011 AccessCipher().<a class="code" href="class_simple_keying_interface.html#adf3c29b3ef3af74788a58c7c49887fd7" title="set or reset the key of this object">SetKey</a>(key, length, params); <a name="l00012"></a>00012 m_reg.CleanNew(AccessCipher().<a class="code" href="namespace_name.html#aa93e40d0259a59959d270e6c82a9f1eb" title="int, in bytes">BlockSize</a>()); <a name="l00013"></a>00013 m_counter = 0; <a name="l00014"></a>00014 } <a name="l00015"></a>00015 <a name="l00016"></a><a class="code" href="class_c_b_c___m_a_c___base.html#af4b9ad28defd9ff98d86f0d6de2f4cf0">00016</a> <span class="keywordtype">void</span> <a class="code" href="class_c_b_c___m_a_c___base.html#af4b9ad28defd9ff98d86f0d6de2f4cf0" title="process more input">CBC_MAC_Base::Update</a>(<span class="keyword">const</span> byte *input, <span class="keywordtype">size_t</span> length) <a name="l00017"></a>00017 { <a name="l00018"></a>00018 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> blockSize = AccessCipher().<a class="code" href="class_block_transformation.html#adfdb78b033996020435c3dcffdca76ce" title="block size of the cipher in bytes">BlockSize</a>(); <a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="keywordflow">while</span> (m_counter && length) <a name="l00021"></a>00021 { <a name="l00022"></a>00022 m_reg[m_counter++] ^= *input++; <a name="l00023"></a>00023 <span class="keywordflow">if</span> (m_counter == blockSize) <a name="l00024"></a>00024 ProcessBuf(); <a name="l00025"></a>00025 length--; <a name="l00026"></a>00026 } <a name="l00027"></a>00027 <a name="l00028"></a>00028 <span class="keywordflow">if</span> (length >= blockSize) <a name="l00029"></a>00029 { <a name="l00030"></a>00030 <span class="keywordtype">size_t</span> leftOver = AccessCipher().<a class="code" href="class_block_transformation.html#adcff119bb709c84bfaaab8d1871b018c" title="encrypt and xor blocks according to flags (see FlagsForAdvancedProcessBlocks)">AdvancedProcessBlocks</a>(m_reg, input, m_reg, length, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput); <a name="l00031"></a>00031 input += (length - leftOver); <a name="l00032"></a>00032 length = leftOver; <a name="l00033"></a>00033 } <a name="l00034"></a>00034 <a name="l00035"></a>00035 <span class="keywordflow">while</span> (length--) <a name="l00036"></a>00036 { <a name="l00037"></a>00037 m_reg[m_counter++] ^= *input++; <a name="l00038"></a>00038 <span class="keywordflow">if</span> (m_counter == blockSize) <a name="l00039"></a>00039 ProcessBuf(); <a name="l00040"></a>00040 } <a name="l00041"></a>00041 } <a name="l00042"></a>00042 <a name="l00043"></a><a class="code" href="class_c_b_c___m_a_c___base.html#a50c5a8fc6a2926485295bbe72bcfe4d8">00043</a> <span class="keywordtype">void</span> <a class="code" href="class_c_b_c___m_a_c___base.html#a50c5a8fc6a2926485295bbe72bcfe4d8" title="truncated version of Final()">CBC_MAC_Base::TruncatedFinal</a>(byte *mac, <span class="keywordtype">size_t</span> size) <a name="l00044"></a>00044 { <a name="l00045"></a>00045 ThrowIfInvalidTruncatedSize(size); <a name="l00046"></a>00046 <a name="l00047"></a>00047 <span class="keywordflow">if</span> (m_counter) <a name="l00048"></a>00048 ProcessBuf(); <a name="l00049"></a>00049 <a name="l00050"></a>00050 memcpy(mac, m_reg, size); <a name="l00051"></a>00051 memset(m_reg, 0, AccessCipher().<a class="code" href="class_hash_transformation.html#ab5507c62376f6bea41d53ae9544d0ff0" title="block size of underlying compression function, or 0 if not block based">BlockSize</a>()); <a name="l00052"></a>00052 } <a name="l00053"></a>00053 <a name="l00054"></a>00054 <span class="keywordtype">void</span> CBC_MAC_Base::ProcessBuf() <a name="l00055"></a>00055 { <a name="l00056"></a>00056 AccessCipher().<a class="code" href="class_block_transformation.html#a2fefb3f4c6c6297c0c91fcbba9e4f4f3" title="encrypt or decrypt one block">ProcessBlock</a>(m_reg); <a name="l00057"></a>00057 m_counter = 0; <a name="l00058"></a>00058 } <a name="l00059"></a>00059 <a name="l00060"></a>00060 NAMESPACE_END <a name="l00061"></a>00061 <a name="l00062"></a>00062 <span class="preprocessor">#endif</span> </pre></div></div> </div> <hr class="footer"/><address class="footer"><small>Generated on Tue Feb 8 2011 for Crypto++ by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address> </body> </html>