📄 xtrcrypt_8cpp-source.html
字号:
<a name="l00048"></a>00048 <span class="keywordflow">if</span> (level >= 1)<a name="l00049"></a>00049 pass = pass && ((m_p.<a class="code" href="class_integer.html#7b5e639045868c5ac338f4180e1c7efa">Squared</a>()-m_p+1)%m_q).IsZero();<a name="l00050"></a>00050 <span class="keywordflow">if</span> (level >= 2)<a name="l00051"></a>00051 {<a name="l00052"></a>00052 pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);<a name="l00053"></a>00053 pass = pass && XTR_Exponentiate(m_g, (m_p.<a class="code" href="class_integer.html#7b5e639045868c5ac338f4180e1c7efa">Squared</a>()-m_p+1)/m_q, m_p) != three;<a name="l00054"></a>00054 pass = pass && XTR_Exponentiate(m_g, m_q, m_p) == three;<a name="l00055"></a>00055 }<a name="l00056"></a>00056 <span class="keywordflow">return</span> pass;<a name="l00057"></a>00057 }<a name="l00058"></a>00058 <a name="l00059"></a><a class="code" href="class_x_t_r___d_h.html#a27f618e7ee5c615d5288db47f254b1c">00059</a> <span class="keywordtype">bool</span> <a class="code" href="class_x_t_r___d_h.html#a27f618e7ee5c615d5288db47f254b1c" title="to be implemented by derived classes, users should use one of the above functions...">XTR_DH::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="l00060"></a>00060 <span class="keyword"></span>{<a name="l00061"></a>00061 <span class="keywordflow">return</span> GetValueHelper(<span class="keyword">this</span>, name, valueType, pValue).Assignable()<a name="l00062"></a>00062 CRYPTOPP_GET_FUNCTION_ENTRY(Modulus)<a name="l00063"></a>00063 CRYPTOPP_GET_FUNCTION_ENTRY(SubgroupOrder)<a name="l00064"></a>00064 CRYPTOPP_GET_FUNCTION_ENTRY(SubgroupGenerator)<a name="l00065"></a>00065 ;<a name="l00066"></a>00066 }<a name="l00067"></a>00067 <a name="l00068"></a><a class="code" href="class_x_t_r___d_h.html#f2456cb49f5b36edaaef3c0cae25a775">00068</a> <span class="keywordtype">void</span> <a class="code" href="class_x_t_r___d_h.html#f2456cb49f5b36edaaef3c0cae25a775" title="assign values from source to this object">XTR_DH::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="l00069"></a>00069 {<a name="l00070"></a>00070 AssignFromHelper(<span class="keyword">this</span>, source)<a name="l00071"></a>00071 CRYPTOPP_SET_FUNCTION_ENTRY(Modulus)<a name="l00072"></a>00072 CRYPTOPP_SET_FUNCTION_ENTRY(SubgroupOrder)<a name="l00073"></a>00073 CRYPTOPP_SET_FUNCTION_ENTRY(SubgroupGenerator)<a name="l00074"></a>00074 ;<a name="l00075"></a>00075 }<a name="l00076"></a>00076 <a name="l00077"></a><a class="code" href="class_x_t_r___d_h.html#f9546b08d1b46a84675cfded8f1176f2">00077</a> <span class="keywordtype">void</span> <a class="code" href="class_x_t_r___d_h.html#f9546b08d1b46a84675cfded8f1176f2" title="generate private key">XTR_DH::GeneratePrivateKey</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, byte *privateKey)<span class="keyword"> const</span><a name="l00078"></a>00078 <span class="keyword"></span>{<a name="l00079"></a>00079 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> x(rng, <a class="code" href="class_integer.html#19b7e6d48b1b57bd4846160ea2928175" title="avoid calling constructors for these frequently used integers">Integer::Zero</a>(), m_q-1);<a name="l00080"></a>00080 x.<a class="code" href="class_integer.html#c12ea467de9a609b86ec03d8cb8837e4" title="encode in big-endian format">Encode</a>(privateKey, <a class="code" href="class_x_t_r___d_h.html#e3f6c87695d27b57f218daa0a7a19a6b" title="return length of private keys in this domain">PrivateKeyLength</a>());<a name="l00081"></a>00081 }<a name="l00082"></a>00082 <a name="l00083"></a><a class="code" href="class_x_t_r___d_h.html#9b2d088f034d458abccc7fea30a22412">00083</a> <span class="keywordtype">void</span> <a class="code" href="class_x_t_r___d_h.html#9b2d088f034d458abccc7fea30a22412" title="generate public key">XTR_DH::GeneratePublicKey</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <span class="keyword">const</span> byte *privateKey, byte *publicKey)<span class="keyword"> const</span><a name="l00084"></a>00084 <span class="keyword"></span>{<a name="l00085"></a>00085 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> x(privateKey, <a class="code" href="class_x_t_r___d_h.html#e3f6c87695d27b57f218daa0a7a19a6b" title="return length of private keys in this domain">PrivateKeyLength</a>());<a name="l00086"></a>00086 <a class="code" href="class_g_f_p2_element.html" title="an element of GF(p^2)">GFP2Element</a> y = XTR_Exponentiate(m_g, x, m_p);<a name="l00087"></a>00087 y.<a class="code" href="class_g_f_p2_element.html#b5c1499bcfd8c52cbc145384aded0363">Encode</a>(publicKey, <a class="code" href="class_x_t_r___d_h.html#d8086f9959a856e7c1279b18af566b6c" title="return length of public keys in this domain">PublicKeyLength</a>());<a name="l00088"></a>00088 }<a name="l00089"></a>00089 <a name="l00090"></a><a class="code" href="class_x_t_r___d_h.html#6947d070cbdba7b811cc79a33a3c6632">00090</a> <span class="keywordtype">bool</span> <a class="code" href="class_x_t_r___d_h.html#6947d070cbdba7b811cc79a33a3c6632" title="derive agreed value from your private key and couterparty's public key, return false...">XTR_DH::Agree</a>(byte *agreedValue, <span class="keyword">const</span> byte *privateKey, <span class="keyword">const</span> byte *otherPublicKey, <span class="keywordtype">bool</span> validateOtherPublicKey)<span class="keyword"> const</span><a name="l00091"></a>00091 <span class="keyword"></span>{<a name="l00092"></a>00092 <a class="code" href="class_g_f_p2_element.html" title="an element of GF(p^2)">GFP2Element</a> w(otherPublicKey, <a class="code" href="class_x_t_r___d_h.html#d8086f9959a856e7c1279b18af566b6c" title="return length of public keys in this domain">PublicKeyLength</a>());<a name="l00093"></a>00093 <span class="keywordflow">if</span> (validateOtherPublicKey)<a name="l00094"></a>00094 {<a name="l00095"></a>00095 <a class="code" href="class_g_f_p2___o_n_b.html" title="GF(p^2), optimal normal basis.">GFP2_ONB<ModularArithmetic></a> gfp2(m_p);<a name="l00096"></a>00096 <a class="code" href="class_g_f_p2_element.html" title="an element of GF(p^2)">GFP2Element</a> three = gfp2.<a class="code" href="class_g_f_p2___o_n_b.html#39b2b3a19f057b43e44159d3ca477861">ConvertIn</a>(3);<a name="l00097"></a>00097 <span class="keywordflow">if</span> (w.<a class="code" href="class_g_f_p2_element.html#65778354421ad2da42fce4221e6da05c">c1</a>.<a class="code" href="class_integer.html#d767ae81c89be3804da8785e132d2d1f">IsNegative</a>() || w.<a class="code" href="class_g_f_p2_element.html#1688b28610e1b080a9304daad7c73bbb">c2</a>.<a class="code" href="class_integer.html#d767ae81c89be3804da8785e132d2d1f">IsNegative</a>() || w.<a class="code" href="class_g_f_p2_element.html#65778354421ad2da42fce4221e6da05c">c1</a> >= m_p || w.<a class="code" href="class_g_f_p2_element.html#1688b28610e1b080a9304daad7c73bbb">c2</a> >= m_p || w == three)<a name="l00098"></a>00098 <span class="keywordflow">return</span> <span class="keyword">false</span>;<a name="l00099"></a>00099 <span class="keywordflow">if</span> (XTR_Exponentiate(w, m_q, m_p) != three)<a name="l00100"></a>00100 <span class="keywordflow">return</span> <span class="keyword">false</span>;<a name="l00101"></a>00101 }<a name="l00102"></a>00102 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> s(privateKey, <a class="code" href="class_x_t_r___d_h.html#e3f6c87695d27b57f218daa0a7a19a6b" title="return length of private keys in this domain">PrivateKeyLength</a>());<a name="l00103"></a>00103 <a class="code" href="class_g_f_p2_element.html" title="an element of GF(p^2)">GFP2Element</a> z = XTR_Exponentiate(w, s, m_p);<a name="l00104"></a>00104 z.<a class="code" href="class_g_f_p2_element.html#b5c1499bcfd8c52cbc145384aded0363">Encode</a>(agreedValue, <a class="code" href="class_x_t_r___d_h.html#68d30b38dde37f451a539d0d1907408d" title="return length of agreed value produced">AgreedValueLength</a>());<a name="l00105"></a>00105 <span class="keywordflow">return</span> <span class="keyword">true</span>;<a name="l00106"></a>00106 }<a name="l00107"></a>00107 <a name="l00108"></a>00108 NAMESPACE_END</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Fri Jun 1 11:11:26 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 + -