<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Crypto++: panama.h Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.3.7 --> <div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a></div> <h1>panama.h</h1><pre class="fragment"><div>00001 <span class="preprocessor">#ifndef CRYPTOPP_PANAMA_H</span> 00002 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_PANAMA_H</span> 00003 <span class="preprocessor"></span> 00004 <span class="preprocessor">#include "seckey.h"</span> 00005 <span class="preprocessor">#include "secblock.h"</span> 00006 <span class="preprocessor">#include "iterhash.h"</span> 00007 <span class="preprocessor">#include "<a class="code" href="strciphr_8h.html">strciphr.h</a>"</span> 00008 00009 NAMESPACE_BEGIN(CryptoPP) 00010 00011 <span class="comment">/// base class, do not use directly</span> 00012 <span class="comment"></span>template <class B> <a name="l00013"></a><a class="code" href="class_panama.html">00013</a> class CRYPTOPP_NO_VTABLE <a class="code" href="class_panama.html">Panama</a> 00014 { 00015 <span class="keyword">public</span>: 00016 <span class="keywordtype">void</span> Reset(); 00017 <span class="keywordtype">void</span> Iterate(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> count, <span class="keyword">const</span> word32 *p=NULL, word32 *z=NULL, <span class="keyword">const</span> word32 *y=NULL); 00018 00019 <span class="keyword">protected</span>: 00020 <span class="keyword">typedef</span> word32 Stage[8]; 00021 <span class="keyword">enum</span> {STAGES = 32}; 00022 00023 FixedSizeSecBlock<word32, 17*2 + STAGES*sizeof(Stage)> m_state; 00024 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m_bstart; 00025 }; 00026 <span class="comment"></span> 00027 <span class="comment">/// <a href="http://www.weidai.com/scan-mirror/md.html#Panama">Panama Hash</a></span> 00028 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> B = LittleEndian> <a name="l00029"></a><a class="code" href="class_panama_hash.html">00029</a> <span class="keyword">class </span><a class="code" href="class_panama_hash.html">PanamaHash</a> : <span class="keyword">protected</span> <a class="code" href="class_panama.html">Panama</a><B>, <span class="keyword">public</span> <a class="code" href="class_algorithm_impl.html">AlgorithmImpl</a><IteratedHash<word32, NativeByteOrder, 32>, PanamaHash<B> > 00030 { 00031 <span class="keyword">public</span>: 00032 <span class="keyword">enum</span> {DIGESTSIZE = 32}; 00033 <a class="code" href="class_panama_hash.html">PanamaHash</a>() {<a class="code" href="class_panama.html">Panama<B>::Reset</a>();} <a name="l00034"></a><a class="code" href="class_panama_hash.html#_panama_hasha1">00034</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_panama_hash.html#_panama_hasha1">DigestSize</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> DIGESTSIZE;} 00035 <span class="keywordtype">void</span> TruncatedFinal(byte *hash, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size); 00036 <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>;} 00037 00038 <span class="keyword">protected</span>: 00039 <span class="keywordtype">void</span> Init() {<a class="code" href="class_panama.html">Panama<B>::Reset</a>();} 00040 <span class="keywordtype">void</span> HashEndianCorrectedBlock(<span class="keyword">const</span> word32 *data) {this->Iterate(1, data);} <span class="comment">// push</span> 00041 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> HashMultipleBlocks(<span class="keyword">const</span> word32 *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length); 00042 }; 00043 <span class="comment"></span> 00044 <span class="comment">//! MAC construction using a hermetic hash function</span> 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">HermeticHashFunctionMAC</a> : <span class="keyword">public</span> <a class="code" href="class_algorithm_impl.html">AlgorithmImpl</a><SimpleKeyingInterfaceImpl<TwoBases<MessageAuthenticationCode, VariableKeyLength<32, 0, UINT_MAX> > >, T_Info> 00047 { 00048 <span class="keyword">public</span>: <a name="l00049"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html#_hermetic_hash_function_m_a_ca0">00049</a> <span class="keywordtype">void</span> SetKey(<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 = g_nullNameValuePairs) 00050 { 00051 m_key.<a class="code" href="class_sec_block.html#_sec_block_with_hinta17">Assign</a>(key, length); 00052 <a class="code" href="class_hermetic_hash_function_m_a_c.html#_hermetic_hash_function_m_a_ca1">Restart</a>(); 00053 } 00054 <a name="l00055"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html#_hermetic_hash_function_m_a_ca1">00055</a> <span class="keywordtype">void</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html#_hermetic_hash_function_m_a_ca1">Restart</a>() 00056 { 00057 m_hash.Restart(); 00058 m_keyed = <span class="keyword">false</span>; 00059 } 00060 <a name="l00061"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html#_hermetic_hash_function_m_a_ca2">00061</a> <span class="keywordtype">void</span> Update(<span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length) 00062 { 00063 <span class="keywordflow">if</span> (!m_keyed) 00064 KeyHash(); 00065 m_hash.Update(input, length); 00066 } 00067 <a name="l00068"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html#_hermetic_hash_function_m_a_ca3">00068</a> <span class="keywordtype">void</span> TruncatedFinal(byte *digest, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> digestSize) 00069 { 00070 <span class="keywordflow">if</span> (!m_keyed) 00071 KeyHash(); 00072 m_hash.TruncatedFinal(digest, digestSize); 00073 m_keyed = <span class="keyword">false</span>; 00074 } 00075 <a name="l00076"></a><a class="code" href="class_hermetic_hash_function_m_a_c.html#_hermetic_hash_function_m_a_ca4">00076</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html#_hermetic_hash_function_m_a_ca4">DigestSize</a>()<span class="keyword"> const</span> 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#_hermetic_hash_function_m_a_ca5">00078</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html#_hermetic_hash_function_m_a_ca5">BlockSize</a>()<span class="keyword"> const</span> 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#_hermetic_hash_function_m_a_ca6">00080</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html#_hermetic_hash_function_m_a_ca6">OptimalBlockSize</a>()<span class="keyword"> const</span> 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#_hermetic_hash_function_m_a_ca7">00082</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html#_hermetic_hash_function_m_a_ca7">OptimalDataAlignment</a>()<span class="keyword"> const</span> 00083 <span class="keyword"> </span>{<span class="keywordflow">return</span> m_hash.OptimalDataAlignment();} 00084 00085 <span class="keyword">protected</span>: 00086 <span class="keywordtype">void</span> KeyHash() 00087 { 00088 m_hash.Update(m_key, m_key.<a class="code" href="class_sec_block.html#_sec_block_with_hinta15">size</a>()); 00089 m_keyed = <span class="keyword">true</span>; 00090 } 00091 00092 T_Hash m_hash; 00093 <span class="keywordtype">bool</span> m_keyed; 00094 <a class="code" href="class_sec_block.html">SecByteBlock</a> m_key; 00095 }; 00096 <span class="comment"></span> 00097 <span class="comment">/// Panama MAC</span> 00098 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> B = LittleEndian> <a name="l00099"></a><a class="code" href="class_panama_m_a_c.html">00099</a> <span class="keyword">class </span><a class="code" href="class_panama_m_a_c.html">PanamaMAC</a> : <span class="keyword">public</span> <a class="code" href="class_hermetic_hash_function_m_a_c.html">HermeticHashFunctionMAC</a><PanamaHash<B> > 00100 { 00101 <span class="keyword">public</span>: 00102 <a class="code" href="class_panama_m_a_c.html">PanamaMAC</a>() {} 00103 <a class="code" href="class_panama_m_a_c.html">PanamaMAC</a>(<span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length) 00104 {this->SetKey(key, length);} 00105 }; 00106 <span class="comment"></span> 00107 <span class="comment">//! algorithm info</span> 00108 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> B> <a name="l00109"></a><a class="code" href="struct_panama_cipher_info.html">00109</a> <span class="keyword">struct </span><a class="code" href="struct_panama_cipher_info.html">PanamaCipherInfo</a> : <span class="keyword">public</span> <a class="code" href="class_variable_key_length.html">VariableKeyLength</a><32, 32, 64, 32, SimpleKeyingInterface::NOT_RESYNCHRONIZABLE> 00110 { 00111 <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>;} 00112 }; 00113 <span class="comment"></span> 00114 <span class="comment">//! _</span> 00115 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> B> <a name="l00116"></a><a class="code" href="class_panama_cipher_policy.html">00116</a> <span class="keyword">class </span><a class="code" href="class_panama_cipher_policy.html">PanamaCipherPolicy</a> : <span class="keyword">public</span> AdditiveCipherConcretePolicy<word32, 8>, 00117 <span class="keyword">public</span> <a class="code" href="struct_panama_cipher_info.html">PanamaCipherInfo</a><B>, 00118 <span class="keyword">protected</span> <a class="code" href="class_panama.html">Panama</a><B> 00119 { 00120 <span class="keyword">protected</span>: 00121 <span class="keywordtype">void</span> CipherSetKey(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &params, <span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length); 00122 <span class="keywordtype">void</span> OperateKeystream(KeystreamOperation operation, byte *output, <span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> iterationCount); 00123 <span class="keywordtype">bool</span> IsRandomAccess()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">false</span>;} 00124 }; 00125 <span class="comment"></span> 00126 <span class="comment">//! <a href="http://www.weidai.com/scan-mirror/cs.html#Panama">Panama Stream Cipher</a></span> 00127 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> B = LittleEndian> <a name="l00128"></a><a class="code" href="struct_panama_cipher.html">00128</a> <span class="keyword">struct </span><a class="code" href="struct_panama_cipher.html">PanamaCipher</a> : <span class="keyword">public</span> <a class="code" href="struct_panama_cipher_info.html">PanamaCipherInfo</a><B>, <span class="keyword">public</span> <a class="code" href="struct_symmetric_cipher_documentation.html">SymmetricCipherDocumentation</a> 00129 { <a name="l00130"></a><a class="code" href="struct_panama_cipher.html#_panama_cipherw0">00130</a> <span class="keyword">typedef</span> <a class="code" href="class_symmetric_cipher_final.html">SymmetricCipherFinal<ConcretePolicyHolder<PanamaCipherPolicy<B></a>, AdditiveCipherTemplate<> > > <a class="code" href="class_symmetric_cipher_final.html">Encryption</a>; <a name="l00131"></a><a class="code" href="struct_panama_cipher.html#_panama_cipherw1">00131</a> <span class="keyword">typedef</span> <a class="code" href="class_symmetric_cipher_final.html">Encryption</a> <a class="code" href="class_symmetric_cipher_final.html">Decryption</a>; 00132 }; 00133 00134 NAMESPACE_END 00135 00136 <span class="preprocessor">#endif</span> </div></pre><hr size="1"><address style="align: right;"><small>Generated on Sun Nov 7 08:23:58 2004 for Crypto++ by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.7 </small></address> </body> </html>