<!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++: poly1305.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">poly1305.h</div> </div> </div><!--header--> <div class="contents"> <a href="poly1305_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">// poly1305.h - written and placed in the public domain by Jeffrey Walton and Jean-Pierre Munch</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment">// Based on Andy Polyakov's Base-2^26 scalar multiplication implementation for OpenSSL.</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment"></span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment">/// \file poly1305.h</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment">/// \brief Classes for Poly1305 message authentication code</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment">/// \details Poly1305-AES is a state-of-the-art message-authentication code suitable for a wide</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment">/// variety of applications. Poly1305-AES computes a 16-byte authenticator of a variable-length</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment">/// message, using a 16-byte AES key, a 16-byte additional key, and a 16-byte nonce.</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment">/// \details Each message must use a unique security context, which means either the key or nonce</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment">/// must be changed after each message. It can be accomplished in one of two ways. First, you</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment">/// can create a new Poly1305 object with a key and nonce each time its needed.</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment">/// <pre> SecByteBlock key(32), nonce(16);</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment">/// prng.GenerateBlock(key, key.size());</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment">/// prng.GenerateBlock(nonce, nonce.size());</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment">///</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="comment">/// Poly1305<AES> poly1305(key, key.size(), nonce, nonce.size());</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment">/// poly1305.Update(...);</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="comment">/// poly1305.Final(...);</pre></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="comment">/// \details Second, you can create a Poly1305 object, reuse the key, and set a fresh nonce</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="comment">/// for each message. The second and subsequent nonces can be generated directly using a</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="comment">/// RandomNumberGenerator() derived class; or it can be generated using GetNextIV().</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="comment">/// <pre> SecByteBlock key(32), nonce(16);</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="comment">/// prng.GenerateBlock(key, key.size());</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="comment">/// prng.GenerateBlock(nonce, nonce.size());</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="comment">///</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="comment">/// // First message</span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="comment">/// Poly1305<AES> poly1305(key, key.size());</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="comment">/// poly1305.Resynchronize(nonce);</span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="comment">/// poly1305.Update(...);</span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> <span class="comment">/// poly1305.Final(...);</span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="comment">///</span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="comment">/// // Second message</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="comment">/// poly1305.GetNextIV(prng, nonce);</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="comment">/// poly1305.Resynchronize(nonce);</span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> <span class="comment">/// poly1305.Update(...);</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span> <span class="comment">/// poly1305.Final(...);</span></div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> <span class="comment">/// ...</pre></span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="comment">/// \sa Daniel J. Bernstein <A HREF="http://cr.yp.to/mac/poly1305-20050329.pdf">The Poly1305-AES</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span> <span class="comment">/// Message-Authentication Code (20050329)</A> and Andy Polyakov <A</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span> <span class="comment">/// HREF="http://www.openssl.org/blog/blog/2016/02/15/poly1305-revised/">Poly1305 Revised</A></span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span> <span class="comment">/// \since Crypto++ 6.0</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span> <span class="comment"></span></div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span> <span class="preprocessor">#ifndef CRYPTOPP_POLY1305_H</span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> <span class="preprocessor">#define CRYPTOPP_POLY1305_H</span></div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span> </div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span> <span class="preprocessor">#include "<a class="code" href="cryptlib_8h.html">cryptlib.h</a>"</span></div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span> <span class="preprocessor">#include "<a class="code" href="seckey_8h.html">seckey.h</a>"</span></div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span> <span class="preprocessor">#include "<a class="code" href="secblock_8h.html">secblock.h</a>"</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span> <span class="preprocessor">#include "<a class="code" href="argnames_8h.html">argnames.h</a>"</span></div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span> <span class="preprocessor">#include "<a class="code" href="algparam_8h.html">algparam.h</a>"</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span> </div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span> NAMESPACE_BEGIN(<a class="code" href="namespace_crypto_p_p.html">CryptoPP</a>)</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span> </div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span> <span class="comment">/// \brief Poly1305 message authentication code base class</span></div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span> <span class="comment"></span><span class="comment">/// \tparam T class derived from BlockCipherDocumentation with 16-byte key and 16-byte blocksize</span></div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span> <span class="comment"></span><span class="comment">/// \since Crypto++ 6.0</span></div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span> <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> T></div><div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="class_poly1305___base.html"> 59</a></span> <span class="keyword">class </span>CRYPTOPP_NO_VTABLE <a class="code" href="class_poly1305___base.html">Poly1305_Base</a> : <span class="keyword">public</span> <a class="code" href="class_fixed_key_length.html">FixedKeyLength</a><32, SimpleKeyingInterface::UNIQUE_IV, 16>, <span class="keyword">public</span> <a class="code" href="class_message_authentication_code.html">MessageAuthenticationCode</a></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>  <a class="code" href="misc_8h.html#a6b378b1b9b2d4654cc852c088742ba70">CRYPTOPP_COMPILE_ASSERT</a>(T::DEFAULT_KEYLENGTH == 16);</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  <a class="code" href="misc_8h.html#a6b378b1b9b2d4654cc852c088742ba70">CRYPTOPP_COMPILE_ASSERT</a>(T::BLOCKSIZE == 16);</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span> </div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span> <span class="keyword">public</span>:</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  <span class="keyword">static</span> std::string StaticAlgorithmName() {<span class="keywordflow">return</span> std::string(<span class="stringliteral">"Poly1305("</span>) + T::StaticAlgorithmName() + <span class="stringliteral">")"</span>;}</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span> </div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  CRYPTOPP_CONSTANT(DIGESTSIZE=T::BLOCKSIZE)</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  CRYPTOPP_CONSTANT(BLOCKSIZE=T::BLOCKSIZE)</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span> </div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  <a class="code" href="class_poly1305___base.html">Poly1305_Base</a>() : m_idx(0), m_used(<span class="keyword">true</span>) {}</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span> </div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  <span class="keywordtype">void</span> <a class="code" href="class_simple_keying_interface.html#ae576137a46ca56005e82f1505cf3cccc">Resynchronize</a> (<span class="keyword">const</span> byte *iv, <span class="keywordtype">int</span> ivLength=-1);</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  <span class="keywordtype">void</span> <a class="code" href="class_simple_keying_interface.html#ac8277d1517add6fd455ca576bee57fe2">GetNextIV</a> (<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &rng, byte *iv);</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="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> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &params);</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  <span class="keywordtype">void</span> <a class="code" href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5">Update</a>(<span class="keyword">const</span> byte *input, <span class="keywordtype">size_t</span> length);</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  <span class="keywordtype">void</span> <a class="code" href="class_hash_transformation.html#a590ecda344aa0fb045abf42ec08823b2">TruncatedFinal</a>(byte *mac, <span class="keywordtype">size_t</span> size);</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <span class="keywordtype">void</span> <a class="code" href="class_hash_transformation.html#a92752eebac10497211d7a065faba8725">Restart</a>();</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span> </div><div class="line"><a name="l00080"></a><span class="lineno"><a class="line" href="class_poly1305___base.html#ac7355133d6eef88697c931c5d46e0016"> 80</a></span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_poly1305___base.html#ac7355133d6eef88697c931c5d46e0016">BlockSize</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> BLOCKSIZE;}</div><div class="line"><a name="l00081"></a><span class="lineno"><a class="line" href="class_poly1305___base.html#a18a6d6100a2283a045e8865a7e2be129"> 81</a></span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_poly1305___base.html#a18a6d6100a2283a045e8865a7e2be129">DigestSize</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> DIGESTSIZE;}</div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span> </div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span> <span class="keyword">protected</span>:</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  <span class="keywordtype">void</span> HashBlocks(<span class="keyword">const</span> byte *input, <span class="keywordtype">size_t</span> length, word32 padbit);</div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  <span class="keywordtype">void</span> HashFinal(byte *mac, <span class="keywordtype">size_t</span> length);</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="keyword">typename</span> T::Encryption m_cipher;</div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span> </div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  <span class="comment">// Accumulated hash, clamped r-key, and encrypted nonce</span></div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  <a class="code" href="class_fixed_size_aligned_sec_block.html">FixedSizeAlignedSecBlock<word32, 5></a> m_h;</div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  <a class="code" href="class_fixed_size_aligned_sec_block.html">FixedSizeAlignedSecBlock<word32, 4></a> m_r;</div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  <a class="code" href="class_fixed_size_aligned_sec_block.html">FixedSizeAlignedSecBlock<word32, 4></a> m_n;</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span> </div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  <span class="comment">// Accumulated message bytes and index</span></div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  <a class="code" href="class_fixed_size_aligned_sec_block.html">FixedSizeAlignedSecBlock<byte, BLOCKSIZE></a> m_acc, m_nk;</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  <span class="keywordtype">size_t</span> m_idx;</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span> </div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  <span class="comment">// Track nonce reuse; assert in debug but continue</span></div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  <span class="keywordtype">bool</span> m_used;</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span> };</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span> <span class="comment"></span></div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span> <span class="comment">/// \brief Poly1305 message authentication code</span></div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span> <span class="comment">/// \tparam T class derived from BlockCipherDocumentation with 16-byte key and 16-byte blocksize</span></div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span> <span class="comment">/// \details Poly1305-AES is a state-of-the-art message-authentication code suitable for a wide</span></div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span> <span class="comment">/// variety of applications. Poly1305-AES computes a 16-byte authenticator of a variable-length</span></div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span> <span class="comment">/// message, using a 16-byte AES key, a 16-byte additional key, and a 16-byte nonce.</span></div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span> <span class="comment">/// \details Each message must use a unique security context, which means either the key or nonce</span></div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span> <span class="comment">/// must be changed after each message. It can be accomplished in one of two ways. First, you</span></div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span> <span class="comment">/// can create a new Poly1305 object with a key and nonce each time its needed.</span></div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span> <span class="comment">/// <pre> SecByteBlock key(32), nonce(16);</span></div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span> <span class="comment">/// prng.GenerateBlock(key, key.size());</span></div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span> <span class="comment">/// prng.GenerateBlock(nonce, nonce.size());</span></div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span> <span class="comment">///</span></div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span> <span class="comment">/// Poly1305<AES> poly1305(key, key.size(), nonce, nonce.size());</span></div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span> <span class="comment">/// poly1305.Update(...);</span></div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span> <span class="comment">/// poly1305.Final(...);</pre></span></div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span> <span class="comment">///</span></div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span> <span class="comment">/// \details Second, you can create a Poly1305 object, reuse the key, and set a fresh nonce</span></div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span> <span class="comment">/// for each message. The second and subsequent nonces can be generated directly using a</span></div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span> <span class="comment">/// RandomNumberGenerator() derived class; or it can be generated using GetNextIV().</span></div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span> <span class="comment">/// <pre> SecByteBlock key(32), nonce(16);</span></div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span> <span class="comment">/// prng.GenerateBlock(key, key.size());</span></div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span> <span class="comment">/// prng.GenerateBlock(nonce, nonce.size());</span></div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span> <span class="comment">///</span></div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span> <span class="comment">/// // First message</span></div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span> <span class="comment">/// Poly1305<AES> poly1305(key, key.size());</span></div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span> <span class="comment">/// poly1305.Resynchronize(nonce);</span></div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span> <span class="comment">/// poly1305.Update(...);</span></div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span> <span class="comment">/// poly1305.Final(...);</span></div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span> <span class="comment">///</span></div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span> <span class="comment">/// // Second message</span></div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span> <span class="comment">/// poly1305.GetNextIV(prng, nonce);</span></div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span> <span class="comment">/// poly1305.Resynchronize(nonce);</span></div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span> <span class="comment">/// poly1305.Update(...);</span></div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span> <span class="comment">/// poly1305.Final(...);</span></div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span> <span class="comment">/// ...</pre></span></div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span> <span class="comment">/// \warning The Poly1305 class does not enforce a fresh nonce for each message. The source code</span></div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span> <span class="comment">/// will assert in debug builds to alert of nonce reuse. No action is taken in release builds.</span></div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span> <span class="comment">/// \sa Daniel J. Bernstein <A HREF="http://cr.yp.to/mac/poly1305-20050329.pdf">The Poly1305-AES</span></div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span> <span class="comment">/// Message-Authentication Code (20050329)</A> and Andy Polyakov <A</span></div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span> <span class="comment">/// HREF="http://www.openssl.org/blog/blog/2016/02/15/poly1305-revised/">Poly1305 Revised</A></span></div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span> <span class="comment">/// \since Crypto++ 6.0</span></div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span> <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> T></div><div class="line"><a name="l00144"></a><span class="lineno"><a class="line" href="class_poly1305.html"> 144</a></span> <span class="keyword">class </span><a class="code" href="class_poly1305.html">Poly1305</a> : <span class="keyword">public</span> <a class="code" href="class_message_authentication_code_final.html">MessageAuthenticationCodeFinal</a><Poly1305_Base<T> ></div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span> {</div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span> <span class="keyword">public</span>:</div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=<a class="code" href="class_poly1305___base.html">Poly1305_Base<T>::DEFAULT_KEYLENGTH</a>)</div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span> </div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  <span class="comment">/// \brief Construct a Poly1305</span></div><div class="line"><a name="l00150"></a><span class="lineno"><a class="line" href="class_poly1305.html#aed19bb11176c25211135ba5a318cdb58"> 150</a></span> <span class="comment"></span> <a class="code" href="class_poly1305.html">Poly1305</a>() {}</div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span> <span class="comment"></span></div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span> <span class="comment"> /// \brief Construct a Poly1305</span></div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span> <span class="comment"> /// \param key a byte array used to key the cipher</span></div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span> <span class="comment"> /// \param keyLength the size of the byte array, in bytes</span></div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span> <span class="comment"> /// \param nonce a byte array used to key the cipher</span></div><div class="line"><a name="l00156"></a><span class="lineno"> 156</span> <span class="comment"> /// \param nonceLength the size of the byte array, in bytes</span></div><div class="line"><a name="l00157"></a><span class="lineno"> 157</span> <span class="comment"> /// \details key is the 32-byte key composed of the 16-byte AES key and the 16 additional key</span></div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span> <span class="comment"> /// bytes used for <tt>r</tt>.</span></div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span> <span class="comment"> /// \details Each message requires a unique security context. You can use GetNextIV() and</span></div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span> <span class="comment"> /// Resynchronize() to set a new nonce under a key for a message.</span></div><div class="line"><a name="l00161"></a><span class="lineno"><a class="line" href="class_poly1305.html#a6ff16963ec595fc4985f7106497ebe73"> 161</a></span> <span class="comment"></span> <a class="code" href="class_poly1305.html#a6ff16963ec595fc4985f7106497ebe73">Poly1305</a>(<span class="keyword">const</span> byte *key, <span class="keywordtype">size_t</span> keyLength=DEFAULT_KEYLENGTH, <span class="keyword">const</span> byte *nonce=NULLPTR, <span class="keywordtype">size_t</span> nonceLength=0)</div><div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  {this-><a class="code" href="class_simple_keying_interface.html#adf3c29b3ef3af74788a58c7c49887fd7">SetKey</a>(key, keyLength, <a class="code" href="algparam_8h.html#aa13eee74de98cf8aaa7e83f4fae7f28b">MakeParameters</a>(<a class="code" href="namespace_name.html#a9b6839240a8bdf1f5bcbebf1866f4733">Name::IV</a>(), <a class="code" href="class_const_byte_array_parameter.html">ConstByteArrayParameter</a>(nonce, nonceLength)));}</div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span> };</div><div class="line"><a name="l00164"></a><span class="lineno"> 164</span> </div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span> NAMESPACE_END</div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span> </div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span> <span class="preprocessor">#endif // CRYPTOPP_POLY1305_H</span></div><div class="ttc" id="class_const_byte_array_parameter_html"><div class="ttname"><a href="class_const_byte_array_parameter.html">ConstByteArrayParameter</a></div><div class="ttdoc">Used to pass byte array input as part of a NameValuePairs object. </div><div class="ttdef"><b>Definition:</b> <a href="algparam_8h_source.html#l00020">algparam.h:20</a></div></div> <div class="ttc" id="argnames_8h_html"><div class="ttname"><a href="argnames_8h.html">argnames.h</a></div><div class="ttdoc">Standard names for retrieving values by name when working with NameValuePairs. </div></div> <div class="ttc" id="class_message_authentication_code_html"><div class="ttname"><a href="class_message_authentication_code.html">MessageAuthenticationCode</a></div><div class="ttdoc">Interface for message authentication codes. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l01245">cryptlib.h:1245</a></div></div> <div class="ttc" id="class_poly1305___base_html"><div class="ttname"><a href="class_poly1305___base.html">Poly1305_Base</a></div><div class="ttdoc">Poly1305 message authentication code base class. </div><div class="ttdef"><b>Definition:</b> <a href="poly1305_8h_source.html#l00059">poly1305.h:59</a></div></div> <div class="ttc" id="class_fixed_key_length_html"><div class="ttname"><a href="class_fixed_key_length.html">FixedKeyLength</a></div><div class="ttdoc">Inherited by keyed algorithms with fixed key length. </div><div class="ttdef"><b>Definition:</b> <a href="seckey_8h_source.html#l00147">seckey.h:147</a></div></div> <div class="ttc" id="algparam_8h_html"><div class="ttname"><a href="algparam_8h.html">algparam.h</a></div><div class="ttdoc">Classes for working with NameValuePairs. </div></div> <div class="ttc" id="class_simple_keying_interface_html_adf3c29b3ef3af74788a58c7c49887fd7"><div class="ttname"><a href="class_simple_keying_interface.html#adf3c29b3ef3af74788a58c7c49887fd7">SimpleKeyingInterface::SetKey</a></div><div class="ttdeci">virtual void SetKey(const byte *key, size_t length, const NameValuePairs &params=g_nullNameValuePairs)</div><div class="ttdoc">Sets or reset the key of this object. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8cpp_source.html#l00064">cryptlib.cpp:64</a></div></div> <div class="ttc" id="class_hash_transformation_html_a590ecda344aa0fb045abf42ec08823b2"><div class="ttname"><a href="class_hash_transformation.html#a590ecda344aa0fb045abf42ec08823b2">HashTransformation::TruncatedFinal</a></div><div class="ttdeci">virtual void TruncatedFinal(byte *digest, size_t digestSize)=0</div><div class="ttdoc">Computes the hash of the current message. </div></div> <div class="ttc" id="class_poly1305___base_html_ac7355133d6eef88697c931c5d46e0016"><div class="ttname"><a href="class_poly1305___base.html#ac7355133d6eef88697c931c5d46e0016">Poly1305_Base::BlockSize</a></div><div class="ttdeci">unsigned int BlockSize() const</div><div class="ttdoc">Provides the block size of the compression function. </div><div class="ttdef"><b>Definition:</b> <a href="poly1305_8h_source.html#l00080">poly1305.h:80</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_random_number_generator_html"><div class="ttname"><a href="class_random_number_generator.html">RandomNumberGenerator</a></div><div class="ttdoc">Interface for random number generators. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l01330">cryptlib.h:1330</a></div></div> <div class="ttc" id="class_message_authentication_code_final_html"><div class="ttname"><a href="class_message_authentication_code_final.html">MessageAuthenticationCodeFinal</a></div><div class="ttdoc">Provides class member functions to key a message authentication code. </div><div class="ttdef"><b>Definition:</b> <a href="seckey_8h_source.html#l00392">seckey.h:392</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="algparam_8h_html_aa13eee74de98cf8aaa7e83f4fae7f28b"><div class="ttname"><a href="algparam_8h.html#aa13eee74de98cf8aaa7e83f4fae7f28b">MakeParameters</a></div><div class="ttdeci">AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)</div><div class="ttdoc">Create an object that implements NameValuePairs. </div><div class="ttdef"><b>Definition:</b> <a href="algparam_8h_source.html#l00502">algparam.h:502</a></div></div> <div class="ttc" id="class_hash_transformation_html_a92752eebac10497211d7a065faba8725"><div class="ttname"><a href="class_hash_transformation.html#a92752eebac10497211d7a065faba8725">HashTransformation::Restart</a></div><div class="ttdeci">virtual void Restart()</div><div class="ttdoc">Restart the hash. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l01100">cryptlib.h:1100</a></div></div> <div class="ttc" id="seckey_8h_html"><div class="ttname"><a href="seckey_8h.html">seckey.h</a></div><div class="ttdoc">Classes and functions for implementing secret key algorithms. </div></div> <div class="ttc" id="class_simple_keying_interface_html_ae576137a46ca56005e82f1505cf3cccc"><div class="ttname"><a href="class_simple_keying_interface.html#ae576137a46ca56005e82f1505cf3cccc">SimpleKeyingInterface::Resynchronize</a></div><div class="ttdeci">virtual void Resynchronize(const byte *iv, int ivLength=-1)</div><div class="ttdoc">Resynchronize with an IV. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l00736">cryptlib.h:736</a></div></div> <div class="ttc" id="misc_8h_html_a6b378b1b9b2d4654cc852c088742ba70"><div class="ttname"><a href="misc_8h.html#a6b378b1b9b2d4654cc852c088742ba70">CRYPTOPP_COMPILE_ASSERT</a></div><div class="ttdeci">#define CRYPTOPP_COMPILE_ASSERT(expr)</div><div class="ttdoc">Compile time assertion. </div><div class="ttdef"><b>Definition:</b> <a href="misc_8h_source.html#l00144">misc.h:144</a></div></div> <div class="ttc" id="class_fixed_size_aligned_sec_block_html"><div class="ttname"><a href="class_fixed_size_aligned_sec_block.html">FixedSizeAlignedSecBlock< word32, 5 ></a></div></div> <div class="ttc" id="class_poly1305_html"><div class="ttname"><a href="class_poly1305.html">Poly1305</a></div><div class="ttdoc">Poly1305 message authentication code. </div><div class="ttdef"><b>Definition:</b> <a href="poly1305_8h_source.html#l00144">poly1305.h:144</a></div></div> <div class="ttc" id="namespace_name_html_a9b6839240a8bdf1f5bcbebf1866f4733"><div class="ttname"><a href="namespace_name.html#a9b6839240a8bdf1f5bcbebf1866f4733">Name::IV</a></div><div class="ttdeci">const char * IV()</div><div class="ttdoc">ConstByteArrayParameter, also accepts const byte * for backwards compatibility. </div><div class="ttdef"><b>Definition:</b> <a href="argnames_8h_source.html#l00021">argnames.h:21</a></div></div> <div class="ttc" id="class_poly1305___base_html_a18a6d6100a2283a045e8865a7e2be129"><div class="ttname"><a href="class_poly1305___base.html#a18a6d6100a2283a045e8865a7e2be129">Poly1305_Base::DigestSize</a></div><div class="ttdeci">unsigned int DigestSize() const</div><div class="ttdoc">Provides the digest size of the hash. </div><div class="ttdef"><b>Definition:</b> <a href="poly1305_8h_source.html#l00081">poly1305.h:81</a></div></div> <div class="ttc" id="class_poly1305_html_a6ff16963ec595fc4985f7106497ebe73"><div class="ttname"><a href="class_poly1305.html#a6ff16963ec595fc4985f7106497ebe73">Poly1305::Poly1305</a></div><div class="ttdeci">Poly1305(const byte *key, size_t keyLength=DEFAULT_KEYLENGTH, const byte *nonce=NULL, size_t nonceLength=0)</div><div class="ttdoc">Construct a Poly1305. </div><div class="ttdef"><b>Definition:</b> <a href="poly1305_8h_source.html#l00161">poly1305.h:161</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_simple_keying_interface_html_ac8277d1517add6fd455ca576bee57fe2"><div class="ttname"><a href="class_simple_keying_interface.html#ac8277d1517add6fd455ca576bee57fe2">SimpleKeyingInterface::GetNextIV</a></div><div class="ttdeci">virtual void GetNextIV(RandomNumberGenerator &rng, byte *iv)</div><div class="ttdoc">Retrieves a secure IV for the next message. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8cpp_source.html#l00142">cryptlib.cpp:142</a></div></div> <div class="ttc" id="class_hash_transformation_html_aafabefaf445b65d3ba0d8e1c0294afe5"><div class="ttname"><a href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5">HashTransformation::Update</a></div><div class="ttdeci">virtual void Update(const byte *input, size_t length)=0</div><div class="ttdoc">Updates a hash with additional input. </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:59 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>