<!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++: eax.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.6.1 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <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 class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <h1>eax.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// eax.cpp - written and placed in the public domain by Wei Dai</span> <a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="preprocessor">#include "pch.h"</span> <a name="l00004"></a>00004 <span class="preprocessor">#include "eax.h"</span> <a name="l00005"></a>00005 <a name="l00006"></a>00006 NAMESPACE_BEGIN(CryptoPP) <a name="l00007"></a>00007 <a name="l00008"></a>00008 void <a class="code" href="class_e_a_x___base.html" title=".">EAX_Base</a>::SetKeyWithoutResync(const byte *userKey, <span class="keywordtype">size_t</span> keylength, const <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &params) <a name="l00009"></a>00009 { <a name="l00010"></a>00010 AccessMAC().SetKey(userKey, keylength, params); <a name="l00011"></a>00011 m_buffer.New(2*AccessMAC().TagSize()); <a name="l00012"></a>00012 } <a name="l00013"></a>00013 <a name="l00014"></a>00014 <span class="keywordtype">void</span> EAX_Base::Resync(<span class="keyword">const</span> byte *iv, <span class="keywordtype">size_t</span> len) <a name="l00015"></a>00015 { <a name="l00016"></a>00016 <a class="code" href="class_message_authentication_code.html" title="interface for message authentication codes">MessageAuthenticationCode</a> &mac = AccessMAC(); <a name="l00017"></a>00017 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> blockSize = mac.<a class="code" href="class_hash_transformation.html#a5e847d65a38ec354de1b28cc4bc66a81" title="same as DigestSize()">TagSize</a>(); <a name="l00018"></a>00018 <a name="l00019"></a>00019 memset(m_buffer, 0, blockSize); <a name="l00020"></a>00020 mac.<a class="code" href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5" title="process more input">Update</a>(m_buffer, blockSize); <a name="l00021"></a>00021 mac.<a class="code" href="class_hash_transformation.html#af8124c4fca23b74bbdc43660bdae692c" title="use this if your input is in one piece and you don&#39;t want to call Update() and...">CalculateDigest</a>(m_buffer+blockSize, iv, len); <a name="l00022"></a>00022 <a name="l00023"></a>00023 m_buffer[blockSize-1] = 1; <a name="l00024"></a>00024 mac.<a class="code" href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5" title="process more input">Update</a>(m_buffer, blockSize); <a name="l00025"></a>00025 <a name="l00026"></a>00026 m_ctr.SetCipherWithIV(AccessMAC().AccessCipher(), m_buffer+blockSize, blockSize); <a name="l00027"></a>00027 } <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="keywordtype">size_t</span> EAX_Base::AuthenticateBlocks(<span class="keyword">const</span> byte *data, <span class="keywordtype">size_t</span> len) <a name="l00030"></a>00030 { <a name="l00031"></a>00031 AccessMAC().<a class="code" href="class_c_m_a_c___base.html#a582cd6d32b41c65d10481ebcd2c1aed4" title="process more input">Update</a>(data, len); <a name="l00032"></a>00032 <span class="keywordflow">return</span> 0; <a name="l00033"></a>00033 } <a name="l00034"></a>00034 <a name="l00035"></a>00035 <span class="keywordtype">void</span> EAX_Base::AuthenticateLastHeaderBlock() <a name="l00036"></a>00036 { <a name="l00037"></a>00037 assert(m_bufferedDataLength == 0); <a name="l00038"></a>00038 <a class="code" href="class_message_authentication_code.html" title="interface for message authentication codes">MessageAuthenticationCode</a> &mac = AccessMAC(); <a name="l00039"></a>00039 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> blockSize = mac.<a class="code" href="class_hash_transformation.html#a5e847d65a38ec354de1b28cc4bc66a81" title="same as DigestSize()">TagSize</a>(); <a name="l00040"></a>00040 <a name="l00041"></a>00041 mac.<a class="code" href="class_hash_transformation.html#aa0b8c7a110d8968268fd02ec32b9a8e8" title="compute hash for current message, then restart for a new message">Final</a>(m_buffer); <a name="l00042"></a>00042 xorbuf(m_buffer+blockSize, m_buffer, blockSize); <a name="l00043"></a>00043 <a name="l00044"></a>00044 memset(m_buffer, 0, blockSize); <a name="l00045"></a>00045 m_buffer[blockSize-1] = 2; <a name="l00046"></a>00046 mac.<a class="code" href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5" title="process more input">Update</a>(m_buffer, blockSize); <a name="l00047"></a>00047 } <a name="l00048"></a>00048 <a name="l00049"></a>00049 <span class="keywordtype">void</span> EAX_Base::AuthenticateLastFooterBlock(byte *tag, <span class="keywordtype">size_t</span> macSize) <a name="l00050"></a>00050 { <a name="l00051"></a>00051 assert(m_bufferedDataLength == 0); <a name="l00052"></a>00052 <a class="code" href="class_message_authentication_code.html" title="interface for message authentication codes">MessageAuthenticationCode</a> &mac = AccessMAC(); <a name="l00053"></a>00053 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> blockSize = mac.<a class="code" href="class_hash_transformation.html#a5e847d65a38ec354de1b28cc4bc66a81" title="same as DigestSize()">TagSize</a>(); <a name="l00054"></a>00054 <a name="l00055"></a>00055 mac.<a class="code" href="class_hash_transformation.html#a590ecda344aa0fb045abf42ec08823b2" title="truncated version of Final()">TruncatedFinal</a>(m_buffer, macSize); <a name="l00056"></a>00056 xorbuf(tag, m_buffer, m_buffer+blockSize, macSize); <a name="l00057"></a>00057 } <a name="l00058"></a>00058 <a name="l00059"></a>00059 NAMESPACE_END </pre></div></div> <hr size="1"/><address style="text-align: right;"><small>Generated on 9 Dec 2009 for Crypto++ by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address> </body> </html>