<!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"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <meta name="generator" content="Doxygen 1.8.14"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>Crypto++: authenc.h Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td id="projectalign" style="padding-left: 0.5em;"> <div id="projectname">Crypto++  <span id="projectnumber">7.0</span> </div> <div id="projectbrief">Free C++ class library of cryptographic schemes</div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.14 --> <script type="text/javascript" src="menudata.js"></script> <script type="text/javascript" src="menu.js"></script> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ $(function() { initMenu('',false,false,'search.php','Search'); }); /* @license-end */</script> <div id="main-nav"></div> </div><!-- top --> <div class="header"> <div class="headertitle"> <div class="title">authenc.h</div> </div> </div><!--header--> <div class="contents"> <a href="authenc_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">// authenc.h - originally written and placed in the public domain by Wei Dai</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment"></span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment">/// \file</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment">/// \brief Classes for authenticated encryption modes of operation</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment">/// \details Authenticated encryption (AE) schemes combine confidentiality and authenticity</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment">/// into a single mode of operation They gained traction in the early 2000's because manually</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment">/// combining them was error prone for the typical developer. Around that time, the desire to</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment">/// authenticate but not ecrypt additional data (AAD) was also identified. When both features</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment">/// are available from a scheme, the system is referred to as an AEAD scheme.</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment">/// \details Crypto++ provides four authenticated encryption modes of operation - CCM, EAX, GCM</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment">/// and OCB mode. All modes derive from AuthenticatedSymmetricCipherBase() and the</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment">/// motivation for the API, like calling AAD a &quot;header&quot;, can be found in Bellare,</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment">/// Rogaway and Wagner's <A HREF="http://web.cs.ucdavis.edu/~rogaway/papers/eax.pdf">The EAX</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment">/// Mode of Operation</A>. The EAX paper suggested a basic API to help standardize AEAD</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment">/// schemes in software and promote adoption of the modes.</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="comment">/// \sa <A HREF="http://www.cryptopp.com/wiki/Authenticated_Encryption">Authenticated</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment">/// Encryption</A> on the Crypto++ wiki.</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="comment">/// \since Crypto++ 5.6.0</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="comment"></span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="preprocessor">#ifndef CRYPTOPP_AUTHENC_H</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="preprocessor">#define CRYPTOPP_AUTHENC_H</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> </div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="preprocessor">#include "<a class="code" href="cryptlib_8h.html">cryptlib.h</a>"</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="preprocessor">#include "<a class="code" href="secblock_8h.html">secblock.h</a>"</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> </div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> NAMESPACE_BEGIN(<a class="code" href="namespace_crypto_p_p.html">CryptoPP</a>)</div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> </div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="comment">/// \brief Base class for authenticated encryption modes of operation</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="comment"></span><span class="comment">/// \details AuthenticatedSymmetricCipherBase() serves as a base implementation for one direction</span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="comment"></span><span class="comment">/// (encryption or decryption) of a stream cipher or block cipher mode with authentication.</span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> <span class="comment"></span><span class="comment">/// \details Crypto++ provides four authenticated encryption modes of operation - CCM, EAX, GCM</span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="comment"></span><span class="comment">/// and OCB mode. All modes derive from AuthenticatedSymmetricCipherBase() and the</span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="comment"></span><span class="comment">/// motivation for the API, like calling AAD a &quot;header&quot;, can be found in Bellare,</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="comment"></span><span class="comment">/// Rogaway and Wagner's <A HREF="http://web.cs.ucdavis.edu/~rogaway/papers/eax.pdf">The EAX</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="comment"></span><span class="comment">/// Mode of Operation</A>. The EAX paper suggested a basic API to help standardize AEAD</span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> <span class="comment"></span><span class="comment">/// schemes in software and promote adoption of the modes.</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span> <span class="comment"></span><span class="comment">/// \sa <A HREF="http://www.cryptopp.com/wiki/Authenticated_Encryption">Authenticated</span></div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> <span class="comment"></span><span class="comment">/// Encryption</A> on the Crypto++ wiki.</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="comment"></span><span class="comment">/// \since Crypto++ 5.6.0</span></div><div class="line"><a name="l00040"></a><span class="lineno"><a class="line" href="class_authenticated_symmetric_cipher_base.html"> 40</a></span> <span class="comment"></span>class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE <a class="code" href="class_authenticated_symmetric_cipher_base.html">AuthenticatedSymmetricCipherBase</a> : public <a class="code" href="class_authenticated_symmetric_cipher.html">AuthenticatedSymmetricCipher</a></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span> {</div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span> <span class="keyword">public</span>:</div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  <a class="code" href="class_authenticated_symmetric_cipher_base.html">AuthenticatedSymmetricCipherBase</a>() : m_totalHeaderLength(0), m_totalMessageLength(0),</div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  m_totalFooterLength(0), m_bufferedDataLength(0), m_state(State_Start) {}</div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> </div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  <span class="comment">// StreamTransformation interface</span></div><div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="class_authenticated_symmetric_cipher_base.html#a007ee52a51a397cc48840e21488e82a0"> 47</a></span>  <span class="keywordtype">bool</span> <a class="code" href="class_authenticated_symmetric_cipher_base.html#a007ee52a51a397cc48840e21488e82a0">IsRandomAccess</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">false</span>;}</div><div class="line"><a name="l00048"></a><span class="lineno"><a class="line" href="class_authenticated_symmetric_cipher_base.html#a5c57dc0ee98bf5684b1be5cd18e34017"> 48</a></span>  <span class="keywordtype">bool</span> <a class="code" href="class_authenticated_symmetric_cipher_base.html#a5c57dc0ee98bf5684b1be5cd18e34017">IsSelfInverting</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">true</span>;}</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span> </div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  <span class="keywordtype">void</span> SetKey(<span class="keyword">const</span> byte *userKey, <span class="keywordtype">size_t</span> keylength, <span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &params);</div><div class="line"><a name="l00051"></a><span class="lineno"><a class="line" href="class_authenticated_symmetric_cipher_base.html#a5c6a2964ef0bae2428347f180f76256e"> 51</a></span>  <span class="keywordtype">void</span> <a class="code" href="class_authenticated_symmetric_cipher_base.html#a5c6a2964ef0bae2428347f180f76256e">Restart</a>() {<span class="keywordflow">if</span> (m_state > State_KeySet) m_state = State_KeySet;}</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  <span class="keywordtype">void</span> Resynchronize(<span class="keyword">const</span> byte *iv, <span class="keywordtype">int</span> length=-1);</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  <span class="keywordtype">void</span> Update(<span class="keyword">const</span> byte *input, <span class="keywordtype">size_t</span> length);</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  <span class="keywordtype">void</span> ProcessData(byte *outString, <span class="keyword">const</span> byte *inString, <span class="keywordtype">size_t</span> length);</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  <span class="keywordtype">void</span> TruncatedFinal(byte *mac, <span class="keywordtype">size_t</span> macSize);</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span> </div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span> <span class="keyword">protected</span>:</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  <span class="keywordtype">void</span> UncheckedSetKey(<span class="keyword">const</span> byte * key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length,<span class="keyword">const</span> CryptoPP::NameValuePairs &params)</div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  {CRYPTOPP_UNUSED(key), CRYPTOPP_UNUSED(length), CRYPTOPP_UNUSED(params); <a class="code" href="trap_8h.html#adf3b392588bc94cbeae9f415a78c7b95">CRYPTOPP_ASSERT</a>(<span class="keyword">false</span>);}</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span> </div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  <span class="keywordtype">void</span> AuthenticateData(<span class="keyword">const</span> byte *data, <span class="keywordtype">size_t</span> len);</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  <span class="keyword">const</span> <a class="code" href="class_symmetric_cipher.html">SymmetricCipher</a> & GetSymmetricCipher()<span class="keyword"> const</span></div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span> <span class="keyword"> </span>{<span class="keywordflow">return</span> <span class="keyword">const_cast<</span><a class="code" href="class_authenticated_symmetric_cipher_base.html">AuthenticatedSymmetricCipherBase</a> *<span class="keyword">></span>(<span class="keyword">this</span>)->AccessSymmetricCipher();};</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span> </div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  <span class="keyword">virtual</span> <a class="code" href="class_symmetric_cipher.html">SymmetricCipher</a> & AccessSymmetricCipher() =0;</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  <span class="keyword">virtual</span> <span class="keywordtype">bool</span> AuthenticationIsOnPlaintext() <span class="keyword">const</span> =0;</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> AuthenticationBlockSize() <span class="keyword">const</span> =0;</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> SetKeyWithoutResync(<span class="keyword">const</span> byte *userKey, <span class="keywordtype">size_t</span> keylength, <span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &params) =0;</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Resync(<span class="keyword">const</span> byte *iv, <span class="keywordtype">size_t</span> len) =0;</div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> AuthenticateBlocks(<span class="keyword">const</span> byte *data, <span class="keywordtype">size_t</span> len) =0;</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> AuthenticateLastHeaderBlock() =0;</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> AuthenticateLastConfidentialBlock() {}</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> AuthenticateLastFooterBlock(byte *mac, <span class="keywordtype">size_t</span> macSize) =0;</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span> </div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  <span class="comment">// State_AuthUntransformed: authentication is applied to plain text (Authenticate-then-Encrypt)</span></div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  <span class="comment">// State_AuthTransformed: authentication is applied to cipher text (Encrypt-then-Authenticate)</span></div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  <span class="keyword">enum</span> State {State_Start, State_KeySet, State_IVSet, State_AuthUntransformed, State_AuthTransformed, State_AuthFooter};</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span> </div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  <a class="code" href="class_aligned_sec_byte_block.html">AlignedSecByteBlock</a> m_buffer;</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  lword m_totalHeaderLength, m_totalMessageLength, m_totalFooterLength;</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m_bufferedDataLength;</div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  State m_state;</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span> };</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span> </div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span> NAMESPACE_END</div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span> </div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span> <span class="preprocessor">#endif</span></div><div class="ttc" id="class_authenticated_symmetric_cipher_html"><div class="ttname"><a href="class_authenticated_symmetric_cipher.html">AuthenticatedSymmetricCipher</a></div><div class="ttdoc">Interface for authenticated encryption modes of operation. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l01267">cryptlib.h:1267</a></div></div> <div class="ttc" id="cryptlib_8h_html"><div class="ttname"><a href="cryptlib_8h.html">cryptlib.h</a></div><div class="ttdoc">Abstract base classes that provide a uniform interface to this library. </div></div> <div class="ttc" id="class_authenticated_symmetric_cipher_base_html_a007ee52a51a397cc48840e21488e82a0"><div class="ttname"><a href="class_authenticated_symmetric_cipher_base.html#a007ee52a51a397cc48840e21488e82a0">AuthenticatedSymmetricCipherBase::IsRandomAccess</a></div><div class="ttdeci">bool IsRandomAccess() const</div><div class="ttdoc">Determines whether the cipher supports random access. </div><div class="ttdef"><b>Definition:</b> <a href="authenc_8h_source.html#l00047">authenc.h:47</a></div></div> <div class="ttc" id="class_authenticated_symmetric_cipher_base_html_a5c6a2964ef0bae2428347f180f76256e"><div class="ttname"><a href="class_authenticated_symmetric_cipher_base.html#a5c6a2964ef0bae2428347f180f76256e">AuthenticatedSymmetricCipherBase::Restart</a></div><div class="ttdeci">void Restart()</div><div class="ttdoc">Restart the hash. </div><div class="ttdef"><b>Definition:</b> <a href="authenc_8h_source.html#l00051">authenc.h:51</a></div></div> <div class="ttc" id="secblock_8h_html"><div class="ttname"><a href="secblock_8h.html">secblock.h</a></div><div class="ttdoc">Classes and functions for secure memory allocations. </div></div> <div class="ttc" id="class_authenticated_symmetric_cipher_base_html_a5c57dc0ee98bf5684b1be5cd18e34017"><div class="ttname"><a href="class_authenticated_symmetric_cipher_base.html#a5c57dc0ee98bf5684b1be5cd18e34017">AuthenticatedSymmetricCipherBase::IsSelfInverting</a></div><div class="ttdeci">bool IsSelfInverting() const</div><div class="ttdoc">Determines whether the cipher is self-inverting. </div><div class="ttdef"><b>Definition:</b> <a href="authenc_8h_source.html#l00048">authenc.h:48</a></div></div> <div class="ttc" id="class_symmetric_cipher_html"><div class="ttname"><a href="class_symmetric_cipher.html">SymmetricCipher</a></div><div class="ttdoc">Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...</div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l01237">cryptlib.h:1237</a></div></div> <div class="ttc" id="class_authenticated_symmetric_cipher_base_html"><div class="ttname"><a href="class_authenticated_symmetric_cipher_base.html">AuthenticatedSymmetricCipherBase</a></div><div class="ttdoc">Base class for authenticated encryption modes of operation. </div><div class="ttdef"><b>Definition:</b> <a href="authenc_8h_source.html#l00040">authenc.h:40</a></div></div> <div class="ttc" id="class_aligned_sec_byte_block_html"><div class="ttname"><a href="class_aligned_sec_byte_block.html">AlignedSecByteBlock</a></div><div class="ttdoc">SecBlock using AllocatorWithCleanup<byte, true> typedef. </div><div class="ttdef"><b>Definition:</b> <a href="secblock_8h_source.html#l00826">secblock.h:826</a></div></div> <div class="ttc" id="trap_8h_html_adf3b392588bc94cbeae9f415a78c7b95"><div class="ttname"><a href="trap_8h.html#adf3b392588bc94cbeae9f415a78c7b95">CRYPTOPP_ASSERT</a></div><div class="ttdeci">#define CRYPTOPP_ASSERT(exp)</div><div class="ttdoc">Debugging and diagnostic assertion. </div><div class="ttdef"><b>Definition:</b> <a href="trap_8h_source.html#l00060">trap.h:60</a></div></div> <div class="ttc" id="namespace_crypto_p_p_html"><div class="ttname"><a href="namespace_crypto_p_p.html">CryptoPP</a></div><div class="ttdoc">Crypto++ library namespace. </div></div> <div class="ttc" id="class_name_value_pairs_html"><div class="ttname"><a href="class_name_value_pairs.html">NameValuePairs</a></div><div class="ttdoc">Interface for retrieving values given their names. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l00290">cryptlib.h:290</a></div></div> </div><!-- fragment --></div><!-- contents --> <!-- start footer part --> <hr class="footer"/><address class="footer"><small> Generated on Sun Sep 16 2018 07:57:45 for Crypto++ by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.8.14 </small></address> </body> </html>