📄 rw_8cpp-source.html
字号:
<a name="l00130"></a>00130 r.<a class="code" href="class_integer.html#0f0574b9cae3cddf62c155da93085f0d">Randomize</a>(rng, <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_r_w_function.html#21b3158cafdb7121e6305b742ffb340f">m_n</a> - <a class="code" href="class_integer.html#8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>());<a name="l00131"></a>00131 rInv = modn.<a class="code" href="class_modular_arithmetic.html#e2246ad602514e19f1291cd46b351ed9">MultiplicativeInverse</a>(r);<a name="l00132"></a>00132 } <span class="keywordflow">while</span> (rInv.<a class="code" href="class_integer.html#cca1f2de6c0bfa91c49950daf681b678">IsZero</a>());<a name="l00133"></a>00133 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> re = modn.<a class="code" href="class_modular_arithmetic.html#c378a2527fe2107d3379bc35d7cd0487">Square</a>(r);<a name="l00134"></a>00134 re = modn.<a class="code" href="class_modular_arithmetic.html#3b88a85b11eb1a826d26d01bdaafbf0a">Multiply</a>(re, x); <span class="comment">// blind</span><a name="l00135"></a>00135 <a name="l00136"></a>00136 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> cp=re%<a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a>, cq=re%<a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a>;<a name="l00137"></a>00137 <span class="keywordflow">if</span> (Jacobi(cp, <a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a>) * Jacobi(cq, <a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a>) != 1)<a name="l00138"></a>00138 {<a name="l00139"></a>00139 cp = cp.<a class="code" href="class_integer.html#ed4bb7208a18b986ef3e1a7d92e06d1d">IsOdd</a>() ? (cp+<a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a>) >> 1 : cp >> 1;<a name="l00140"></a>00140 cq = cq.<a class="code" href="class_integer.html#ed4bb7208a18b986ef3e1a7d92e06d1d">IsOdd</a>() ? (cq+<a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a>) >> 1 : cq >> 1;<a name="l00141"></a>00141 }<a name="l00142"></a>00142 <a name="l00143"></a>00143 <span class="preprocessor"> #pragma omp parallel</span><a name="l00144"></a>00144 <span class="preprocessor"></span><span class="preprocessor"> #pragma omp sections</span><a name="l00145"></a>00145 <span class="preprocessor"></span> {<a name="l00146"></a>00146 <span class="preprocessor"> #pragma omp section</span><a name="l00147"></a>00147 <span class="preprocessor"></span> cp = ModularSquareRoot(cp, <a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a>);<a name="l00148"></a>00148 <span class="preprocessor"> #pragma omp section</span><a name="l00149"></a>00149 <span class="preprocessor"></span> cq = ModularSquareRoot(cq, <a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a>);<a name="l00150"></a>00150 }<a name="l00151"></a>00151 <a name="l00152"></a>00152 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> y = CRT(cq, <a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a>, cp, <a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a>, <a class="code" href="class_invertible_r_w_function.html#e2afd7a6cc5342f098a858dde9161581">m_u</a>);<a name="l00153"></a>00153 y = modn.<a class="code" href="class_modular_arithmetic.html#3b88a85b11eb1a826d26d01bdaafbf0a">Multiply</a>(y, rInv); <span class="comment">// unblind</span><a name="l00154"></a>00154 y = STDMIN(y, <a class="code" href="class_r_w_function.html#21b3158cafdb7121e6305b742ffb340f">m_n</a>-y);<a name="l00155"></a>00155 <span class="keywordflow">if</span> (<a class="code" href="class_r_w_function.html#cddf9a5cb9d37ab07a1535f644cdac19">ApplyFunction</a>(y) != x) <span class="comment">// check</span><a name="l00156"></a>00156 <span class="keywordflow">throw</span> <a class="code" href="class_exception.html" title="base class for all exceptions thrown by Crypto++">Exception</a>(<a class="code" href="class_exception.html#8e53909d979479380e0274807c074c0a27d9ee7704100a88e4ae4adcc4072015" title="some error not belong to any of the above categories">Exception::OTHER_ERROR</a>, <span class="stringliteral">"InvertibleRWFunction: computational error during private key operation"</span>);<a name="l00157"></a>00157 <span class="keywordflow">return</span> y;<a name="l00158"></a>00158 }<a name="l00159"></a>00159 <a name="l00160"></a><a class="code" href="class_invertible_r_w_function.html#1c3858f76fdd2c48bcac7346d75b8c9e">00160</a> <span class="keywordtype">bool</span> <a class="code" href="class_invertible_r_w_function.html#1c3858f76fdd2c48bcac7346d75b8c9e" title="check this object for errors">InvertibleRWFunction::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="l00161"></a>00161 <span class="keyword"></span>{<a name="l00162"></a>00162 <span class="keywordtype">bool</span> pass = <a class="code" href="class_r_w_function.html#f326ae91ff9d6719c879861d21d380ac" title="check this object for errors">RWFunction::Validate</a>(rng, level);<a name="l00163"></a>00163 pass = pass && <a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">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_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a>%8 == 3 && <a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a> < <a class="code" href="class_r_w_function.html#21b3158cafdb7121e6305b742ffb340f">m_n</a>;<a name="l00164"></a>00164 pass = pass && <a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">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_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a>%8 == 7 && <a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a> < m_n;<a name="l00165"></a>00165 pass = pass && <a class="code" href="class_invertible_r_w_function.html#e2afd7a6cc5342f098a858dde9161581">m_u</a>.<a class="code" href="class_integer.html#13ddbfd8e9729932c2a99b0dff530978">IsPositive</a>() && <a class="code" href="class_invertible_r_w_function.html#e2afd7a6cc5342f098a858dde9161581">m_u</a> < <a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a>;<a name="l00166"></a>00166 <span class="keywordflow">if</span> (level >= 1)<a name="l00167"></a>00167 {<a name="l00168"></a>00168 pass = pass && m_p * <a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a> == m_n;<a name="l00169"></a>00169 pass = pass && <a class="code" href="class_invertible_r_w_function.html#e2afd7a6cc5342f098a858dde9161581">m_u</a> * m_q % m_p == 1;<a name="l00170"></a>00170 }<a name="l00171"></a>00171 <span class="keywordflow">if</span> (level >= 2)<a name="l00172"></a>00172 pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, <a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a>, level-2);<a name="l00173"></a>00173 <span class="keywordflow">return</span> pass;<a name="l00174"></a>00174 }<a name="l00175"></a>00175 <a name="l00176"></a><a class="code" href="class_invertible_r_w_function.html#bd17ed1b135d340abc325046eebef6ac">00176</a> <span class="keywordtype">bool</span> <a class="code" href="class_invertible_r_w_function.html#bd17ed1b135d340abc325046eebef6ac" title="to be implemented by derived classes, users should use one of the above functions...">InvertibleRWFunction::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="l00177"></a>00177 <span class="keyword"></span>{<a name="l00178"></a>00178 <span class="keywordflow">return</span> GetValueHelper<RWFunction>(<span class="keyword">this</span>, name, valueType, pValue).Assignable()<a name="l00179"></a>00179 CRYPTOPP_GET_FUNCTION_ENTRY(Prime1)<a name="l00180"></a>00180 CRYPTOPP_GET_FUNCTION_ENTRY(Prime2)<a name="l00181"></a>00181 CRYPTOPP_GET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1)<a name="l00182"></a>00182 ;<a name="l00183"></a>00183 }<a name="l00184"></a>00184 <a name="l00185"></a><a class="code" href="class_invertible_r_w_function.html#56b0314b678c58228671d3c9049f86db">00185</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_r_w_function.html#56b0314b678c58228671d3c9049f86db" title="assign values from source to this object">InvertibleRWFunction::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="l00186"></a>00186 {<a name="l00187"></a>00187 AssignFromHelper<RWFunction>(<span class="keyword">this</span>, source)<a name="l00188"></a>00188 CRYPTOPP_SET_FUNCTION_ENTRY(Prime1)<a name="l00189"></a>00189 CRYPTOPP_SET_FUNCTION_ENTRY(Prime2)<a name="l00190"></a>00190 CRYPTOPP_SET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1)<a name="l00191"></a>00191 ;<a name="l00192"></a>00192 }<a name="l00193"></a>00193 <a name="l00194"></a>00194 NAMESPACE_END<a name="l00195"></a>00195 <a name="l00196"></a>00196 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Fri Jun 1 11:11:24 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 + -