Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > 07dfcfe50d66c9a48a3c5e6c1693f12a > files > 1718

cryptopp-doc-5.6.1-0.1.svn479.fc13.i686.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Crypto++: esign.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>esign.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// esign.cpp - written and placed in the public domain by Wei Dai</span>
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="preprocessor">#include &quot;pch.h&quot;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &quot;<a class="code" href="esign_8h.html" title="This file contains classes that implement the ESIGN signature schemes as defined...">esign.h</a>&quot;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include &quot;asn.h&quot;</span>
<a name="l00006"></a>00006 <span class="preprocessor">#include &quot;modarith.h&quot;</span>
<a name="l00007"></a>00007 <span class="preprocessor">#include &quot;nbtheory.h&quot;</span>
<a name="l00008"></a>00008 <span class="preprocessor">#include &quot;sha.h&quot;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &quot;algparam.h&quot;</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 NAMESPACE_BEGIN(CryptoPP)
<a name="l00012"></a>00012 
<a name="l00013"></a>00013 void ESIGN_TestInstantiations()
<a name="l00014"></a>00014 {
<a name="l00015"></a>00015         <a class="code" href="class_p_k___final_template.html" title="A template implementing constructors for public key algorithm classes.">ESIGN&lt;SHA&gt;::Verifier</a> x1(1, 1);
<a name="l00016"></a>00016         <a class="code" href="class_p_k___final_template.html" title="A template implementing constructors for public key algorithm classes.">ESIGN&lt;SHA&gt;::Signer</a> x2(NullRNG(), 1);
<a name="l00017"></a>00017         <a class="code" href="class_p_k___final_template.html" title="A template implementing constructors for public key algorithm classes.">ESIGN&lt;SHA&gt;::Verifier</a> x3(x2);
<a name="l00018"></a>00018         <a class="code" href="class_p_k___final_template.html" title="A template implementing constructors for public key algorithm classes.">ESIGN&lt;SHA&gt;::Verifier</a> x4(x2.GetKey());
<a name="l00019"></a>00019         <a class="code" href="class_p_k___final_template.html" title="A template implementing constructors for public key algorithm classes.">ESIGN&lt;SHA&gt;::Verifier</a> x5(x3);
<a name="l00020"></a>00020         <a class="code" href="class_p_k___final_template.html" title="A template implementing constructors for public key algorithm classes.">ESIGN&lt;SHA&gt;::Signer</a> x6 = x2;
<a name="l00021"></a>00021 
<a name="l00022"></a>00022         x6 = x2;
<a name="l00023"></a>00023         x3 = <a class="code" href="class_t_f___s_s.html#a65546b9070fbf3960015932defd8b333" title="implements PK_Verifier interface">ESIGN&lt;SHA&gt;::Verifier</a>(x2);
<a name="l00024"></a>00024         x4 = x2.GetKey();
<a name="l00025"></a>00025 }
<a name="l00026"></a>00026 
<a name="l00027"></a><a class="code" href="class_e_s_i_g_n_function.html#a6517cb00d59eb584c9ecf86d3dce6742">00027</a> <span class="keywordtype">void</span> <a class="code" href="class_e_s_i_g_n_function.html#a6517cb00d59eb584c9ecf86d3dce6742" title="decode this object from a BufferedTransformation, using BER (Basic Encoding Rules)...">ESIGNFunction::BERDecode</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;bt)
<a name="l00028"></a>00028 {
<a name="l00029"></a>00029         <a class="code" href="class_b_e_r_sequence_decoder.html" title="BER Sequence Decoder.">BERSequenceDecoder</a> seq(bt);
<a name="l00030"></a>00030                 m_n.BERDecode(seq);
<a name="l00031"></a>00031                 m_e.BERDecode(seq);
<a name="l00032"></a>00032         seq.MessageEnd();
<a name="l00033"></a>00033 }
<a name="l00034"></a>00034 
<a name="l00035"></a><a class="code" href="class_e_s_i_g_n_function.html#a524f9708759975ed9a9481ee94b9eb08">00035</a> <span class="keywordtype">void</span> <a class="code" href="class_e_s_i_g_n_function.html#a524f9708759975ed9a9481ee94b9eb08" title="encode this object into a BufferedTransformation, using DER (Distinguished Encoding...">ESIGNFunction::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="l00036"></a>00036 <span class="keyword"></span>{
<a name="l00037"></a>00037         <a class="code" href="class_d_e_r_sequence_encoder.html" title="DER Sequence Encoder.">DERSequenceEncoder</a> seq(bt);
<a name="l00038"></a>00038                 m_n.<a class="code" href="class_integer.html#a6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(seq);
<a name="l00039"></a>00039                 m_e.<a class="code" href="class_integer.html#a6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(seq);
<a name="l00040"></a>00040         seq.MessageEnd();
<a name="l00041"></a>00041 }
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> ESIGNFunction::ApplyFunction(<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="l00044"></a>00044 <span class="keyword"></span>{
<a name="l00045"></a>00045         DoQuickSanityCheck();
<a name="l00046"></a>00046         <span class="keywordflow">return</span> STDMIN(a_exp_b_mod_c(x, m_e, m_n) &gt;&gt; (2*GetK()+2), MaxImage());
<a name="l00047"></a>00047 }
<a name="l00048"></a>00048 
<a name="l00049"></a><a class="code" href="class_e_s_i_g_n_function.html#ad9696d3e060bd7acb702b5bfa650eeb7">00049</a> <span class="keywordtype">bool</span> <a class="code" href="class_e_s_i_g_n_function.html#ad9696d3e060bd7acb702b5bfa650eeb7" title="check this object for errors">ESIGNFunction::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="l00050"></a>00050 <span class="keyword"></span>{
<a name="l00051"></a>00051         <span class="keywordtype">bool</span> pass = <span class="keyword">true</span>;
<a name="l00052"></a>00052         pass = pass &amp;&amp; m_n &gt; <a class="code" href="class_integer.html#a8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>() &amp;&amp; m_n.IsOdd();
<a name="l00053"></a>00053         pass = pass &amp;&amp; m_e &gt;= 8 &amp;&amp; m_e &lt; m_n;
<a name="l00054"></a>00054         <span class="keywordflow">return</span> pass;
<a name="l00055"></a>00055 }
<a name="l00056"></a>00056 
<a name="l00057"></a><a class="code" href="class_e_s_i_g_n_function.html#a53def4f94e81acd0e02a3e50fb9b15ee">00057</a> <span class="keywordtype">bool</span> <a class="code" href="class_e_s_i_g_n_function.html#a53def4f94e81acd0e02a3e50fb9b15ee" title="to be implemented by derived classes, users should use one of the above functions...">ESIGNFunction::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="l00058"></a>00058 <span class="keyword"></span>{
<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#a1ff8229ed7786a13a69d15e5a64e4d21">00065</a> <span class="keywordtype">void</span> <a class="code" href="class_e_s_i_g_n_function.html#a1ff8229ed7786a13a69d15e5a64e4d21" 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> &amp;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#a241b733193f9f420f188ca6f57d49c27">00075</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_e_s_i_g_n_function.html#a241b733193f9f420f188ca6f57d49c27">InvertibleESIGNFunction::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;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#a39b6daefcabcdd07f5ae482a075e1728" title="get a named value with type int">GetIntValue</a>(<span class="stringliteral">&quot;ModulusSize&quot;</span>, modulusSize) || param.<a class="code" href="class_name_value_pairs.html#a39b6daefcabcdd07f5ae482a075e1728" title="get a named value with type int">GetIntValue</a>(<span class="stringliteral">&quot;KeySize&quot;</span>, modulusSize);
<a name="l00079"></a>00079 
<a name="l00080"></a>00080         <span class="keywordflow">if</span> (modulusSize &lt; 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">&quot;InvertibleESIGNFunction: specified modulus size is too small&quot;</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">&quot;InvertibleESIGNFunction: modulus size must be divisible by 3&quot;</span>);
<a name="l00085"></a>00085 
<a name="l00086"></a>00086         m_e = param.<a class="code" href="class_name_value_pairs.html#a943b2009297783f1c35bae46efc3b5f7" title="get a named value, returns the default if the name doesn&amp;#39;t exist">GetValueWithDefault</a>(<span class="stringliteral">&quot;PublicExponent&quot;</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> (m_e &lt; 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">&quot;InvertibleESIGNFunction: public exponents less than 8 may not be secure&quot;</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">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) &lt;&lt; (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#ade53248f5dbb520273a70856b975417c" title="return the integer 2**e">Integer::Power2</a>(modulusSize/3)-1;
<a name="l00097"></a>00097         <a class="code" href="class_algorithm_parameters.html">AlgorithmParameters</a> primeParam = MakeParameters(<span class="stringliteral">&quot;Min&quot;</span>, minP)(<span class="stringliteral">&quot;Max&quot;</span>, maxP)(<span class="stringliteral">&quot;RandomNumberType&quot;</span>, Integer::PRIME);
<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#a96686e9f8d6ce3ab870e516fb72b608e" title="get a named value, returns true if the name exists">GetValue</a>(<span class="stringliteral">&quot;Seed&quot;</span>, seedParam))
<a name="l00100"></a>00100         {
<a name="l00101"></a>00101                 seed.<a class="code" href="class_sec_block.html#af9e98d3f4a7af1156fcf3e6e68f4ae5a" title="change size and preserve contents">resize</a>(seedParam.size() + 4);
<a name="l00102"></a>00102                 memcpy(seed + 4, seedParam.begin(), seedParam.size());
<a name="l00103"></a>00103 
<a name="l00104"></a>00104                 PutWord(<span class="keyword">false</span>, BIG_ENDIAN_ORDER, seed, (word32)0);
<a name="l00105"></a>00105                 m_p.GenerateRandom(rng, <a class="code" href="class_combined_name_value_pairs.html">CombinedNameValuePairs</a>(primeParam, MakeParameters(<span class="stringliteral">&quot;Seed&quot;</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>, BIG_ENDIAN_ORDER, seed, (word32)1);
<a name="l00107"></a>00107                 m_q.GenerateRandom(rng, <a class="code" href="class_combined_name_value_pairs.html">CombinedNameValuePairs</a>(primeParam, MakeParameters(<span class="stringliteral">&quot;Seed&quot;</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                 m_p.GenerateRandom(rng, primeParam);
<a name="l00112"></a>00112                 m_q.GenerateRandom(rng, primeParam);
<a name="l00113"></a>00113         }
<a name="l00114"></a>00114 
<a name="l00115"></a>00115         m_n = m_p * m_p * m_q;
<a name="l00116"></a>00116 
<a name="l00117"></a>00117         assert(m_n.<a class="code" href="class_integer.html#a178398002ab175e788a3bc224e5e5a8d" 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#a7e63d8fe66a25af6611f37bdaac982c4">00120</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_e_s_i_g_n_function.html#a7e63d8fe66a25af6611f37bdaac982c4" 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> &amp;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                 m_n.BERDecode(privateKey);
<a name="l00124"></a>00124                 m_e.BERDecode(privateKey);
<a name="l00125"></a>00125                 m_p.BERDecode(privateKey);
<a name="l00126"></a>00126                 m_q.BERDecode(privateKey);
<a name="l00127"></a>00127         privateKey.MessageEnd();
<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#a7c12cab3cb37c52da87672ef1bc33f13">00130</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_e_s_i_g_n_function.html#a7c12cab3cb37c52da87672ef1bc33f13" 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> &amp;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                 m_n.<a class="code" href="class_integer.html#a6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(privateKey);
<a name="l00134"></a>00134                 m_e.<a class="code" href="class_integer.html#a6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(privateKey);
<a name="l00135"></a>00135                 m_p.<a class="code" href="class_integer.html#a6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(privateKey);
<a name="l00136"></a>00136                 m_q.<a class="code" href="class_integer.html#a6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(privateKey);
<a name="l00137"></a>00137         privateKey.MessageEnd();
<a name="l00138"></a>00138 }
<a name="l00139"></a>00139 
<a name="l00140"></a>00140 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> InvertibleESIGNFunction::CalculateRandomizedInverse(<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="l00141"></a>00141 <span class="keyword"></span>{
<a name="l00142"></a>00142         DoQuickSanityCheck();
<a name="l00143"></a>00143 
<a name="l00144"></a>00144         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> pq = m_p * m_q;
<a name="l00145"></a>00145         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> p2 = m_p * m_p;
<a name="l00146"></a>00146         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> r, z, re, a, w0, w1;
<a name="l00147"></a>00147 
<a name="l00148"></a>00148         <span class="keywordflow">do</span>
<a name="l00149"></a>00149         {
<a name="l00150"></a>00150                 r.Randomize(rng, <a class="code" href="class_integer.html#a19b7e6d48b1b57bd4846160ea2928175" title="avoid calling constructors for these frequently used integers">Integer::Zero</a>(), pq);
<a name="l00151"></a>00151                 z = x &lt;&lt; (2*GetK()+2);
<a name="l00152"></a>00152                 re = a_exp_b_mod_c(r, m_e, m_n);
<a name="l00153"></a>00153                 a = (z - re) % m_n;
<a name="l00154"></a>00154                 <a class="code" href="class_integer.html#a567c89aa176b354143c99d558d05a5fb" title="calculate r and q such that (a == d*q + r) &amp;amp;&amp;amp; (0 &amp;lt;= r &amp;lt; abs(d))">Integer::Divide</a>(w1, w0, a, pq);
<a name="l00155"></a>00155                 <span class="keywordflow">if</span> (w1.NotZero())
<a name="l00156"></a>00156                 {
<a name="l00157"></a>00157                         ++w0;
<a name="l00158"></a>00158                         w1 = pq - w1;
<a name="l00159"></a>00159                 }
<a name="l00160"></a>00160         }
<a name="l00161"></a>00161         <span class="keywordflow">while</span> ((w1 &gt;&gt; 2*GetK()+1).IsPositive());
<a name="l00162"></a>00162 
<a name="l00163"></a>00163         <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a> modp(m_p);
<a name="l00164"></a>00164         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> t = modp.Divide(w0 * r % m_p, m_e * re % m_p);
<a name="l00165"></a>00165         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> s = r + t*pq;
<a name="l00166"></a>00166         assert(s &lt; m_n);
<a name="l00167"></a>00167 <span class="comment">/*</span>
<a name="l00168"></a>00168 <span class="comment">        using namespace std;</span>
<a name="l00169"></a>00169 <span class="comment">        cout &lt;&lt; &quot;f = &quot; &lt;&lt; x &lt;&lt; endl;</span>
<a name="l00170"></a>00170 <span class="comment">        cout &lt;&lt; &quot;r = &quot; &lt;&lt; r &lt;&lt; endl;</span>
<a name="l00171"></a>00171 <span class="comment">        cout &lt;&lt; &quot;z = &quot; &lt;&lt; z &lt;&lt; endl;</span>
<a name="l00172"></a>00172 <span class="comment">        cout &lt;&lt; &quot;a = &quot; &lt;&lt; a &lt;&lt; endl;</span>
<a name="l00173"></a>00173 <span class="comment">        cout &lt;&lt; &quot;w0 = &quot; &lt;&lt; w0 &lt;&lt; endl;</span>
<a name="l00174"></a>00174 <span class="comment">        cout &lt;&lt; &quot;w1 = &quot; &lt;&lt; w1 &lt;&lt; endl;</span>
<a name="l00175"></a>00175 <span class="comment">        cout &lt;&lt; &quot;t = &quot; &lt;&lt; t &lt;&lt; endl;</span>
<a name="l00176"></a>00176 <span class="comment">        cout &lt;&lt; &quot;s = &quot; &lt;&lt; s &lt;&lt; endl;</span>
<a name="l00177"></a>00177 <span class="comment">*/</span>
<a name="l00178"></a>00178         <span class="keywordflow">return</span> s;
<a name="l00179"></a>00179 }
<a name="l00180"></a>00180 
<a name="l00181"></a><a class="code" href="class_invertible_e_s_i_g_n_function.html#a7ff23978311f9f86024f8287d3fd02a8">00181</a> <span class="keywordtype">bool</span> <a class="code" href="class_invertible_e_s_i_g_n_function.html#a7ff23978311f9f86024f8287d3fd02a8" title="check this object for errors">InvertibleESIGNFunction::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="l00182"></a>00182 <span class="keyword"></span>{
<a name="l00183"></a>00183         <span class="keywordtype">bool</span> pass = <a class="code" href="class_invertible_e_s_i_g_n_function.html#a7ff23978311f9f86024f8287d3fd02a8" title="check this object for errors">ESIGNFunction::Validate</a>(rng, level);
<a name="l00184"></a>00184         pass = pass &amp;&amp; m_p &gt; <a class="code" href="class_integer.html#a8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>() &amp;&amp; m_p.IsOdd() &amp;&amp; m_p &lt; m_n;
<a name="l00185"></a>00185         pass = pass &amp;&amp; m_q &gt; <a class="code" href="class_integer.html#a8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>() &amp;&amp; m_q.IsOdd() &amp;&amp; m_q &lt; m_n;
<a name="l00186"></a>00186         pass = pass &amp;&amp; m_p.BitCount() == m_q.BitCount();
<a name="l00187"></a>00187         <span class="keywordflow">if</span> (level &gt;= 1)
<a name="l00188"></a>00188                 pass = pass &amp;&amp; m_p * m_p * m_q == m_n;
<a name="l00189"></a>00189         <span class="keywordflow">if</span> (level &gt;= 2)
<a name="l00190"></a>00190                 pass = pass &amp;&amp; VerifyPrime(rng, m_p, level-2) &amp;&amp; VerifyPrime(rng, m_q, level-2);
<a name="l00191"></a>00191         <span class="keywordflow">return</span> pass;
<a name="l00192"></a>00192 }
<a name="l00193"></a>00193 
<a name="l00194"></a><a class="code" href="class_invertible_e_s_i_g_n_function.html#a6532958ce2c456eef8b84c33f69e944d">00194</a> <span class="keywordtype">bool</span> <a class="code" href="class_invertible_e_s_i_g_n_function.html#a6532958ce2c456eef8b84c33f69e944d" title="to be implemented by derived classes, users should use one of the above functions...">InvertibleESIGNFunction::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="l00195"></a>00195 <span class="keyword"></span>{
<a name="l00196"></a>00196         <span class="keywordflow">return</span> GetValueHelper&lt;ESIGNFunction&gt;(<span class="keyword">this</span>, name, valueType, pValue).Assignable()
<a name="l00197"></a>00197                 CRYPTOPP_GET_FUNCTION_ENTRY(Prime1)
<a name="l00198"></a>00198                 CRYPTOPP_GET_FUNCTION_ENTRY(Prime2)
<a name="l00199"></a>00199                 ;
<a name="l00200"></a>00200 }
<a name="l00201"></a>00201 
<a name="l00202"></a><a class="code" href="class_invertible_e_s_i_g_n_function.html#aca870e350b30d04a47d452f21e903278">00202</a> <span class="keywordtype">void</span> <a class="code" href="class_invertible_e_s_i_g_n_function.html#aca870e350b30d04a47d452f21e903278" title="assign values from source to this object">InvertibleESIGNFunction::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="l00203"></a>00203 {
<a name="l00204"></a>00204         AssignFromHelper&lt;ESIGNFunction&gt;(<span class="keyword">this</span>, source)
<a name="l00205"></a>00205                 CRYPTOPP_SET_FUNCTION_ENTRY(Prime1)
<a name="l00206"></a>00206                 CRYPTOPP_SET_FUNCTION_ENTRY(Prime2)
<a name="l00207"></a>00207                 ;
<a name="l00208"></a>00208 }
<a name="l00209"></a>00209 
<a name="l00210"></a>00210 NAMESPACE_END
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on 9 Dec 2009 for Crypto++ by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>