📄 lubyrack_8h-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Crypto++: lubyrack.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.2 --><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">Compound 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">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div><h1>lubyrack.h</h1><a href="lubyrack_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">// lubyrack.h - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="preprocessor">#ifndef CRYPTOPP_LUBYRACK_H</span>00004 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_LUBYRACK_H</span>00005 <span class="preprocessor"></span><span class="comment"></span>00006 <span class="comment">/** \file */</span>00007 00008 <span class="preprocessor">#include "<a class="code" href="simple_8h.html">simple.h</a>"</span>00009 <span class="preprocessor">#include "secblock.h"</span>00010 00011 NAMESPACE_BEGIN(CryptoPP)00012 00013 <span class="keyword">template</span> <<span class="keyword">class</span> T> <span class="keyword">struct </span>DigestSizeDoubleWorkaround {<span class="keyword">enum</span> {RESULT = 2*T::DIGESTSIZE};}; <span class="comment">// VC60 workaround</span>00014 <span class="comment"></span>00015 <span class="comment">//! .</span>00016 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> T><a name="l00017"></a><a class="code" href="struct_l_r___info.html">00017</a> <span class="keyword">struct </span><a class="code" href="struct_l_r___info.html">LR_Info</a> : <span class="keyword">public</span> <a class="code" href="class_variable_key_length.html">VariableKeyLength</a><16, 0, 2*(UINT_MAX/2), 2>, <span class="keyword">public</span> <a class="code" href="class_fixed_block_size.html">FixedBlockSize</a><DigestSizeDoubleWorkaround<T>::RESULT>00018 {00019 <span class="keyword">static</span> std::string StaticAlgorithmName() {<span class="keywordflow">return</span> std::string(<span class="stringliteral">"LR/"</span>)+T::StaticAlgorithmName();}00020 };00021 <span class="comment"></span>00022 <span class="comment">//! Luby-Rackoff</span>00023 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> T><a name="l00024"></a><a class="code" href="class_l_r.html">00024</a> <span class="keyword">class </span><a class="code" href="class_l_r.html">LR</a> : <span class="keyword">public</span> <a class="code" href="struct_l_r___info.html">LR_Info</a><T>, <span class="keyword">public</span> <a class="code" href="struct_block_cipher_documentation.html">BlockCipherDocumentation</a>00025 {00026 <span class="keyword">class </span>Base : <span class="keyword">public</span> BlockCipherBaseTemplate<LR_Info<T> >00027 {00028 <span class="keyword">public</span>:00029 <span class="comment">// VC60 workaround: have to define these functions within class definition</span>00030 <span class="keywordtype">void</span> UncheckedSetKey(<a class="code" href="cryptlib_8h.html#a11">CipherDir</a> direction, <span class="keyword">const</span> byte *userKey, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00031 {00032 AssertValidKeyLength(length);00033 00034 L = length/2;00035 buffer.New(2*S);00036 digest.New(S);00037 key.Assign(userKey, 2*L);00038 }00039 00040 <span class="keyword">protected</span>:00041 <span class="keyword">enum</span> {S=T::DIGESTSIZE};00042 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> L; <span class="comment">// key length / 2</span>00043 <a class="code" href="class_sec_block.html">SecByteBlock</a> key;00044 00045 <span class="keyword">mutable</span> T hm;00046 <span class="keyword">mutable</span> <a class="code" href="class_sec_block.html">SecByteBlock</a> buffer, digest;00047 };00048 00049 <span class="keyword">class </span>Enc : <span class="keyword">public</span> Base00050 {00051 <span class="keyword">public</span>:00052 00053 <span class="preprocessor">#define KL key</span>00054 <span class="preprocessor"></span><span class="preprocessor">#define KR key+L</span>00055 <span class="preprocessor"></span><span class="preprocessor">#define BL buffer</span>00056 <span class="preprocessor"></span><span class="preprocessor">#define BR buffer+S</span>00057 <span class="preprocessor"></span><span class="preprocessor">#define IL inBlock</span>00058 <span class="preprocessor"></span><span class="preprocessor">#define IR inBlock+S</span>00059 <span class="preprocessor"></span><span class="preprocessor">#define OL outBlock</span>00060 <span class="preprocessor"></span><span class="preprocessor">#define OR outBlock+S</span>00061 <span class="preprocessor"></span>00062 <span class="keywordtype">void</span> ProcessAndXorBlock(<span class="keyword">const</span> byte *inBlock, <span class="keyword">const</span> byte *xorBlock, byte *outBlock)<span class="keyword"> const</span>00063 <span class="keyword"> </span>{00064 hm.Update(KL, L);00065 hm.Update(IL, S);00066 hm.Final(BR);00067 xorbuf(BR, IR, S);00068 00069 hm.Update(KR, L);00070 hm.Update(BR, S);00071 hm.Final(BL);00072 xorbuf(BL, IL, S);00073 00074 hm.Update(KL, L);00075 hm.Update(BL, S);00076 hm.Final(digest);00077 xorbuf(BR, digest, S);00078 00079 hm.Update(KR, L);00080 hm.Update(OR, S);00081 hm.Final(digest);00082 xorbuf(BL, digest, S);00083 00084 <span class="keywordflow">if</span> (xorBlock)00085 xorbuf(outBlock, xorBlock, buffer, 2*S);00086 <span class="keywordflow">else</span>00087 memcpy(outBlock, buffer, 2*S);00088 }00089 };00090 00091 <span class="keyword">class </span>Dec : <span class="keyword">public</span> Base00092 {00093 <span class="keyword">public</span>:00094 <span class="keywordtype">void</span> ProcessAndXorBlock(<span class="keyword">const</span> byte *inBlock, <span class="keyword">const</span> byte *xorBlock, byte *outBlock)<span class="keyword"> const</span>00095 <span class="keyword"> </span>{00096 hm.Update(KR, L);00097 hm.Update(IR, S);00098 hm.Final(BL);00099 xorbuf(BL, IL, S);00100 00101 hm.Update(KL, L);00102 hm.Update(BL, S);00103 hm.Final(BR);00104 xorbuf(BR, IR, S);00105 00106 hm.Update(KR, L);00107 hm.Update(BR, S);00108 hm.Final(digest);00109 xorbuf(BL, digest, S);00110 00111 hm.Update(KL, L);00112 hm.Update(OL, S);00113 hm.Final(digest);00114 xorbuf(BR, digest, S);00115 00116 <span class="keywordflow">if</span> (xorBlock)00117 xorbuf(outBlock, xorBlock, buffer, 2*S);00118 <span class="keywordflow">else</span>00119 memcpy(outBlock, buffer, 2*S);00120 }00121 <span class="preprocessor">#undef KL</span>00122 <span class="preprocessor"></span><span class="preprocessor">#undef KR</span>00123 <span class="preprocessor"></span><span class="preprocessor">#undef BL</span>00124 <span class="preprocessor"></span><span class="preprocessor">#undef BR</span>00125 <span class="preprocessor"></span><span class="preprocessor">#undef IL</span>00126 <span class="preprocessor"></span><span class="preprocessor">#undef IR</span>00127 <span class="preprocessor"></span><span class="preprocessor">#undef OL</span>00128 <span class="preprocessor"></span><span class="preprocessor">#undef OR</span>00129 <span class="preprocessor"></span> };00130 00131 <span class="keyword">public</span>:<a name="l00132"></a><a class="code" href="class_l_r.html#_l_rw0">00132</a> <span class="keyword">typedef</span> <a class="code" href="class_block_cipher_template.html">BlockCipherTemplate<ENCRYPTION, Enc></a> <a class="code" href="class_block_cipher_template.html">Encryption</a>;<a name="l00133"></a><a class="code" href="class_l_r.html#_l_rw1">00133</a> <span class="keyword">typedef</span> <a class="code" href="class_block_cipher_template.html">BlockCipherTemplate<DECRYPTION, Dec></a> <a class="code" href="class_block_cipher_template.html">Decryption</a>;00134 };00135 00136 NAMESPACE_END00137 00138 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:19 2003 for Crypto++ by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -