📄 modarith_8h-source.html
字号:
<a name="l00073"></a><a class="code" href="class_modular_arithmetic.html#f942a7ca057b363cb7a4c74f15a9530e">00073</a> <span class="keyword">const</span> Integer& MultiplicativeIdentity()<span class="keyword"> const</span><a name="l00074"></a>00074 <span class="keyword"> </span>{<span class="keywordflow">return</span> <a class="code" href="class_integer.html#8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>();}<a name="l00075"></a>00075 <a name="l00076"></a><a class="code" href="class_modular_arithmetic.html#3b88a85b11eb1a826d26d01bdaafbf0a">00076</a> <span class="keyword">const</span> Integer& Multiply(<span class="keyword">const</span> Integer &a, <span class="keyword">const</span> Integer &b)<span class="keyword"> const</span><a name="l00077"></a>00077 <span class="keyword"> </span>{<span class="keywordflow">return</span> m_result1 = a*b%m_modulus;}<a name="l00078"></a>00078 <a name="l00079"></a><a class="code" href="class_modular_arithmetic.html#c378a2527fe2107d3379bc35d7cd0487">00079</a> <span class="keyword">const</span> Integer& <a class="code" href="class_square.html" title="Square">Square</a>(<span class="keyword">const</span> Integer &a)<span class="keyword"> const</span><a name="l00080"></a>00080 <span class="keyword"> </span>{<span class="keywordflow">return</span> m_result1 = a.<a class="code" href="class_integer.html#7b5e639045868c5ac338f4180e1c7efa">Squared</a>()%m_modulus;}<a name="l00081"></a>00081 <a name="l00082"></a><a class="code" href="class_modular_arithmetic.html#90ca6f6591e3e5553dc7b9e94dad100d">00082</a> <span class="keywordtype">bool</span> IsUnit(<span class="keyword">const</span> Integer &a)<span class="keyword"> const</span><a name="l00083"></a>00083 <span class="keyword"> </span>{<span class="keywordflow">return</span> <a class="code" href="class_integer.html#2d4d29937f8ef666717530b30f137c37" title="greatest common divisor">Integer::Gcd</a>(a, m_modulus).<a class="code" href="class_integer.html#ea313b73beda59a8c4ee2de11d637412" title="is 1 or -1">IsUnit</a>();}<a name="l00084"></a>00084 <a name="l00085"></a><a class="code" href="class_modular_arithmetic.html#e2246ad602514e19f1291cd46b351ed9">00085</a> <span class="keyword">const</span> Integer& MultiplicativeInverse(<span class="keyword">const</span> Integer &a)<span class="keyword"> const</span><a name="l00086"></a>00086 <span class="keyword"> </span>{<span class="keywordflow">return</span> m_result1 = a.<a class="code" href="class_integer.html#881f9c714ee42f35718725a43d4d7db3" title="calculate multiplicative inverse of *this mod n">InverseMod</a>(m_modulus);}<a name="l00087"></a>00087 <a name="l00088"></a><a class="code" href="class_modular_arithmetic.html#584d214676856d1463e14c6407d1cd31">00088</a> <span class="keyword">const</span> Integer& Divide(<span class="keyword">const</span> Integer &a, <span class="keyword">const</span> Integer &b)<span class="keyword"> const</span><a name="l00089"></a>00089 <span class="keyword"> </span>{<span class="keywordflow">return</span> Multiply(a, MultiplicativeInverse(b));}<a name="l00090"></a>00090 <a name="l00091"></a>00091 Integer CascadeExponentiate(<span class="keyword">const</span> Integer &x, <span class="keyword">const</span> Integer &e1, <span class="keyword">const</span> Integer &y, <span class="keyword">const</span> Integer &e2) <span class="keyword">const</span>;<a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="keywordtype">void</span> SimultaneousExponentiate(Element *results, <span class="keyword">const</span> Element &base, <span class="keyword">const</span> Integer *exponents, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> exponentsCount) <span class="keyword">const</span>;<a name="l00094"></a>00094 <a name="l00095"></a><a class="code" href="class_modular_arithmetic.html#3c802233b0edf8df4228d65082ff37fa">00095</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> MaxElementBitLength()<span class="keyword"> const</span><a name="l00096"></a>00096 <span class="keyword"> </span>{<span class="keywordflow">return</span> (m_modulus-1).BitCount();}<a name="l00097"></a>00097 <a name="l00098"></a><a class="code" href="class_modular_arithmetic.html#5897aea2ee78595979f8f261130c93ee">00098</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> MaxElementByteLength()<span class="keyword"> const</span><a name="l00099"></a>00099 <span class="keyword"> </span>{<span class="keywordflow">return</span> (m_modulus-1).ByteCount();}<a name="l00100"></a>00100 <a name="l00101"></a><a class="code" href="class_modular_arithmetic.html#6abf94f5924223c316c04752ba39795a">00101</a> Element RandomElement( <a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng , <span class="keyword">const</span> RandomizationParameter &ignore_for_now = 0 ) const<a name="l00102"></a>00102 <span class="comment">// left RandomizationParameter arg as ref in case RandomizationParameter becomes a more complicated struct</span><a name="l00103"></a>00103 { <a name="l00104"></a>00104 <span class="keywordflow">return</span> Element( rng , Integer( (<span class="keywordtype">long</span>) 0) , m_modulus - Integer( (<span class="keywordtype">long</span>) 1 ) ) ; <a name="l00105"></a>00105 } <a name="l00106"></a>00106 <a name="l00107"></a><a class="code" href="class_modular_arithmetic.html#5a84667a0345e770fd189fcaa0e33865">00107</a> <span class="keywordtype">bool</span> <a class="code" href="gf2n_8h.html#22c25c181c409600aa2e4bf1067ac47a">operator==</a>(<span class="keyword">const</span> <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a> &rhs)<span class="keyword"> const</span><a name="l00108"></a>00108 <span class="keyword"> </span>{<span class="keywordflow">return</span> m_modulus == rhs.<a class="code" href="class_modular_arithmetic.html#4abc2cc7581f81095609dd78a1ac8a01">m_modulus</a>;}<a name="l00109"></a>00109 <a name="l00110"></a><a class="code" href="class_modular_arithmetic.html#0bc237302baf05d7a7dcf7469eb2d331">00110</a> <span class="keyword">static</span> <span class="keyword">const</span> RandomizationParameter DefaultRandomizationParameter ;<a name="l00111"></a>00111 <a name="l00112"></a>00112 <span class="keyword">protected</span>:<a name="l00113"></a><a class="code" href="class_modular_arithmetic.html#4abc2cc7581f81095609dd78a1ac8a01">00113</a> Integer m_modulus;<a name="l00114"></a><a class="code" href="class_modular_arithmetic.html#38e0eb807c66bef02cb5e1e808e10da4">00114</a> <span class="keyword">mutable</span> Integer m_result, m_result1;<a name="l00115"></a>00115 <a name="l00116"></a>00116 };<a name="l00117"></a>00117 <a name="l00118"></a>00118 <span class="comment">// const ModularArithmetic::RandomizationParameter ModularArithmetic::DefaultRandomizationParameter = 0 ;</span><a name="l00119"></a>00119 <span class="comment"></span><a name="l00120"></a>00120 <span class="comment">//! do modular arithmetics in Montgomery representation for increased speed</span><a name="l00121"></a>00121 <span class="comment"></span><span class="comment">/*! \note the Montgomery representation represents each congruence class [a] as a*r%n, where r is a convenient power of 2 */</span><a name="l00122"></a><a class="code" href="class_montgomery_representation.html">00122</a> <span class="keyword">class </span>CRYPTOPP_DLL MontgomeryRepresentation : <span class="keyword">public</span> <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a><a name="l00123"></a>00123 {<a name="l00124"></a>00124 <span class="keyword">public</span>:<a name="l00125"></a>00125 MontgomeryRepresentation(<span class="keyword">const</span> Integer &modulus); <span class="comment">// modulus must be odd</span><a name="l00126"></a>00126 <a name="l00127"></a><a class="code" href="class_montgomery_representation.html#4591893e6fb0e05f4d2585cddcc15201">00127</a> <span class="keyword">virtual</span> <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a> * <a class="code" href="class_modular_arithmetic.html#2ea01ae9e84d5392a8781b99d5cba83f">Clone</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">new</span> MontgomeryRepresentation(*<span class="keyword">this</span>);}<a name="l00128"></a>00128 <a name="l00129"></a><a class="code" href="class_montgomery_representation.html#5e2e1914f195a03be80c58d62be84f5e">00129</a> <span class="keywordtype">bool</span> <a class="code" href="class_modular_arithmetic.html#7a93adfe41f5545dcfaf3ee9f2b49bc3">IsMontgomeryRepresentation</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">true</span>;}<a name="l00130"></a>00130 <a name="l00131"></a><a class="code" href="class_montgomery_representation.html#c0a6608ef5bac036beb44d8cbd5eac52">00131</a> Integer <a class="code" href="class_modular_arithmetic.html#6d504c7166a5eab47a74b86ce8cc782b">ConvertIn</a>(<span class="keyword">const</span> Integer &a)<span class="keyword"> const</span><a name="l00132"></a>00132 <span class="keyword"> </span>{<span class="keywordflow">return</span> (a<<(WORD_BITS*m_modulus.reg.size()))%m_modulus;}<a name="l00133"></a>00133 <a name="l00134"></a>00134 Integer <a class="code" href="class_modular_arithmetic.html#bbd97fd2abfb869063f51cfdeb769c71">ConvertOut</a>(<span class="keyword">const</span> Integer &a) <span class="keyword">const</span>;<a name="l00135"></a>00135 <a name="l00136"></a><a class="code" href="class_montgomery_representation.html#ebab2112b22e0af65d4d0048166ca432">00136</a> <span class="keyword">const</span> Integer& <a class="code" href="class_modular_arithmetic.html#f942a7ca057b363cb7a4c74f15a9530e">MultiplicativeIdentity</a>()<span class="keyword"> const</span><a name="l00137"></a>00137 <span class="keyword"> </span>{<span class="keywordflow">return</span> m_result1 = <a class="code" href="class_integer.html#de53248f5dbb520273a70856b975417c" title="return the integer 2**e">Integer::Power2</a>(WORD_BITS*m_modulus.reg.size())%m_modulus;}<a name="l00138"></a>00138 <a name="l00139"></a>00139 <span class="keyword">const</span> Integer& <a class="code" href="class_modular_arithmetic.html#3b88a85b11eb1a826d26d01bdaafbf0a">Multiply</a>(<span class="keyword">const</span> Integer &a, <span class="keyword">const</span> Integer &b) <span class="keyword">const</span>;<a name="l00140"></a>00140 <a name="l00141"></a>00141 <span class="keyword">const</span> Integer& <a class="code" href="class_modular_arithmetic.html#c378a2527fe2107d3379bc35d7cd0487">Square</a>(<span class="keyword">const</span> Integer &a) <span class="keyword">const</span>;<a name="l00142"></a>00142 <a name="l00143"></a>00143 <span class="keyword">const</span> Integer& <a class="code" href="class_modular_arithmetic.html#e2246ad602514e19f1291cd46b351ed9">MultiplicativeInverse</a>(<span class="keyword">const</span> Integer &a) <span class="keyword">const</span>;<a name="l00144"></a>00144 <a name="l00145"></a><a class="code" href="class_montgomery_representation.html#cd3a38b45b2e1c3d1dd9e1bb43d500fe">00145</a> Integer <a class="code" href="class_modular_arithmetic.html#39c4f7a3fb501adc8d96145aecfb63f0">CascadeExponentiate</a>(<span class="keyword">const</span> Integer &x, <span class="keyword">const</span> Integer &e1, <span class="keyword">const</span> Integer &y, <span class="keyword">const</span> Integer &e2)<span class="keyword"> const</span><a name="l00146"></a>00146 <span class="keyword"> </span>{<span class="keywordflow">return</span> <a class="code" href="class_abstract_ring.html#cbe859e24ea6ee1e22ed2a1261f7f9d0">AbstractRing<Integer>::CascadeExponentiate</a>(x, e1, y, e2);}<a name="l00147"></a>00147 <a name="l00148"></a><a class="code" href="class_montgomery_representation.html#031b2e547e3c748947e295e6e44b404c">00148</a> <span class="keywordtype">void</span> <a class="code" href="class_modular_arithmetic.html#e37f29d8031840d185935819318f90dd">SimultaneousExponentiate</a>(Element *results, <span class="keyword">const</span> Element &base, <span class="keyword">const</span> Integer *exponents, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> exponentsCount)<span class="keyword"> const</span><a name="l00149"></a>00149 <span class="keyword"> </span>{<a class="code" href="class_abstract_ring.html#56b1047d5e1c57d9b3c52e20af464cfe">AbstractRing<Integer>::SimultaneousExponentiate</a>(results, base, exponents, exponentsCount);}<a name="l00150"></a>00150 <a name="l00151"></a>00151 <span class="keyword">private</span>:<a name="l00152"></a>00152 Integer m_u;<a name="l00153"></a>00153 <span class="keyword">mutable</span> <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">IntegerSecBlock</a> m_workspace;<a name="l00154"></a>00154 };<a name="l00155"></a>00155 <a name="l00156"></a>00156 NAMESPACE_END<a name="l00157"></a>00157 <a name="l00158"></a>00158 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Fri Jun 1 11:11:22 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 + -