Sophie

Sophie

distrib > Mandriva > 10.2 > i586 > media > contrib > by-pkgid > 7457b841ac8136d3a1a9d3d960c5252e > files > 1344

libcryptopp-doc-5.2.1-2mdk.i586.rpm

<!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.cpp 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&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div>
<h1>panama.cpp</h1><pre class="fragment"><div>00001 <span class="comment">// panama.cpp - written and placed in the public domain by Wei Dai</span>
00002 
00003 <span class="preprocessor">#include "pch.h"</span>
00004 <span class="preprocessor">#include "panama.h"</span>
00005 <span class="preprocessor">#include "misc.h"</span>
00006 
00007 NAMESPACE_BEGIN(CryptoPP)
00008 
00009 template &lt;class B&gt;
00010 <span class="keywordtype">void</span> <a class="code" href="class_panama.html">Panama</a>&lt;B&gt;::Reset()
00011 {
00012         m_bstart = 0;
00013         memset(m_state, 0, m_state.size()*4);
00014 }
00015 
00016 <span class="keyword">template</span> &lt;<span class="keyword">class</span> B&gt;
00017 <span class="keywordtype">void</span> <a class="code" href="class_panama.html">Panama&lt;B&gt;::Iterate</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> count, <span class="keyword">const</span> word32 *p, word32 *z, <span class="keyword">const</span> word32 *y)
00018 {
00019         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bstart = m_bstart;
00020         word32 *<span class="keyword">const</span> a = m_state;
00021 <span class="preprocessor">#define c (a+17)</span>
00022 <span class="preprocessor"></span><span class="preprocessor">#define b ((Stage *)(a+34))</span>
00023 <span class="preprocessor"></span>
00024 <span class="comment">// output</span>
00025 <span class="preprocessor">#define OA(i) z[i] = ConditionalByteReverse(B::ToEnum(), a[i+9])</span>
00026 <span class="preprocessor"></span><span class="preprocessor">#define OX(i) z[i] = y[i] ^ ConditionalByteReverse(B::ToEnum(), a[i+9])</span>
00027 <span class="preprocessor"></span><span class="comment">// buffer update</span>
00028 <span class="preprocessor">#define US(i) {word32 t=b0[i]; b0[i]=ConditionalByteReverse(B::ToEnum(), p[i])^t; b25[(i+6)%8]^=t;}</span>
00029 <span class="preprocessor"></span><span class="preprocessor">#define UL(i) {word32 t=b0[i]; b0[i]=a[i+1]^t; b25[(i+6)%8]^=t;}</span>
00030 <span class="preprocessor"></span><span class="comment">// gamma and pi</span>
00031 <span class="preprocessor">#define GP(i) c[5*i%17] = rotlFixed(a[i] ^ (a[(i+1)%17] | ~a[(i+2)%17]), ((5*i%17)*((5*i%17)+1)/2)%32)</span>
00032 <span class="preprocessor"></span><span class="comment">// theta and sigma</span>
00033 <span class="preprocessor">#define T(i,x) a[i] = c[i] ^ c[(i+1)%17] ^ c[(i+4)%17] ^ x</span>
00034 <span class="preprocessor"></span><span class="preprocessor">#define TS1S(i) T(i+1, ConditionalByteReverse(B::ToEnum(), p[i]))</span>
00035 <span class="preprocessor"></span><span class="preprocessor">#define TS1L(i) T(i+1, b4[i])</span>
00036 <span class="preprocessor"></span><span class="preprocessor">#define TS2(i) T(i+9, b16[i])</span>
00037 <span class="preprocessor"></span>
00038         <span class="keywordflow">while</span> (count--)
00039         {
00040                 <span class="keywordflow">if</span> (z)
00041                 {
00042                         <span class="keywordflow">if</span> (y)
00043                         {
00044                                 OX(0); OX(1); OX(2); OX(3); OX(4); OX(5); OX(6); OX(7);
00045                                 y += 8;
00046                         }
00047                         <span class="keywordflow">else</span>
00048                         {
00049                                 OA(0); OA(1); OA(2); OA(3); OA(4); OA(5); OA(6); OA(7);
00050                         }
00051                         z += 8;
00052                 }
00053 
00054                 word32 *<span class="keyword">const</span> b16 = b[(bstart+16) % STAGES];
00055                 word32 *<span class="keyword">const</span> b4 = b[(bstart+4) % STAGES];
00056         bstart = (bstart + STAGES - 1) % STAGES;
00057                 word32 *<span class="keyword">const</span> b0 = b[bstart];
00058                 word32 *<span class="keyword">const</span> b25 = b[(bstart+25) % STAGES];
00059 
00060 
00061                 <span class="keywordflow">if</span> (p)
00062                 {
00063                         US(0); US(1); US(2); US(3); US(4); US(5); US(6); US(7);
00064                 }
00065                 <span class="keywordflow">else</span>
00066                 {
00067                         UL(0); UL(1); UL(2); UL(3); UL(4); UL(5); UL(6); UL(7);
00068                 }
00069 
00070                 GP(0); GP(1); GP(2); GP(3); GP(4); GP(5); GP(6); GP(7);
00071                 GP(8); GP(9); GP(10); GP(11); GP(12); GP(13); GP(14); GP(15); GP(16);
00072 
00073                 T(0,1);
00074 
00075                 <span class="keywordflow">if</span> (p)
00076                 {
00077                         TS1S(0); TS1S(1); TS1S(2); TS1S(3); TS1S(4); TS1S(5); TS1S(6); TS1S(7);
00078                         p += 8;
00079                 }
00080                 <span class="keywordflow">else</span>
00081                 {
00082                         TS1L(0); TS1L(1); TS1L(2); TS1L(3); TS1L(4); TS1L(5); TS1L(6); TS1L(7);
00083                 }
00084 
00085                 TS2(0); TS2(1); TS2(2); TS2(3); TS2(4); TS2(5); TS2(6); TS2(7);
00086         }
00087         m_bstart = bstart;
00088 }
00089 
00090 <span class="keyword">template</span> &lt;<span class="keyword">class</span> B&gt;
00091 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_panama_hash.html">PanamaHash&lt;B&gt;::HashMultipleBlocks</a>(<span class="keyword">const</span> word32 *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)
00092 {
00093         this-&gt;Iterate(length / this-&gt;BLOCKSIZE, input);
00094         <span class="keywordflow">return</span> length % this-&gt;BLOCKSIZE;
00095 }
00096 
00097 <span class="keyword">template</span> &lt;<span class="keyword">class</span> B&gt;
<a name="l00098"></a><a class="code" href="class_panama_hash.html#_panama_hasha2">00098</a> <span class="keywordtype">void</span> <a class="code" href="class_panama_hash.html">PanamaHash&lt;B&gt;::TruncatedFinal</a>(byte *hash, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size)
00099 {
00100         this-&gt;ThrowIfInvalidTruncatedSize(size);
00101 
00102         PadLastBlock(this-&gt;BLOCKSIZE, 0x01);
00103         
00104         HashEndianCorrectedBlock(this-&gt;m_data);
00105 
00106         this-&gt;Iterate(32);      <span class="comment">// pull</span>
00107 
00108         ConditionalByteReverse(B::ToEnum(), this-&gt;m_state+9, this-&gt;m_state+9, DIGESTSIZE);
00109         memcpy(hash, this-&gt;m_state+9, size);
00110 
00111         this-&gt;<a class="code" href="class_hash_transformation.html#_two_bases_3_01_message_authentication_code_00_01_variable_key_length_3_0132_00_010_00_01_u_i_n_t___m_a_x_01_4_01_4a3">Restart</a>();                <span class="comment">// reinit for next use</span>
00112 }
00113 
00114 <span class="keyword">template</span> &lt;<span class="keyword">class</span> B&gt;
00115 <span class="keywordtype">void</span> <a class="code" href="class_panama_cipher_policy.html">PanamaCipherPolicy&lt;B&gt;::CipherSetKey</a>(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &amp;params, <span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)
00116 {
00117         FixedSizeSecBlock&lt;word32, 8&gt; buf;
00118 
00119         this-&gt;Reset();
00120         memcpy(buf, key, 32);
00121         this-&gt;Iterate(1, buf);
00122         <span class="keywordflow">if</span> (length == 64)
00123                 memcpy(buf, key+32, 32);
00124         <span class="keywordflow">else</span>
00125                 memset(buf, 0, 32);
00126         this-&gt;Iterate(1, buf);
00127 
00128         this-&gt;Iterate(32);
00129 }
00130 
00131 <span class="keyword">template</span> &lt;<span class="keyword">class</span> B&gt;
00132 <span class="keywordtype">void</span> <a class="code" href="class_panama_cipher_policy.html">PanamaCipherPolicy&lt;B&gt;::OperateKeystream</a>(KeystreamOperation operation, byte *output, <span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> iterationCount)
00133 {
00134         this-&gt;Iterate(iterationCount, NULL, (word32 *)output, (<span class="keyword">const</span> word32 *)input);
00135 }
00136 
00137 <span class="keyword">template</span> <span class="keyword">class </span><a class="code" href="class_panama.html">Panama&lt;BigEndian&gt;</a>;
00138 <span class="keyword">template</span> <span class="keyword">class </span><a class="code" href="class_panama.html">Panama&lt;LittleEndian&gt;</a>;
00139 
00140 <span class="keyword">template</span> <span class="keyword">class </span><a class="code" href="class_panama_hash.html">PanamaHash&lt;BigEndian&gt;</a>;
00141 <span class="keyword">template</span> <span class="keyword">class </span><a class="code" href="class_panama_hash.html">PanamaHash&lt;LittleEndian&gt;</a>;
00142 
00143 <span class="keyword">template</span> <span class="keyword">class </span><a class="code" href="class_panama_cipher_policy.html">PanamaCipherPolicy&lt;BigEndian&gt;</a>;
00144 <span class="keyword">template</span> <span class="keyword">class </span><a class="code" href="class_panama_cipher_policy.html">PanamaCipherPolicy&lt;LittleEndian&gt;</a>;
00145 
00146 NAMESPACE_END
</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>