Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > 07dfcfe50d66c9a48a3c5e6c1693f12a > files > 2423

cryptopp-doc-5.6.1-0.1.svn479.fc13.i686.rpm

<!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++: wake.cpp 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.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;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 class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>wake.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// wake.cpp - written and placed in the public domain by Wei Dai</span>
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="preprocessor">#include &quot;pch.h&quot;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &quot;wake.h&quot;</span>
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 NAMESPACE_BEGIN(CryptoPP)
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 void WAKE_TestInstantiations()
<a name="l00009"></a>00009 {
<a name="l00010"></a>00010         <a class="code" href="class_symmetric_cipher_final.html" title="_">Weak::WAKE_CFB&lt;&gt;::Encryption</a> x1;
<a name="l00011"></a>00011         <a class="code" href="class_symmetric_cipher_final.html" title="_">Weak::WAKE_CFB&lt;&gt;::Decryption</a> x3;
<a name="l00012"></a>00012         <a class="code" href="class_symmetric_cipher_final.html" title="_">WAKE_OFB&lt;&gt;::Encryption</a> x2;
<a name="l00013"></a>00013         <a class="code" href="class_symmetric_cipher.html" title="interface for one direction (encryption or decryption) of a stream cipher or cipher...">WAKE_OFB&lt;&gt;::Decryption</a> x4;
<a name="l00014"></a>00014 }
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="keyword">inline</span> word32 WAKE_Base::M(word32 x, word32 y)
<a name="l00017"></a>00017 {
<a name="l00018"></a>00018         word32 w = x+y;
<a name="l00019"></a>00019         <span class="keywordflow">return</span> (w&gt;&gt;8) ^ t[(byte)w];
<a name="l00020"></a>00020 }
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="keywordtype">void</span> WAKE_Base::GenKey(word32 k0, word32 k1, word32 k2, word32 k3)
<a name="l00023"></a>00023 {
<a name="l00024"></a>00024         <span class="keywordtype">long</span> x, z;
<a name="l00025"></a>00025         <span class="keywordtype">int</span> p ;
<a name="l00026"></a>00026         <span class="keyword">static</span> <span class="keywordtype">long</span> tt[10]= {
<a name="l00027"></a>00027                 0x726a8f3bL,                                                             <span class="comment">// table</span>
<a name="l00028"></a>00028                 0xe69a3b5cL,
<a name="l00029"></a>00029                 0xd3c71fe5L,
<a name="l00030"></a>00030                 0xab3c73d2L,
<a name="l00031"></a>00031                 0x4d3a8eb3L,
<a name="l00032"></a>00032                 0x0396d6e8L,
<a name="l00033"></a>00033                 0x3d4c2f7aL,
<a name="l00034"></a>00034                 0x9ee27cf3L, } ;
<a name="l00035"></a>00035         t[0] = k0;
<a name="l00036"></a>00036         t[1] = k1;
<a name="l00037"></a>00037         t[2] = k2;
<a name="l00038"></a>00038         t[3] = k3;
<a name="l00039"></a>00039         <span class="keywordflow">for</span> (p=4 ; p&lt;256 ; p++)
<a name="l00040"></a>00040         {
<a name="l00041"></a>00041           x=t[p-4]+t[p-1] ;                                        <span class="comment">// fill t</span>
<a name="l00042"></a>00042           t[p]= (x&gt;&gt;3) ^ tt[byte(x&amp;7)] ;
<a name="l00043"></a>00043         }
<a name="l00044"></a>00044 
<a name="l00045"></a>00045         <span class="keywordflow">for</span> (p=0 ; p&lt;23 ; p++)
<a name="l00046"></a>00046                 t[p]+=t[p+89] ;                   <span class="comment">// mix first entries</span>
<a name="l00047"></a>00047         x=t[33] ; z=t[59] | 0x01000001L ;
<a name="l00048"></a>00048         z=z&amp;0xff7fffffL ;
<a name="l00049"></a>00049         <span class="keywordflow">for</span> (p=0 ; p&lt;256 ; p++) {               <span class="comment">//change top byte to</span>
<a name="l00050"></a>00050           x=(x&amp;0xff7fffffL)+z ;                  <span class="comment">// a permutation etc</span>
<a name="l00051"></a>00051           t[p]=(t[p] &amp; 0x00ffffffL) ^ x ; }
<a name="l00052"></a>00052 
<a name="l00053"></a>00053         t[256]=t[0] ;
<a name="l00054"></a>00054         byte y=byte(x);
<a name="l00055"></a>00055         <span class="keywordflow">for</span> (p=0 ; p&lt;256 ; p++) {         <span class="comment">// further change perm.</span>
<a name="l00056"></a>00056           t[p]=t[y=byte(t[p^y]^y)] ;  <span class="comment">// and other digits</span>
<a name="l00057"></a>00057           t[y]=t[p+1] ;  }
<a name="l00058"></a>00058 }
<a name="l00059"></a>00059 
<a name="l00060"></a>00060 <span class="keyword">template</span> &lt;<span class="keyword">class</span> B&gt;
<a name="l00061"></a>00061 <span class="keywordtype">void</span> <a class="code" href="class_w_a_k_e___policy.html">WAKE_Policy&lt;B&gt;::CipherSetKey</a>(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &amp;params, <span class="keyword">const</span> byte *key, <span class="keywordtype">size_t</span> length)
<a name="l00062"></a>00062 {
<a name="l00063"></a>00063         word32 k0, k1, k2, k3;
<a name="l00064"></a>00064         <a class="code" href="struct_block_get_and_put.html">BlockGetAndPut&lt;word32, BigEndian&gt;::Get</a>(key)(r3)(r4)(r5)(r6)(k0)(k1)(k2)(k3);
<a name="l00065"></a>00065         GenKey(k0, k1, k2, k3);
<a name="l00066"></a>00066 }
<a name="l00067"></a>00067 
<a name="l00068"></a>00068 <span class="comment">// CFB</span>
<a name="l00069"></a>00069 <span class="keyword">template</span> &lt;<span class="keyword">class</span> B&gt;
<a name="l00070"></a>00070 <span class="keywordtype">void</span> <a class="code" href="class_w_a_k_e___policy.html">WAKE_Policy&lt;B&gt;::Iterate</a>(byte *output, <span class="keyword">const</span> byte *input, <a class="code" href="cryptlib_8h.html#a353ccabf5ddc119a6a33e92f7b9961c7" title="used to specify a direction for a cipher to operate in (encrypt or decrypt)">CipherDir</a> dir, <span class="keywordtype">size_t</span> iterationCount)
<a name="l00071"></a>00071 {
<a name="l00072"></a>00072         RegisterOutput&lt;B&gt; registerOutput(output, input, dir);
<a name="l00073"></a>00073 
<a name="l00074"></a>00074         <span class="keywordflow">while</span> (iterationCount--)
<a name="l00075"></a>00075         {
<a name="l00076"></a>00076                 r3 = M(r3, ConditionalByteReverse(B::ToEnum(), r6));
<a name="l00077"></a>00077                 r4 = M(r4, r3);
<a name="l00078"></a>00078                 r5 = M(r5, r4);
<a name="l00079"></a>00079                 r6 = M(r6, r5);
<a name="l00080"></a>00080                 registerOutput(r6);
<a name="l00081"></a>00081         }
<a name="l00082"></a>00082 }
<a name="l00083"></a>00083 
<a name="l00084"></a>00084 <span class="comment">// OFB</span>
<a name="l00085"></a>00085 <span class="keyword">template</span> &lt;<span class="keyword">class</span> B&gt;
<a name="l00086"></a>00086 <span class="keywordtype">void</span> <a class="code" href="class_w_a_k_e___policy.html">WAKE_Policy&lt;B&gt;::OperateKeystream</a>(KeystreamOperation operation, byte *output, <span class="keyword">const</span> byte *input, <span class="keywordtype">size_t</span> iterationCount)
<a name="l00087"></a>00087 {
<a name="l00088"></a>00088 <span class="preprocessor">#define WAKE_OUTPUT(x)\</span>
<a name="l00089"></a>00089 <span class="preprocessor">        while (iterationCount--)\</span>
<a name="l00090"></a>00090 <span class="preprocessor">        {\</span>
<a name="l00091"></a>00091 <span class="preprocessor">                CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 0, r6);\</span>
<a name="l00092"></a>00092 <span class="preprocessor">                r3 = M(r3, r6);\</span>
<a name="l00093"></a>00093 <span class="preprocessor">                r4 = M(r4, r3);\</span>
<a name="l00094"></a>00094 <span class="preprocessor">                r5 = M(r5, r4);\</span>
<a name="l00095"></a>00095 <span class="preprocessor">                r6 = M(r6, r5);\</span>
<a name="l00096"></a>00096 <span class="preprocessor">                output += 4;\</span>
<a name="l00097"></a>00097 <span class="preprocessor">                if (!(x &amp; INPUT_NULL))\</span>
<a name="l00098"></a>00098 <span class="preprocessor">                        input += 4;\</span>
<a name="l00099"></a>00099 <span class="preprocessor">        }</span>
<a name="l00100"></a>00100 <span class="preprocessor"></span>
<a name="l00101"></a>00101         <span class="keyword">typedef</span> word32 WordType;
<a name="l00102"></a>00102         CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(WAKE_OUTPUT, 0);
<a name="l00103"></a>00103 }
<a name="l00104"></a>00104 <span class="comment">/*</span>
<a name="l00105"></a>00105 <span class="comment">template &lt;class B&gt;</span>
<a name="l00106"></a>00106 <span class="comment">void WAKE_ROFB_Policy&lt;B&gt;::Iterate(KeystreamOperation operation, byte *output, const byte *input, unsigned int iterationCount)</span>
<a name="l00107"></a>00107 <span class="comment">{</span>
<a name="l00108"></a>00108 <span class="comment">        KeystreamOutput&lt;B&gt; keystreamOperation(operation, output, input);</span>
<a name="l00109"></a>00109 <span class="comment"></span>
<a name="l00110"></a>00110 <span class="comment">        while (iterationCount--)</span>
<a name="l00111"></a>00111 <span class="comment">        {</span>
<a name="l00112"></a>00112 <span class="comment">                keystreamOperation(r6);</span>
<a name="l00113"></a>00113 <span class="comment">                r3 = M(r3, r6);</span>
<a name="l00114"></a>00114 <span class="comment">                r4 = M(r4, r3);</span>
<a name="l00115"></a>00115 <span class="comment">                r5 = M(r5, r4);</span>
<a name="l00116"></a>00116 <span class="comment">                r6 = M(r6, r5);</span>
<a name="l00117"></a>00117 <span class="comment">        }</span>
<a name="l00118"></a>00118 <span class="comment">}</span>
<a name="l00119"></a>00119 <span class="comment">*/</span>
<a name="l00120"></a>00120 <span class="keyword">template</span> <span class="keyword">class </span><a class="code" href="class_w_a_k_e___policy.html">WAKE_Policy&lt;BigEndian&gt;</a>;
<a name="l00121"></a>00121 <span class="keyword">template</span> <span class="keyword">class </span><a class="code" href="class_w_a_k_e___policy.html">WAKE_Policy&lt;LittleEndian&gt;</a>;
<a name="l00122"></a>00122 <span class="comment">//template class WAKE_ROFB_Policy&lt;BigEndian&gt;;</span>
<a name="l00123"></a>00123 <span class="comment">//template class WAKE_ROFB_Policy&lt;LittleEndian&gt;;</span>
<a name="l00124"></a>00124 
<a name="l00125"></a>00125 NAMESPACE_END
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on 9 Dec 2009 for Crypto++ by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>