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

📄 rw_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<a name="l00055"></a>00055                 out &lt;&lt;= 1;<a name="l00056"></a>00056                 <span class="keywordflow">break</span>;<a name="l00057"></a>00057         <span class="keywordflow">default</span>:<a name="l00058"></a>00058                 out = <a class="code" href="class_integer.html#19b7e6d48b1b57bd4846160ea2928175" title="avoid calling constructors for these frequently used integers">Integer::Zero</a>();<a name="l00059"></a>00059         }<a name="l00060"></a>00060         <span class="keywordflow">return</span> out;<a name="l00061"></a>00061 }<a name="l00062"></a>00062 <a name="l00063"></a><a class="code" href="class_r_w_function.html#f326ae91ff9d6719c879861d21d380ac">00063</a> <span class="keywordtype">bool</span> <a class="code" href="class_r_w_function.html#f326ae91ff9d6719c879861d21d380ac" title="check this object for errors">RWFunction::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="l00064"></a>00064 <span class="keyword"></span>{<a name="l00065"></a>00065         <span class="keywordtype">bool</span> pass = <span class="keyword">true</span>;<a name="l00066"></a>00066         pass = pass &amp;&amp; <a class="code" href="class_r_w_function.html#21b3158cafdb7121e6305b742ffb340f">m_n</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_r_w_function.html#21b3158cafdb7121e6305b742ffb340f">m_n</a>%8 == 5;<a name="l00067"></a>00067         <span class="keywordflow">return</span> pass;<a name="l00068"></a>00068 }<a name="l00069"></a>00069 <a name="l00070"></a><a class="code" href="class_r_w_function.html#0c9efa849855d8aa9c907d84d3aebd42">00070</a> <span class="keywordtype">bool</span> <a class="code" href="class_r_w_function.html#0c9efa849855d8aa9c907d84d3aebd42" title="to be implemented by derived classes, users should use one of the above functions...">RWFunction::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="l00071"></a>00071 <span class="keyword"></span>{<a name="l00072"></a>00072         <span class="keywordflow">return</span> GetValueHelper(<span class="keyword">this</span>, name, valueType, pValue).Assignable()<a name="l00073"></a>00073                 CRYPTOPP_GET_FUNCTION_ENTRY(Modulus)<a name="l00074"></a>00074                 ;<a name="l00075"></a>00075 }<a name="l00076"></a>00076 <a name="l00077"></a><a class="code" href="class_r_w_function.html#99293c55c055b338bd7c783a7b8c0484">00077</a> <span class="keywordtype">void</span> <a class="code" href="class_r_w_function.html#99293c55c055b338bd7c783a7b8c0484" title="assign values from source to this object">RWFunction::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="l00078"></a>00078 {<a name="l00079"></a>00079         AssignFromHelper(<span class="keyword">this</span>, source)<a name="l00080"></a>00080                 CRYPTOPP_SET_FUNCTION_ENTRY(Modulus)<a name="l00081"></a>00081                 ;<a name="l00082"></a>00082 }<a name="l00083"></a>00083 <a name="l00084"></a>00084 <span class="comment">// *****************************************************************************</span><a name="l00085"></a>00085 <span class="comment">// private key operations:</span><a name="l00086"></a>00086 <a name="l00087"></a>00087 <span class="comment">// generate a random private key</span><a name="l00088"></a><a class="code" href="class_invertible_r_w_function.html#8953bb59727e0ae2d79071874a793c48">00088</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_r_w_function.html#8953bb59727e0ae2d79071874a793c48">InvertibleRWFunction::GenerateRandom</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &amp;rng, <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;alg)<a name="l00089"></a>00089 {<a name="l00090"></a>00090         <span class="keywordtype">int</span> modulusSize = 2048;<a name="l00091"></a>00091         alg.<a class="code" href="class_name_value_pairs.html#39b6daefcabcdd07f5ae482a075e1728" title="get a named value with type int">GetIntValue</a>(<span class="stringliteral">"ModulusSize"</span>, modulusSize) || alg.<a class="code" href="class_name_value_pairs.html#39b6daefcabcdd07f5ae482a075e1728" title="get a named value with type int">GetIntValue</a>(<span class="stringliteral">"KeySize"</span>, modulusSize);<a name="l00092"></a>00092 <a name="l00093"></a>00093         <span class="keywordflow">if</span> (modulusSize &lt; 16)<a name="l00094"></a>00094                 <span class="keywordflow">throw</span> <a class="code" href="class_invalid_argument.html" title="exception thrown when an invalid argument is detected">InvalidArgument</a>(<span class="stringliteral">"InvertibleRWFunction: specified modulus length is too small"</span>);<a name="l00095"></a>00095 <a name="l00096"></a>00096         <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;primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize);<a name="l00097"></a>00097         <a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a>.<a class="code" href="class_integer.html#0d9a427fe64a454b11b24fe61c10dbeb">GenerateRandom</a>(rng, <a class="code" href="class_combined_name_value_pairs.html">CombinedNameValuePairs</a>(primeParam, MakeParameters(<span class="stringliteral">"EquivalentTo"</span>, 3)(<span class="stringliteral">"Mod"</span>, 8)));<a name="l00098"></a>00098         <a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a>.<a class="code" href="class_integer.html#0d9a427fe64a454b11b24fe61c10dbeb">GenerateRandom</a>(rng, <a class="code" href="class_combined_name_value_pairs.html">CombinedNameValuePairs</a>(primeParam, MakeParameters(<span class="stringliteral">"EquivalentTo"</span>, 7)(<span class="stringliteral">"Mod"</span>, 8)));<a name="l00099"></a>00099 <a name="l00100"></a>00100         <a class="code" href="class_r_w_function.html#21b3158cafdb7121e6305b742ffb340f">m_n</a> = <a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a> * <a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a>;<a name="l00101"></a>00101         <a class="code" href="class_invertible_r_w_function.html#e2afd7a6cc5342f098a858dde9161581">m_u</a> = m_q.<a class="code" href="class_integer.html#881f9c714ee42f35718725a43d4d7db3" title="calculate multiplicative inverse of *this mod n">InverseMod</a>(<a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a>);<a name="l00102"></a>00102 }<a name="l00103"></a>00103 <a name="l00104"></a><a class="code" href="class_invertible_r_w_function.html#85e6ad506b653b4511bfd14d06aa95b5">00104</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_r_w_function.html#85e6ad506b653b4511bfd14d06aa95b5">InvertibleRWFunction::BERDecode</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;bt)<a name="l00105"></a>00105 {<a name="l00106"></a>00106         <a class="code" href="class_b_e_r_sequence_decoder.html" title="BER Sequence Decoder.">BERSequenceDecoder</a> seq(bt);<a name="l00107"></a>00107         <a class="code" href="class_r_w_function.html#21b3158cafdb7121e6305b742ffb340f">m_n</a>.<a class="code" href="class_integer.html#810fc0382f8928893fe192ab79b1972c">BERDecode</a>(seq);<a name="l00108"></a>00108         <a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a>.<a class="code" href="class_integer.html#810fc0382f8928893fe192ab79b1972c">BERDecode</a>(seq);<a name="l00109"></a>00109         <a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a>.<a class="code" href="class_integer.html#810fc0382f8928893fe192ab79b1972c">BERDecode</a>(seq);<a name="l00110"></a>00110         <a class="code" href="class_invertible_r_w_function.html#e2afd7a6cc5342f098a858dde9161581">m_u</a>.<a class="code" href="class_integer.html#810fc0382f8928893fe192ab79b1972c">BERDecode</a>(seq);<a name="l00111"></a>00111         seq.<a class="code" href="class_b_e_r_general_decoder.html#40b14625c98ac7febb8ca218d02358ad">MessageEnd</a>();<a name="l00112"></a>00112 }<a name="l00113"></a>00113 <a name="l00114"></a><a class="code" href="class_invertible_r_w_function.html#a487d8ccbcb409066776ef48721b037a">00114</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_r_w_function.html#a487d8ccbcb409066776ef48721b037a">InvertibleRWFunction::DEREncode</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;bt)<span class="keyword"> const</span><a name="l00115"></a>00115 <span class="keyword"></span>{<a name="l00116"></a>00116         <a class="code" href="class_d_e_r_sequence_encoder.html" title="DER Sequence Encoder.">DERSequenceEncoder</a> seq(bt);<a name="l00117"></a>00117         <a class="code" href="class_r_w_function.html#21b3158cafdb7121e6305b742ffb340f">m_n</a>.<a class="code" href="class_integer.html#6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(seq);<a name="l00118"></a>00118         <a class="code" href="class_invertible_r_w_function.html#b4a121ce0a3f24d29b88b08ed8fa275e">m_p</a>.<a class="code" href="class_integer.html#6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(seq);<a name="l00119"></a>00119         <a class="code" href="class_invertible_r_w_function.html#42013f81c5212a7d2072d2382018ae8d">m_q</a>.<a class="code" href="class_integer.html#6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(seq);<a name="l00120"></a>00120         <a class="code" href="class_invertible_r_w_function.html#e2afd7a6cc5342f098a858dde9161581">m_u</a>.<a class="code" href="class_integer.html#6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(seq);<a name="l00121"></a>00121         seq.<a class="code" href="class_d_e_r_general_encoder.html#cb5f1a94ba97027c603b019bd5228510">MessageEnd</a>();<a name="l00122"></a>00122 }<a name="l00123"></a>00123 <a name="l00124"></a><a class="code" href="class_invertible_r_w_function.html#e72e7da96f9dc18c80e84bb510aab377">00124</a> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> <a class="code" href="class_invertible_r_w_function.html#e72e7da96f9dc18c80e84bb510aab377">InvertibleRWFunction::CalculateInverse</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &amp;rng, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;x)<span class="keyword"> const</span><a name="l00125"></a>00125 <span class="keyword"></span>{<a name="l00126"></a>00126         <a class="code" href="class_crypto_material.html#a1da44802c5cf00946043922cb9e7e6e">DoQuickSanityCheck</a>();<a name="l00127"></a>00127         <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a> modn(<a class="code" href="class_r_w_function.html#21b3158cafdb7121e6305b742ffb340f">m_n</a>);<a name="l00128"></a>00128         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> r, rInv;<a name="l00129"></a>00129         <span class="keywordflow">do</span> {    <span class="comment">// do this in a loop for people using small numbers for testing</span>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -