⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rabin_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<a name="l00146"></a>00146         r = modn.<a class="code" href="class_modular_arithmetic.html#c378a2527fe2107d3379bc35d7cd0487">Square</a>(r);<a name="l00147"></a>00147         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> r2 = modn.<a class="code" href="class_modular_arithmetic.html#c378a2527fe2107d3379bc35d7cd0487">Square</a>(r);<a name="l00148"></a>00148         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> c = modn.<a class="code" href="class_modular_arithmetic.html#3b88a85b11eb1a826d26d01bdaafbf0a">Multiply</a>(in, r2);              <span class="comment">// blind</span><a name="l00149"></a>00149 <a name="l00150"></a>00150         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> cp=c%<a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a>, cq=c%<a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a>;<a name="l00151"></a>00151 <a name="l00152"></a>00152         <span class="keywordtype">int</span> jp = Jacobi(cp, <a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a>);<a name="l00153"></a>00153         <span class="keywordtype">int</span> jq = Jacobi(cq, <a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a>);<a name="l00154"></a>00154 <a name="l00155"></a>00155         <span class="keywordflow">if</span> (jq==-1)<a name="l00156"></a>00156         {<a name="l00157"></a>00157                 cp = cp*EuclideanMultiplicativeInverse(<a class="code" href="class_rabin_function.html#c98a931385ae02de294a7a7da66fddfd">m_r</a>, <a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a>)%<a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a>;<a name="l00158"></a>00158                 cq = cq*EuclideanMultiplicativeInverse(<a class="code" href="class_rabin_function.html#c98a931385ae02de294a7a7da66fddfd">m_r</a>, <a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a>)%<a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a>;<a name="l00159"></a>00159         }<a name="l00160"></a>00160 <a name="l00161"></a>00161         <span class="keywordflow">if</span> (jp==-1)<a name="l00162"></a>00162         {<a name="l00163"></a>00163                 cp = cp*EuclideanMultiplicativeInverse(<a class="code" href="class_rabin_function.html#601264d1c703941468aaaa7c1918dec2">m_s</a>, <a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a>)%<a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a>;<a name="l00164"></a>00164                 cq = cq*EuclideanMultiplicativeInverse(<a class="code" href="class_rabin_function.html#601264d1c703941468aaaa7c1918dec2">m_s</a>, <a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a>)%<a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a>;<a name="l00165"></a>00165         }<a name="l00166"></a>00166 <a name="l00167"></a>00167         cp = ModularSquareRoot(cp, <a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a>);<a name="l00168"></a>00168         cq = ModularSquareRoot(cq, <a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a>);<a name="l00169"></a>00169 <a name="l00170"></a>00170         <span class="keywordflow">if</span> (jp==-1)<a name="l00171"></a>00171                 cp = <a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a>-cp;<a name="l00172"></a>00172 <a name="l00173"></a>00173         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> out = CRT(cq, <a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a>, cp, <a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a>, <a class="code" href="class_invertible_rabin_function.html#39d937e65da2073ea867b8a93f8b25e7">m_u</a>);<a name="l00174"></a>00174 <a name="l00175"></a>00175         out = modn.<a class="code" href="class_modular_arithmetic.html#584d214676856d1463e14c6407d1cd31">Divide</a>(out, r);      <span class="comment">// unblind</span><a name="l00176"></a>00176 <a name="l00177"></a>00177         <span class="keywordflow">if</span> ((jq==-1 &amp;&amp; out.<a class="code" href="class_integer.html#fedf9af097a3417d8bd3742ec53f9593">IsEven</a>()) || (jq==1 &amp;&amp; out.<a class="code" href="class_integer.html#ed4bb7208a18b986ef3e1a7d92e06d1d">IsOdd</a>()))<a name="l00178"></a>00178                 out = <a class="code" href="class_rabin_function.html#f361185b5962701c78c410945f6280bc">m_n</a>-out;<a name="l00179"></a>00179 <a name="l00180"></a>00180         <span class="keywordflow">return</span> out;<a name="l00181"></a>00181 }<a name="l00182"></a>00182 <a name="l00183"></a><a class="code" href="class_invertible_rabin_function.html#8f654d654bf7e833c9c48351346d3cb9">00183</a> <span class="keywordtype">bool</span> <a class="code" href="class_invertible_rabin_function.html#8f654d654bf7e833c9c48351346d3cb9" title="check this object for errors">InvertibleRabinFunction::Validate</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &amp;rng, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> level)<span class="keyword"> const</span><a name="l00184"></a>00184 <span class="keyword"></span>{<a name="l00185"></a>00185         <span class="keywordtype">bool</span> pass = <a class="code" href="class_rabin_function.html#c1f4bf45382c16a486616269884d95be" title="check this object for errors">RabinFunction::Validate</a>(rng, level);<a name="l00186"></a>00186         pass = pass &amp;&amp; <a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a> &gt; <a class="code" href="class_integer.html#8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>() &amp;&amp; <a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a>%4 == 3 &amp;&amp; <a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a> &lt; <a class="code" href="class_rabin_function.html#f361185b5962701c78c410945f6280bc">m_n</a>;<a name="l00187"></a>00187         pass = pass &amp;&amp; <a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a> &gt; <a class="code" href="class_integer.html#8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>() &amp;&amp; <a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a>%4 == 3 &amp;&amp; <a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a> &lt; m_n;<a name="l00188"></a>00188         pass = pass &amp;&amp; <a class="code" href="class_invertible_rabin_function.html#39d937e65da2073ea867b8a93f8b25e7">m_u</a>.<a class="code" href="class_integer.html#13ddbfd8e9729932c2a99b0dff530978">IsPositive</a>() &amp;&amp; <a class="code" href="class_invertible_rabin_function.html#39d937e65da2073ea867b8a93f8b25e7">m_u</a> &lt; <a class="code" href="class_invertible_rabin_function.html#7265f1577c7c60962100bf048c532b65">m_p</a>;<a name="l00189"></a>00189         <span class="keywordflow">if</span> (level &gt;= 1)<a name="l00190"></a>00190         {<a name="l00191"></a>00191                 pass = pass &amp;&amp; m_p * <a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a> == m_n;<a name="l00192"></a>00192                 pass = pass &amp;&amp; <a class="code" href="class_invertible_rabin_function.html#39d937e65da2073ea867b8a93f8b25e7">m_u</a> * m_q % m_p == 1;<a name="l00193"></a>00193                 pass = pass &amp;&amp; Jacobi(<a class="code" href="class_rabin_function.html#c98a931385ae02de294a7a7da66fddfd">m_r</a>, m_p) == 1;<a name="l00194"></a>00194                 pass = pass &amp;&amp; Jacobi(<a class="code" href="class_rabin_function.html#c98a931385ae02de294a7a7da66fddfd">m_r</a>, m_q) == -1;<a name="l00195"></a>00195                 pass = pass &amp;&amp; Jacobi(<a class="code" href="class_rabin_function.html#601264d1c703941468aaaa7c1918dec2">m_s</a>, m_p) == -1;<a name="l00196"></a>00196                 pass = pass &amp;&amp; Jacobi(<a class="code" href="class_rabin_function.html#601264d1c703941468aaaa7c1918dec2">m_s</a>, m_q) == 1;<a name="l00197"></a>00197         }<a name="l00198"></a>00198         <span class="keywordflow">if</span> (level &gt;= 2)<a name="l00199"></a>00199                 pass = pass &amp;&amp; VerifyPrime(rng, m_p, level-2) &amp;&amp; VerifyPrime(rng, <a class="code" href="class_invertible_rabin_function.html#6f7f68cf7b9299b85da9df3241aa8096">m_q</a>, level-2);<a name="l00200"></a>00200         <span class="keywordflow">return</span> pass;<a name="l00201"></a>00201 }<a name="l00202"></a>00202 <a name="l00203"></a><a class="code" href="class_invertible_rabin_function.html#52931eba7e69b47a1b9307dc92721e0f">00203</a> <span class="keywordtype">bool</span> <a class="code" href="class_invertible_rabin_function.html#52931eba7e69b47a1b9307dc92721e0f" title="to be implemented by derived classes, users should use one of the above functions...">InvertibleRabinFunction::GetVoidValue</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keyword">const</span> std::type_info &amp;valueType, <span class="keywordtype">void</span> *pValue)<span class="keyword"> const</span><a name="l00204"></a>00204 <span class="keyword"></span>{<a name="l00205"></a>00205         <span class="keywordflow">return</span> GetValueHelper&lt;RabinFunction&gt;(<span class="keyword">this</span>, name, valueType, pValue).Assignable()<a name="l00206"></a>00206                 CRYPTOPP_GET_FUNCTION_ENTRY(Prime1)<a name="l00207"></a>00207                 CRYPTOPP_GET_FUNCTION_ENTRY(Prime2)<a name="l00208"></a>00208                 CRYPTOPP_GET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1)<a name="l00209"></a>00209                 ;<a name="l00210"></a>00210 }<a name="l00211"></a>00211 <a name="l00212"></a><a class="code" href="class_invertible_rabin_function.html#66594bb7f369e4ecc30bbe6ae62527ea">00212</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_rabin_function.html#66594bb7f369e4ecc30bbe6ae62527ea" title="assign values from source to this object">InvertibleRabinFunction::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> &amp;source)<a name="l00213"></a>00213 {<a name="l00214"></a>00214         AssignFromHelper&lt;RabinFunction&gt;(<span class="keyword">this</span>, source)<a name="l00215"></a>00215                 CRYPTOPP_SET_FUNCTION_ENTRY(Prime1)<a name="l00216"></a>00216                 CRYPTOPP_SET_FUNCTION_ENTRY(Prime2)<a name="l00217"></a>00217                 CRYPTOPP_SET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1)<a name="l00218"></a>00218                 ;<a name="l00219"></a>00219 }<a name="l00220"></a>00220 <a name="l00221"></a>00221 NAMESPACE_END</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Fri Jun 1 11:11:23 2007 for Crypto++ by&nbsp;<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 + -