📄 esign_8cpp-source.html
字号:
<a name="l00059"></a>00059 <span class="keywordflow">return</span> GetValueHelper(<span class="keyword">this</span>, name, valueType, pValue).Assignable()<a name="l00060"></a>00060 CRYPTOPP_GET_FUNCTION_ENTRY(Modulus)<a name="l00061"></a>00061 CRYPTOPP_GET_FUNCTION_ENTRY(PublicExponent)<a name="l00062"></a>00062 ;<a name="l00063"></a>00063 }<a name="l00064"></a>00064 <a name="l00065"></a><a class="code" href="class_e_s_i_g_n_function.html#1ff8229ed7786a13a69d15e5a64e4d21">00065</a> <span class="keywordtype">void</span> <a class="code" href="class_e_s_i_g_n_function.html#1ff8229ed7786a13a69d15e5a64e4d21" title="assign values from source to this object">ESIGNFunction::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="l00066"></a>00066 {<a name="l00067"></a>00067 AssignFromHelper(<span class="keyword">this</span>, source)<a name="l00068"></a>00068 CRYPTOPP_SET_FUNCTION_ENTRY(Modulus)<a name="l00069"></a>00069 CRYPTOPP_SET_FUNCTION_ENTRY(PublicExponent)<a name="l00070"></a>00070 ;<a name="l00071"></a>00071 }<a name="l00072"></a>00072 <a name="l00073"></a>00073 <span class="comment">// *****************************************************************************</span><a name="l00074"></a>00074 <a name="l00075"></a><a class="code" href="class_invertible_e_s_i_g_n_function.html#241b733193f9f420f188ca6f57d49c27">00075</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_e_s_i_g_n_function.html#241b733193f9f420f188ca6f57d49c27">InvertibleESIGNFunction::GenerateRandom</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_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &param)<a name="l00076"></a>00076 {<a name="l00077"></a>00077 <span class="keywordtype">int</span> modulusSize = 1023*2;<a name="l00078"></a>00078 param.<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) || param.<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="l00079"></a>00079 <a name="l00080"></a>00080 <span class="keywordflow">if</span> (modulusSize < 24)<a name="l00081"></a>00081 <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">"InvertibleESIGNFunction: specified modulus size is too small"</span>);<a name="l00082"></a>00082 <a name="l00083"></a>00083 <span class="keywordflow">if</span> (modulusSize % 3 != 0)<a name="l00084"></a>00084 <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">"InvertibleESIGNFunction: modulus size must be divisible by 3"</span>);<a name="l00085"></a>00085 <a name="l00086"></a>00086 <a class="code" href="class_e_s_i_g_n_function.html#086e17e8047753768b22c6b59faebf60">m_e</a> = param.<a class="code" href="class_name_value_pairs.html#943b2009297783f1c35bae46efc3b5f7" title="get a named value, returns the default if the name doesn't exist">GetValueWithDefault</a>(<span class="stringliteral">"PublicExponent"</span>, <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a>(32));<a name="l00087"></a>00087 <a name="l00088"></a>00088 <span class="keywordflow">if</span> (<a class="code" href="class_e_s_i_g_n_function.html#086e17e8047753768b22c6b59faebf60">m_e</a> < 8)<a name="l00089"></a>00089 <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">"InvertibleESIGNFunction: public exponents less than 8 may not be secure"</span>);<a name="l00090"></a>00090 <a name="l00091"></a>00091 <span class="comment">// VC70 workaround: putting these after primeParam causes overlapped stack allocation</span><a name="l00092"></a>00092 <a class="code" href="class_const_byte_array_parameter.html" title="used to pass byte array input as part of a NameValuePairs object">ConstByteArrayParameter</a> seedParam;<a name="l00093"></a>00093 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> seed;<a name="l00094"></a>00094 <a name="l00095"></a>00095 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> minP = <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a>(204) << (modulusSize/3-8);<a name="l00096"></a>00096 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> maxP = <a class="code" href="class_integer.html#de53248f5dbb520273a70856b975417c" title="return the integer 2**e">Integer::Power2</a>(modulusSize/3)-1;<a name="l00097"></a>00097 <span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &primeParam = MakeParameters(<span class="stringliteral">"Min"</span>, minP)(<span class="stringliteral">"Max"</span>, maxP)(<span class="stringliteral">"RandomNumberType"</span>, <a class="code" href="class_integer.html#9b4088ac01abf76b9ba60060abccb7a3fe686f55e5b6768b20009a12522bd0d9">Integer::PRIME</a>);<a name="l00098"></a>00098 <a name="l00099"></a>00099 <span class="keywordflow">if</span> (param.<a class="code" href="class_name_value_pairs.html#96686e9f8d6ce3ab870e516fb72b608e" title="get a named value, returns true if the name exists">GetValue</a>(<span class="stringliteral">"Seed"</span>, seedParam))<a name="l00100"></a>00100 {<a name="l00101"></a>00101 seed.<a class="code" href="class_sec_block.html#f9e98d3f4a7af1156fcf3e6e68f4ae5a" title="change size and preserve contents">resize</a>(seedParam.<a class="code" href="class_const_byte_array_parameter.html#b83dbf7e4d80c0304917a3cc1d3cf144">size</a>() + 4);<a name="l00102"></a>00102 memcpy(seed + 4, seedParam.<a class="code" href="class_const_byte_array_parameter.html#b89acc8dae383f2663dd3864651e8ef1">begin</a>(), seedParam.<a class="code" href="class_const_byte_array_parameter.html#b83dbf7e4d80c0304917a3cc1d3cf144">size</a>());<a name="l00103"></a>00103 <a name="l00104"></a>00104 PutWord(<span class="keyword">false</span>, <a class="code" href="cryptlib_8h.html#aeb92d42f5a6e27b8ba19f18d69d142bf0c3bb6c718cc7ff0bffef4e8f178c57">BIG_ENDIAN_ORDER</a>, seed, (word32)0);<a name="l00105"></a>00105 <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">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">"Seed"</span>, <a class="code" href="class_const_byte_array_parameter.html" title="used to pass byte array input as part of a NameValuePairs object">ConstByteArrayParameter</a>(seed))));<a name="l00106"></a>00106 PutWord(<span class="keyword">false</span>, <a class="code" href="cryptlib_8h.html#aeb92d42f5a6e27b8ba19f18d69d142bf0c3bb6c718cc7ff0bffef4e8f178c57">BIG_ENDIAN_ORDER</a>, seed, (word32)1);<a name="l00107"></a>00107 <a class="code" href="class_invertible_e_s_i_g_n_function.html#dc2b3dc52e2421e408f0e1bb607da135">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">"Seed"</span>, <a class="code" href="class_const_byte_array_parameter.html" title="used to pass byte array input as part of a NameValuePairs object">ConstByteArrayParameter</a>(seed))));<a name="l00108"></a>00108 }<a name="l00109"></a>00109 <span class="keywordflow">else</span><a name="l00110"></a>00110 {<a name="l00111"></a>00111 <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a>.<a class="code" href="class_integer.html#0d9a427fe64a454b11b24fe61c10dbeb">GenerateRandom</a>(rng, primeParam);<a name="l00112"></a>00112 <a class="code" href="class_invertible_e_s_i_g_n_function.html#dc2b3dc52e2421e408f0e1bb607da135">m_q</a>.<a class="code" href="class_integer.html#0d9a427fe64a454b11b24fe61c10dbeb">GenerateRandom</a>(rng, primeParam);<a name="l00113"></a>00113 }<a name="l00114"></a>00114 <a name="l00115"></a>00115 <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</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#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a> * <a class="code" href="class_invertible_e_s_i_g_n_function.html#dc2b3dc52e2421e408f0e1bb607da135">m_q</a>;<a name="l00116"></a>00116 <a name="l00117"></a>00117 assert(<a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a>.<a class="code" href="class_integer.html#867356d88074424328d0ebb9bea63254" title="number of significant bits = floor(log2(abs(*this))) + 1">BitCount</a>() == modulusSize);<a name="l00118"></a>00118 }<a name="l00119"></a>00119 <a name="l00120"></a><a class="code" href="class_invertible_e_s_i_g_n_function.html#7e63d8fe66a25af6611f37bdaac982c4">00120</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_e_s_i_g_n_function.html#7e63d8fe66a25af6611f37bdaac982c4" title="decode this object from a BufferedTransformation, using BER (Basic Encoding Rules)...">InvertibleESIGNFunction::BERDecode</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &bt)<a name="l00121"></a>00121 {<a name="l00122"></a>00122 <a class="code" href="class_b_e_r_sequence_decoder.html" title="BER Sequence Decoder.">BERSequenceDecoder</a> privateKey(bt);<a name="l00123"></a>00123 <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a>.<a class="code" href="class_integer.html#810fc0382f8928893fe192ab79b1972c">BERDecode</a>(privateKey);<a name="l00124"></a>00124 <a class="code" href="class_e_s_i_g_n_function.html#086e17e8047753768b22c6b59faebf60">m_e</a>.<a class="code" href="class_integer.html#810fc0382f8928893fe192ab79b1972c">BERDecode</a>(privateKey);<a name="l00125"></a>00125 <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a>.<a class="code" href="class_integer.html#810fc0382f8928893fe192ab79b1972c">BERDecode</a>(privateKey);<a name="l00126"></a>00126 <a class="code" href="class_invertible_e_s_i_g_n_function.html#dc2b3dc52e2421e408f0e1bb607da135">m_q</a>.<a class="code" href="class_integer.html#810fc0382f8928893fe192ab79b1972c">BERDecode</a>(privateKey);<a name="l00127"></a>00127 privateKey.<a class="code" href="class_b_e_r_general_decoder.html#40b14625c98ac7febb8ca218d02358ad">MessageEnd</a>();<a name="l00128"></a>00128 }<a name="l00129"></a>00129 <a name="l00130"></a><a class="code" href="class_invertible_e_s_i_g_n_function.html#7c12cab3cb37c52da87672ef1bc33f13">00130</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_e_s_i_g_n_function.html#7c12cab3cb37c52da87672ef1bc33f13" title="encode this object into a BufferedTransformation, using DER (Distinguished Encoding...">InvertibleESIGNFunction::DEREncode</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &bt)<span class="keyword"> const</span><a name="l00131"></a>00131 <span class="keyword"></span>{<a name="l00132"></a>00132 <a class="code" href="class_d_e_r_sequence_encoder.html" title="DER Sequence Encoder.">DERSequenceEncoder</a> privateKey(bt);<a name="l00133"></a>00133 <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a>.<a class="code" href="class_integer.html#6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(privateKey);<a name="l00134"></a>00134 <a class="code" href="class_e_s_i_g_n_function.html#086e17e8047753768b22c6b59faebf60">m_e</a>.<a class="code" href="class_integer.html#6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(privateKey);<a name="l00135"></a>00135 <a class="code" href="class_invertible_e_s_i_g_n_function.html#d743ae7fe10fbff6c9dddd88e76fc7fd">m_p</a>.<a class="code" href="class_integer.html#6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(privateKey);<a name="l00136"></a>00136 <a class="code" href="class_invertible_e_s_i_g_n_function.html#dc2b3dc52e2421e408f0e1bb607da135">m_q</a>.<a class="code" href="class_integer.html#6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(privateKey);<a name="l00137"></a>00137 privateKey.<a class="code" href="class_d_e_r_general_encoder.html#cb5f1a94ba97027c603b019bd5228510">MessageEnd</a>();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -