<!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++: panama.h 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>panama.h</h1> </div> </div> <div class="contents"> <div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef CRYPTOPP_PANAMA_H</span> <a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_PANAMA_H</span> <a name="l00003"></a>00003 <span class="preprocessor"></span> <a name="l00004"></a>00004 <span class="preprocessor">#include "<a class="code" href="strciphr_8h.html">strciphr.h</a>"</span> <a name="l00005"></a>00005 <span class="preprocessor">#include "iterhash.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 <span class="comment">/// base class, do not use directly</span> <a name="l00010"></a>00010 <span class="comment"></span>template <class B> <a name="l00011"></a><a class="code" href="class_panama.html">00011</a> class CRYPTOPP_NO_VTABLE <a class="code" href="class_panama.html" title="base class, do not use directly">Panama</a> <a name="l00012"></a>00012 { <a name="l00013"></a>00013 <span class="keyword">public</span>: <a name="l00014"></a>00014 <span class="keywordtype">void</span> Reset(); <a name="l00015"></a>00015 <span class="keywordtype">void</span> Iterate(<span class="keywordtype">size_t</span> count, <span class="keyword">const</span> word32 *p=NULL, word32 *z=NULL, <span class="keyword">const</span> word32 *y=NULL); <a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="keyword">protected</span>: <a name="l00018"></a>00018 <span class="keyword">typedef</span> word32 Stage[8]; <a name="l00019"></a>00019 CRYPTOPP_CONSTANT(STAGES = 32) <a name="l00020"></a>00020 <a name="l00021"></a>00021 <a class="code" href="class_fixed_size_aligned_sec_block.html">FixedSizeAlignedSecBlock<word32, 20 + 8*32></a> m_state; <a name="l00022"></a>00022 }; <a name="l00023"></a>00023 <a name="l00024"></a>00024 <span class="keyword">namespace </span>Weak {<span class="comment"></span> <a name="l00025"></a>00025 <span class="comment">/// <a href="http://www.weidai.com/scan-mirror/md.html#Panama">Panama Hash</a></span> <a name="l00026"></a>00026 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> B = LittleEndian> <a name="l00027"></a><a class="code" href="class_weak_1_1_panama_hash.html">00027</a> <span class="keyword">class </span><a class="code" href="class_weak_1_1_panama_hash.html" title="Panama Hash">PanamaHash</a> : <span class="keyword">protected</span> <a class="code" href="class_panama.html" title="base class, do not use directly">Panama</a><B>, <span class="keyword">public</span> <a class="code" href="class_algorithm_impl.html" title="_">AlgorithmImpl</a><IteratedHash<word32, NativeByteOrder, 32>, PanamaHash<B> > <a name="l00028"></a>00028 { <a name="l00029"></a>00029 <span class="keyword">public</span>: <a name="l00030"></a>00030 CRYPTOPP_CONSTANT(DIGESTSIZE = 32) <a name="l00031"></a>00031 <a class="code" href="class_weak_1_1_panama_hash.html" title="Panama Hash">PanamaHash</a>() {<a class="code" href="class_panama.html" title="base class, do not use directly">Panama<B>::Reset</a>();} <a name="l00032"></a><a class="code" href="class_weak_1_1_panama_hash.html#abd1249e41e1ab953239fb57221a08bde">00032</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_weak_1_1_panama_hash.html#abd1249e41e1ab953239fb57221a08bde" title="size of the hash/digest/MAC returned by Final()">DigestSize</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> DIGESTSIZE;} <a name="l00033"></a>00033 <span class="keywordtype">void</span> <a class="code" href="class_weak_1_1_panama_hash.html#af4d1ab27a1cebb1857ba24901b30b3b6" title="truncated version of Final()">TruncatedFinal</a>(byte *hash, <span class="keywordtype">size_t</span> size); <a name="l00034"></a>00034 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * StaticAlgorithmName() {<span class="keywordflow">return</span> B::ToEnum() == BIG_ENDIAN_ORDER ? <span class="stringliteral">"Panama-BE"</span> : <span class="stringliteral">"Panama-LE"</span>;} <a name="l00035"></a>00035 <a name="l00036"></a>00036 <span class="keyword">protected</span>: <a name="l00037"></a>00037 <span class="keywordtype">void</span> Init() {<a class="code" href="class_panama.html" title="base class, do not use directly">Panama<B>::Reset</a>();} <a name="l00038"></a>00038 <span class="keywordtype">void</span> HashEndianCorrectedBlock(<span class="keyword">const</span> word32 *data) {this->Iterate(1, data);} <span class="comment">// push</span> <a name="l00039"></a>00039 <span class="keywordtype">size_t</span> HashMultipleBlocks(<span class="keyword">const</span> word32 *input, <span class="keywordtype">size_t</span> length); <a name="l00040"></a>00040 word32* StateBuf() {<span class="keywordflow">return</span> NULL;} <a name="l00041"></a>00041 }; <a name="l00042"></a>00042 } <a name="l00043"></a>00043 <span class="comment"></span> <a name="l00044"></a>00044 <span class="comment">//! MAC construction using a hermetic hash function</span> <a name="l00045"></a>00045 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> T_Hash, <span class="keyword">class</span> T_Info = T_Hash> <a name="l00046"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html">00046</a> <span class="keyword">class </span><a class="code" href="class_hermetic_hash_function_m_a_c.html" title="MAC construction using a hermetic hash function.">HermeticHashFunctionMAC</a> : <span class="keyword">public</span> <a class="code" href="class_algorithm_impl.html" title="_">AlgorithmImpl</a><SimpleKeyingInterfaceImpl<TwoBases<MessageAuthenticationCode, VariableKeyLength<32, 0, INT_MAX> > >, T_Info> <a name="l00047"></a>00047 { <a name="l00048"></a>00048 <span class="keyword">public</span>: <a name="l00049"></a>00049 <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" title="interface for retrieving values given their names">NameValuePairs</a> &params) <a name="l00050"></a>00050 { <a name="l00051"></a>00051 m_key.<a class="code" href="class_sec_block.html#a2cf5dc5e31c63eb927f935af6104f36a" title="set contents and size">Assign</a>(key, length); <a name="l00052"></a>00052 <a class="code" href="class_hermetic_hash_function_m_a_c.html#a7d2ca6328f5d859a3dcec39240aa700f" title="discard the current state, and restart with a new message">Restart</a>(); <a name="l00053"></a>00053 } <a name="l00054"></a>00054 <a name="l00055"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html#a7d2ca6328f5d859a3dcec39240aa700f">00055</a> <span class="keywordtype">void</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html#a7d2ca6328f5d859a3dcec39240aa700f" title="discard the current state, and restart with a new message">Restart</a>() <a name="l00056"></a>00056 { <a name="l00057"></a>00057 m_hash.Restart(); <a name="l00058"></a>00058 m_keyed = <span class="keyword">false</span>; <a name="l00059"></a>00059 } <a name="l00060"></a>00060 <a name="l00061"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html#ad724a2082e81c4174fdd877030ead35b">00061</a> <span class="keywordtype">void</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html#ad724a2082e81c4174fdd877030ead35b" title="process more input">Update</a>(<span class="keyword">const</span> byte *input, <span class="keywordtype">size_t</span> length) <a name="l00062"></a>00062 { <a name="l00063"></a>00063 <span class="keywordflow">if</span> (!m_keyed) <a name="l00064"></a>00064 KeyHash(); <a name="l00065"></a>00065 m_hash.Update(input, length); <a name="l00066"></a>00066 } <a name="l00067"></a>00067 <a name="l00068"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html#ae7fb80814d9ed73148a63a9f33890422">00068</a> <span class="keywordtype">void</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html#ae7fb80814d9ed73148a63a9f33890422" title="truncated version of Final()">TruncatedFinal</a>(byte *digest, <span class="keywordtype">size_t</span> digestSize) <a name="l00069"></a>00069 { <a name="l00070"></a>00070 <span class="keywordflow">if</span> (!m_keyed) <a name="l00071"></a>00071 KeyHash(); <a name="l00072"></a>00072 m_hash.TruncatedFinal(digest, digestSize); <a name="l00073"></a>00073 m_keyed = <span class="keyword">false</span>; <a name="l00074"></a>00074 } <a name="l00075"></a>00075 <a name="l00076"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html#ab6797b4705656e5ca0dcf1e750d3daca">00076</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html#ab6797b4705656e5ca0dcf1e750d3daca" title="size of the hash/digest/MAC returned by Final()">DigestSize</a>()<span class="keyword"> const</span> <a name="l00077"></a>00077 <span class="keyword"> </span>{<span class="keywordflow">return</span> m_hash.DigestSize();} <a name="l00078"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html#a59b2e0fd6b4a34d600e32ff931bd6d8f">00078</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html#a59b2e0fd6b4a34d600e32ff931bd6d8f" title="block size of underlying compression function, or 0 if not block based">BlockSize</a>()<span class="keyword"> const</span> <a name="l00079"></a>00079 <span class="keyword"> </span>{<span class="keywordflow">return</span> m_hash.BlockSize();} <a name="l00080"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html#aceabbeab826dcbd76df0035a41d93ddc">00080</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html#aceabbeab826dcbd76df0035a41d93ddc" title="input to Update() should have length a multiple of this for optimal speed">OptimalBlockSize</a>()<span class="keyword"> const</span> <a name="l00081"></a>00081 <span class="keyword"> </span>{<span class="keywordflow">return</span> m_hash.OptimalBlockSize();} <a name="l00082"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html#adb0185f06080a3325a256e80986de683">00082</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html#adb0185f06080a3325a256e80986de683" title="returns how input should be aligned for optimal performance">OptimalDataAlignment</a>()<span class="keyword"> const</span> <a name="l00083"></a>00083 <span class="keyword"> </span>{<span class="keywordflow">return</span> m_hash.OptimalDataAlignment();} <a name="l00084"></a>00084 <a name="l00085"></a>00085 <span class="keyword">protected</span>: <a name="l00086"></a>00086 <span class="keywordtype">void</span> KeyHash() <a name="l00087"></a>00087 { <a name="l00088"></a>00088 m_hash.Update(m_key, m_key.size()); <a name="l00089"></a>00089 m_keyed = <span class="keyword">true</span>; <a name="l00090"></a>00090 } <a name="l00091"></a>00091 <a name="l00092"></a>00092 T_Hash m_hash; <a name="l00093"></a>00093 <span class="keywordtype">bool</span> m_keyed; <a name="l00094"></a>00094 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> m_key; <a name="l00095"></a>00095 }; <a name="l00096"></a>00096 <a name="l00097"></a>00097 <span class="keyword">namespace </span>Weak {<span class="comment"></span> <a name="l00098"></a>00098 <span class="comment">/// Panama MAC</span> <a name="l00099"></a>00099 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> B = LittleEndian> <a name="l00100"></a><a class="code" href="class_weak_1_1_panama_m_a_c.html">00100</a> <span class="keyword">class </span><a class="code" href="class_weak_1_1_panama_m_a_c.html" title="Panama MAC.">PanamaMAC</a> : <span class="keyword">public</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html" title="MAC construction using a hermetic hash function.">HermeticHashFunctionMAC</a><PanamaHash<B> > <a name="l00101"></a>00101 { <a name="l00102"></a>00102 <span class="keyword">public</span>: <a name="l00103"></a>00103 <a class="code" href="class_weak_1_1_panama_m_a_c.html" title="Panama MAC.">PanamaMAC</a>() {} <a name="l00104"></a>00104 <a class="code" href="class_weak_1_1_panama_m_a_c.html" title="Panama MAC.">PanamaMAC</a>(<span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length) <a name="l00105"></a>00105 {this-><a class="code" href="class_simple_keying_interface.html#adf3c29b3ef3af74788a58c7c49887fd7" title="set or reset the key of this object">SetKey</a>(key, length);} <a name="l00106"></a>00106 }; <a name="l00107"></a>00107 } <a name="l00108"></a>00108 <span class="comment"></span> <a name="l00109"></a>00109 <span class="comment">//! algorithm info</span> <a name="l00110"></a>00110 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> B> <a name="l00111"></a><a class="code" href="struct_panama_cipher_info.html">00111</a> <span class="keyword">struct </span><a class="code" href="struct_panama_cipher_info.html" title="algorithm info">PanamaCipherInfo</a> : <span class="keyword">public</span> <a class="code" href="class_fixed_key_length.html" title="to be inherited by keyed algorithms with fixed key length">FixedKeyLength</a><32, SimpleKeyingInterface::UNIQUE_IV, 32> <a name="l00112"></a>00112 { <a name="l00113"></a>00113 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * StaticAlgorithmName() {<span class="keywordflow">return</span> B::ToEnum() == BIG_ENDIAN_ORDER ? <span class="stringliteral">"Panama-BE"</span> : <span class="stringliteral">"Panama-LE"</span>;} <a name="l00114"></a>00114 }; <a name="l00115"></a>00115 <span class="comment"></span> <a name="l00116"></a>00116 <span class="comment">//! _</span> <a name="l00117"></a>00117 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> B> <a name="l00118"></a><a class="code" href="class_panama_cipher_policy.html">00118</a> <span class="keyword">class </span><a class="code" href="class_panama_cipher_policy.html" title="_">PanamaCipherPolicy</a> : <span class="keyword">public</span> <a class="code" href="struct_additive_cipher_concrete_policy.html">AdditiveCipherConcretePolicy</a><word32, 8>, <a name="l00119"></a>00119 <span class="keyword">public</span> <a class="code" href="struct_panama_cipher_info.html" title="algorithm info">PanamaCipherInfo</a><B>, <a name="l00120"></a>00120 <span class="keyword">protected</span> <a class="code" href="class_panama.html" title="base class, do not use directly">Panama</a><B> <a name="l00121"></a>00121 { <a name="l00122"></a>00122 <span class="keyword">protected</span>: <a name="l00123"></a>00123 <span class="keywordtype">void</span> CipherSetKey(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &params, <span class="keyword">const</span> byte *key, <span class="keywordtype">size_t</span> length); <a name="l00124"></a>00124 <span class="keywordtype">void</span> OperateKeystream(KeystreamOperation operation, byte *output, <span class="keyword">const</span> byte *input, <span class="keywordtype">size_t</span> iterationCount); <a name="l00125"></a>00125 <span class="keywordtype">bool</span> CipherIsRandomAccess()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">false</span>;} <a name="l00126"></a>00126 <span class="keywordtype">void</span> CipherResynchronize(byte *keystreamBuffer, <span class="keyword">const</span> byte *iv, <span class="keywordtype">size_t</span> length); <a name="l00127"></a>00127 <span class="preprocessor">#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X64</span> <a name="l00128"></a>00128 <span class="preprocessor"></span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> GetAlignment() <span class="keyword">const</span>; <a name="l00129"></a>00129 <span class="preprocessor">#endif</span> <a name="l00130"></a>00130 <span class="preprocessor"></span> <a name="l00131"></a>00131 <a class="code" href="class_fixed_size_sec_block.html">FixedSizeSecBlock<word32, 8></a> m_key; <a name="l00132"></a>00132 }; <a name="l00133"></a>00133 <span class="comment"></span> <a name="l00134"></a>00134 <span class="comment">//! <a href="http://www.cryptolounge.org/wiki/PANAMA">Panama Stream Cipher</a></span> <a name="l00135"></a>00135 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> B = LittleEndian> <a name="l00136"></a><a class="code" href="struct_panama_cipher.html">00136</a> <span class="keyword">struct </span><a class="code" href="struct_panama_cipher.html" title="Panama Stream Cipher">PanamaCipher</a> : <span class="keyword">public</span> <a class="code" href="struct_panama_cipher_info.html" title="algorithm info">PanamaCipherInfo</a><B>, <span class="keyword">public</span> <a class="code" href="struct_symmetric_cipher_documentation.html" title="Each class derived from this one defines two types, Encryption and Decryption, both of which implemen...">SymmetricCipherDocumentation</a> <a name="l00137"></a>00137 { <a name="l00138"></a><a class="code" href="struct_panama_cipher.html#adbc52f2d09bbd059b9a50823afa0576a">00138</a> <span class="keyword">typedef</span> <a class="code" href="class_symmetric_cipher_final.html" title="_">SymmetricCipherFinal<ConcretePolicyHolder<PanamaCipherPolicy<B></a>, <a class="code" href="class_additive_cipher_template.html">AdditiveCipherTemplate<></a> >, <a class="code" href="struct_panama_cipher_info.html" title="algorithm info">PanamaCipherInfo<B></a> > <a class="code" href="struct_panama_cipher.html#adbc52f2d09bbd059b9a50823afa0576a" title="implements the SymmetricCipher interface">Encryption</a>; <a name="l00139"></a><a class="code" href="struct_panama_cipher.html#a701cae4cf59e1b12e701ecf71e61a6cb">00139</a> <span class="keyword">typedef</span> <a class="code" href="class_symmetric_cipher_final.html" title="_">Encryption</a> <a class="code" href="struct_panama_cipher.html#a701cae4cf59e1b12e701ecf71e61a6cb" title="implements the SymmetricCipher interface">Decryption</a>; <a name="l00140"></a>00140 }; <a name="l00141"></a>00141 <a name="l00142"></a>00142 NAMESPACE_END <a name="l00143"></a>00143 <a name="l00144"></a>00144 <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>