📄 esign_8cpp-source.html
字号:
<a name="l00138"></a>00138 }<a name="l00139"></a>00139 <a name="l00140"></a><a class="code" href="class_invertible_e_s_i_g_n_function.html#905be1ca12abad6fd3d8e862d713b7c7">00140</a> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> <a class="code" href="class_invertible_e_s_i_g_n_function.html#905be1ca12abad6fd3d8e862d713b7c7">InvertibleESIGNFunction::CalculateRandomizedInverse</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &x)<span class="keyword"> const </span><a name="l00141"></a>00141 <span class="keyword"></span>{<a name="l00142"></a>00142 <a class="code" href="class_crypto_material.html#a1da44802c5cf00946043922cb9e7e6e">DoQuickSanityCheck</a>();<a name="l00143"></a>00143 <a name="l00144"></a>00144 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> pq = <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a> * <a class="code" href="class_invertible_e_s_i_g_n_function.html#dc2b3dc52e2421e408f0e1bb607da135">m_q</a>;<a name="l00145"></a>00145 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> p2 = <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a> * <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a>;<a name="l00146"></a>00146 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> r, z, re, a, w0, w1;<a name="l00147"></a>00147 <a name="l00148"></a>00148 <span class="keywordflow">do</span><a name="l00149"></a>00149 {<a name="l00150"></a>00150 r.<a class="code" href="class_integer.html#0f0574b9cae3cddf62c155da93085f0d">Randomize</a>(rng, <a class="code" href="class_integer.html#19b7e6d48b1b57bd4846160ea2928175" title="avoid calling constructors for these frequently used integers">Integer::Zero</a>(), pq);<a name="l00151"></a>00151 z = x << (2*<a class="code" href="class_e_s_i_g_n_function.html#5a6e6a26b2bfb547685852483909f5a5">GetK</a>()+2);<a name="l00152"></a>00152 re = a_exp_b_mod_c(r, <a class="code" href="class_e_s_i_g_n_function.html#086e17e8047753768b22c6b59faebf60">m_e</a>, <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a>);<a name="l00153"></a>00153 a = (z - re) % <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a>;<a name="l00154"></a>00154 <a class="code" href="class_integer.html#567c89aa176b354143c99d558d05a5fb" title="calculate r and q such that (a == d*q + r) && (0 <= r < abs(d))">Integer::Divide</a>(w1, w0, a, pq);<a name="l00155"></a>00155 <span class="keywordflow">if</span> (w1.NotZero())<a name="l00156"></a>00156 {<a name="l00157"></a>00157 ++w0;<a name="l00158"></a>00158 w1 = pq - w1;<a name="l00159"></a>00159 }<a name="l00160"></a>00160 }<a name="l00161"></a>00161 <span class="keywordflow">while</span> ((w1 >> 2*<a class="code" href="class_e_s_i_g_n_function.html#5a6e6a26b2bfb547685852483909f5a5">GetK</a>()+1).IsPositive());<a name="l00162"></a>00162 <a name="l00163"></a>00163 <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a> modp(m_p);<a name="l00164"></a>00164 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> t = modp.<a class="code" href="class_modular_arithmetic.html#584d214676856d1463e14c6407d1cd31">Divide</a>(w0 * r % m_p, <a class="code" href="class_e_s_i_g_n_function.html#086e17e8047753768b22c6b59faebf60">m_e</a> * re % m_p);<a name="l00165"></a>00165 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> s = r + t*pq;<a name="l00166"></a>00166 assert(s < <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a>);<a name="l00167"></a>00167 <span class="comment">/*</span><a name="l00168"></a>00168 <span class="comment"> using namespace std;</span><a name="l00169"></a>00169 <span class="comment"> cout << "f = " << x << endl;</span><a name="l00170"></a>00170 <span class="comment"> cout << "r = " << r << endl;</span><a name="l00171"></a>00171 <span class="comment"> cout << "z = " << z << endl;</span><a name="l00172"></a>00172 <span class="comment"> cout << "a = " << a << endl;</span><a name="l00173"></a>00173 <span class="comment"> cout << "w0 = " << w0 << endl;</span><a name="l00174"></a>00174 <span class="comment"> cout << "w1 = " << w1 << endl;</span><a name="l00175"></a>00175 <span class="comment"> cout << "t = " << t << endl;</span><a name="l00176"></a>00176 <span class="comment"> cout << "s = " << s << endl;</span><a name="l00177"></a>00177 <span class="comment">*/</span><a name="l00178"></a>00178 <span class="keywordflow">return</span> s;<a name="l00179"></a>00179 }<a name="l00180"></a>00180 <a name="l00181"></a><a class="code" href="class_invertible_e_s_i_g_n_function.html#1c64c8101a488232cde43a5c473742b1">00181</a> <span class="keywordtype">bool</span> <a class="code" href="class_invertible_e_s_i_g_n_function.html#1c64c8101a488232cde43a5c473742b1" title="check this object for errors">InvertibleESIGNFunction::Validate</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> level)<span class="keyword"> const</span><a name="l00182"></a>00182 <span class="keyword"></span>{<a name="l00183"></a>00183 <span class="keywordtype">bool</span> pass = <a class="code" href="class_e_s_i_g_n_function.html#cc185d24c97a74543a6e5820219282bd" title="check this object for errors">ESIGNFunction::Validate</a>(rng, level);<a name="l00184"></a>00184 pass = pass && <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a> > <a class="code" href="class_integer.html#8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>() && <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a>.<a class="code" href="class_integer.html#ed4bb7208a18b986ef3e1a7d92e06d1d">IsOdd</a>() && <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a> < <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a>;<a name="l00185"></a>00185 pass = pass && <a class="code" href="class_invertible_e_s_i_g_n_function.html#dc2b3dc52e2421e408f0e1bb607da135">m_q</a> > <a class="code" href="class_integer.html#8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>() && <a class="code" href="class_invertible_e_s_i_g_n_function.html#dc2b3dc52e2421e408f0e1bb607da135">m_q</a>.<a class="code" href="class_integer.html#ed4bb7208a18b986ef3e1a7d92e06d1d">IsOdd</a>() && <a class="code" href="class_invertible_e_s_i_g_n_function.html#dc2b3dc52e2421e408f0e1bb607da135">m_q</a> < m_n;<a name="l00186"></a>00186 pass = pass && <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a>.<a class="code" href="class_integer.html#867356d88074424328d0ebb9bea63254" title="number of significant bits = floor(log2(abs(*this))) + 1">BitCount</a>() == <a class="code" href="class_invertible_e_s_i_g_n_function.html#dc2b3dc52e2421e408f0e1bb607da135">m_q</a>.<a class="code" href="class_integer.html#867356d88074424328d0ebb9bea63254" title="number of significant bits = floor(log2(abs(*this))) + 1">BitCount</a>();<a name="l00187"></a>00187 <span class="keywordflow">if</span> (level >= 1)<a name="l00188"></a>00188 pass = pass && <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a> * <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a> * <a class="code" href="class_invertible_e_s_i_g_n_function.html#dc2b3dc52e2421e408f0e1bb607da135">m_q</a> == m_n;<a name="l00189"></a>00189 <span class="keywordflow">if</span> (level >= 2)<a name="l00190"></a>00190 pass = pass && VerifyPrime(rng, <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a>, level-2) && VerifyPrime(rng, m_q, level-2);<a name="l00191"></a>00191 <span class="keywordflow">return</span> pass;<a name="l00192"></a>00192 }<a name="l00193"></a>00193 <a name="l00194"></a><a class="code" href="class_invertible_e_s_i_g_n_function.html#6532958ce2c456eef8b84c33f69e944d">00194</a> <span class="keywordtype">bool</span> <a class="code" href="class_invertible_e_s_i_g_n_function.html#6532958ce2c456eef8b84c33f69e944d" title="to be implemented by derived classes, users should use one of the above functions...">InvertibleESIGNFunction::GetVoidValue</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keyword">const</span> std::type_info &valueType, <span class="keywordtype">void</span> *pValue)<span class="keyword"> const</span><a name="l00195"></a>00195 <span class="keyword"></span>{<a name="l00196"></a>00196 <span class="keywordflow">return</span> GetValueHelper<ESIGNFunction>(<span class="keyword">this</span>, name, valueType, pValue).Assignable()<a name="l00197"></a>00197 CRYPTOPP_GET_FUNCTION_ENTRY(Prime1)<a name="l00198"></a>00198 CRYPTOPP_GET_FUNCTION_ENTRY(Prime2)<a name="l00199"></a>00199 ;<a name="l00200"></a>00200 }<a name="l00201"></a>00201 <a name="l00202"></a><a class="code" href="class_invertible_e_s_i_g_n_function.html#ca870e350b30d04a47d452f21e903278">00202</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_e_s_i_g_n_function.html#ca870e350b30d04a47d452f21e903278" title="assign values from source to this object">InvertibleESIGNFunction::AssignFrom</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> &source)<a name="l00203"></a>00203 {<a name="l00204"></a>00204 AssignFromHelper<ESIGNFunction>(<span class="keyword">this</span>, source)<a name="l00205"></a>00205 CRYPTOPP_SET_FUNCTION_ENTRY(Prime1)<a name="l00206"></a>00206 CRYPTOPP_SET_FUNCTION_ENTRY(Prime2)<a name="l00207"></a>00207 ;<a name="l00208"></a>00208 }<a name="l00209"></a>00209 <a name="l00210"></a>00210 NAMESPACE_END</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Fri Jun 1 11:11:21 2007 for Crypto++ by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -