Sophie

Sophie

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

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++: gfpcrypt.h 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>gfpcrypt.h</h1><a href="gfpcrypt_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef CRYPTOPP_GFPCRYPT_H</span>
<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_GFPCRYPT_H</span>
<a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment"></span>
<a name="l00004"></a>00004 <span class="comment">/** \file</span>
<a name="l00005"></a>00005 <span class="comment">        Implementation of schemes based on DL over GF(p)</span>
<a name="l00006"></a>00006 <span class="comment">*/</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="preprocessor">#include &quot;<a class="code" href="pubkey_8h.html" title="This file contains helper classes/functions for implementing public key algorithms...">pubkey.h</a>&quot;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &quot;modexppc.h&quot;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &quot;sha.h&quot;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &quot;algparam.h&quot;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &quot;asn.h&quot;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &quot;smartptr.h&quot;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &quot;hmac.h&quot;</span>
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;limits.h&gt;</span>
<a name="l00017"></a>00017 
<a name="l00018"></a>00018 NAMESPACE_BEGIN(CryptoPP)
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 CRYPTOPP_DLL_TEMPLATE_CLASS <a class="code" href="class_d_l___group_parameters.html" title="interface for DL group parameters">DL_GroupParameters</a>&lt;<a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a>&gt;;
<a name="l00021"></a>00021 <span class="comment"></span>
<a name="l00022"></a>00022 <span class="comment">//! _</span>
<a name="l00023"></a><a class="code" href="class_d_l___group_parameters___integer_based.html">00023</a> <span class="comment"></span>class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE <a class="code" href="class_d_l___group_parameters___integer_based.html" title="_">DL_GroupParameters_IntegerBased</a> : public <a class="code" href="class_a_s_n1_crypto_material.html" title="_">ASN1CryptoMaterial</a>&lt;<a class="code" href="class_d_l___group_parameters.html" title="interface for DL group parameters">DL_GroupParameters</a>&lt;Integer&gt; &gt;
<a name="l00024"></a>00024 {
<a name="l00025"></a>00025         <span class="keyword">typedef</span> <a class="code" href="class_d_l___group_parameters___integer_based.html" title="_">DL_GroupParameters_IntegerBased</a> <a class="code" href="class_d_l___group_parameters___integer_based.html" title="_">ThisClass</a>;
<a name="l00026"></a>00026         
<a name="l00027"></a>00027 <span class="keyword">public</span>:
<a name="l00028"></a>00028         <span class="keywordtype">void</span> Initialize(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters___integer_based.html" title="_">DL_GroupParameters_IntegerBased</a> &amp;params)
<a name="l00029"></a>00029                 {Initialize(params.GetModulus(), params.GetSubgroupOrder(), params.GetSubgroupGenerator());}
<a name="l00030"></a>00030         <span class="keywordtype">void</span> Initialize(<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> pbits)
<a name="l00031"></a>00031                 {GenerateRandom(rng, MakeParameters(<span class="stringliteral">&quot;ModulusSize&quot;</span>, (<span class="keywordtype">int</span>)pbits));}
<a name="l00032"></a>00032         <span class="keywordtype">void</span> Initialize(<span class="keyword">const</span> Integer &amp;p, <span class="keyword">const</span> Integer &amp;g)
<a name="l00033"></a>00033                 {SetModulusAndSubgroupGenerator(p, g); SetSubgroupOrder(ComputeGroupOrder(p)/2);}
<a name="l00034"></a>00034         <span class="keywordtype">void</span> Initialize(<span class="keyword">const</span> Integer &amp;p, <span class="keyword">const</span> Integer &amp;q, <span class="keyword">const</span> Integer &amp;g)
<a name="l00035"></a>00035                 {SetModulusAndSubgroupGenerator(p, g); SetSubgroupOrder(q);}
<a name="l00036"></a>00036 
<a name="l00037"></a>00037         <span class="comment">// ASN1Object interface</span>
<a name="l00038"></a>00038         <span class="keywordtype">void</span> BERDecode(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;bt);
<a name="l00039"></a>00039         <span class="keywordtype">void</span> DEREncode(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;bt) <span class="keyword">const</span>;
<a name="l00040"></a>00040 
<a name="l00041"></a>00041         <span class="comment">// GeneratibleCryptoMaterial interface</span><span class="comment"></span>
<a name="l00042"></a>00042 <span class="comment">        /*! parameters: (ModulusSize, SubgroupOrderSize (optional)) */</span>
<a name="l00043"></a>00043         <span class="keywordtype">void</span> GenerateRandom(<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="l00044"></a>00044         <span class="keywordtype">bool</span> GetVoidValue(<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="l00045"></a>00045         <span class="keywordtype">void</span> AssignFrom(<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="l00046"></a>00046         
<a name="l00047"></a>00047         <span class="comment">// DL_GroupParameters</span>
<a name="l00048"></a>00048         <span class="keyword">const</span> Integer &amp; GetSubgroupOrder()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_q;}
<a name="l00049"></a>00049         Integer GetGroupOrder()<span class="keyword"> const </span>{<span class="keywordflow">return</span> GetFieldType() == 1 ? GetModulus()-<a class="code" href="class_integer.html#a8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>() : GetModulus()+<a class="code" href="class_integer.html#a8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>();}
<a name="l00050"></a>00050         <span class="keywordtype">bool</span> ValidateGroup(<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="l00051"></a>00051         <span class="keywordtype">bool</span> ValidateElement(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> level, <span class="keyword">const</span> Integer &amp;element, <span class="keyword">const</span> <a class="code" href="class_d_l___fixed_base_precomputation.html">DL_FixedBasePrecomputation&lt;Integer&gt;</a> *precomp) <span class="keyword">const</span>;
<a name="l00052"></a>00052         <span class="keywordtype">bool</span> FastSubgroupCheckAvailable()<span class="keyword"> const </span>{<span class="keywordflow">return</span> GetCofactor() == 2;}
<a name="l00053"></a>00053         <span class="keywordtype">void</span> EncodeElement(<span class="keywordtype">bool</span> reversible, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Element</a> &amp;element, byte *encoded)<span class="keyword"> const</span>
<a name="l00054"></a>00054 <span class="keyword">                </span>{element.<a class="code" href="class_integer.html#ac12ea467de9a609b86ec03d8cb8837e4" title="encode in big-endian format">Encode</a>(encoded, GetModulus().ByteCount());}
<a name="l00055"></a>00055         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> GetEncodedElementSize(<span class="keywordtype">bool</span> reversible)<span class="keyword"> const </span>{<span class="keywordflow">return</span> GetModulus().ByteCount();}
<a name="l00056"></a>00056         Integer DecodeElement(<span class="keyword">const</span> byte *encoded, <span class="keywordtype">bool</span> checkForGroupMembership) <span class="keyword">const</span>;
<a name="l00057"></a>00057         Integer ConvertElementToInteger(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Element</a> &amp;element)<span class="keyword"> const</span>
<a name="l00058"></a>00058 <span class="keyword">                </span>{<span class="keywordflow">return</span> element;}
<a name="l00059"></a>00059         Integer GetMaxExponent() <span class="keyword">const</span>;
<a name="l00060"></a>00060         <span class="keyword">static</span> std::string CRYPTOPP_API StaticAlgorithmNamePrefix() {<span class="keywordflow">return</span> <span class="stringliteral">&quot;&quot;</span>;}
<a name="l00061"></a>00061 
<a name="l00062"></a>00062         <a class="code" href="class_o_i_d.html" title="Object Identifier.">OID</a> GetAlgorithmID() <span class="keyword">const</span>;
<a name="l00063"></a>00063 
<a name="l00064"></a>00064         <span class="keyword">virtual</span> <span class="keyword">const</span> Integer &amp; GetModulus() <span class="keyword">const</span> =0;
<a name="l00065"></a>00065         <span class="keyword">virtual</span> <span class="keywordtype">void</span> SetModulusAndSubgroupGenerator(<span class="keyword">const</span> Integer &amp;p, <span class="keyword">const</span> Integer &amp;g) =0;
<a name="l00066"></a>00066 
<a name="l00067"></a>00067         <span class="keywordtype">void</span> SetSubgroupOrder(<span class="keyword">const</span> Integer &amp;q)
<a name="l00068"></a>00068                 {m_q = q; ParametersChanged();}
<a name="l00069"></a>00069 
<a name="l00070"></a>00070 <span class="keyword">protected</span>:
<a name="l00071"></a>00071         Integer ComputeGroupOrder(<span class="keyword">const</span> Integer &amp;modulus)<span class="keyword"> const</span>
<a name="l00072"></a>00072 <span class="keyword">                </span>{<span class="keywordflow">return</span> modulus-(GetFieldType() == 1 ? 1 : -1);}
<a name="l00073"></a>00073 
<a name="l00074"></a>00074         <span class="comment">// GF(p) = 1, GF(p^2) = 2</span>
<a name="l00075"></a>00075         <span class="keyword">virtual</span> <span class="keywordtype">int</span> GetFieldType() <span class="keyword">const</span> =0;
<a name="l00076"></a>00076         <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> GetDefaultSubgroupOrderSize(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> modulusSize) <span class="keyword">const</span>;
<a name="l00077"></a>00077 
<a name="l00078"></a>00078 <span class="keyword">private</span>:
<a name="l00079"></a>00079         Integer m_q;
<a name="l00080"></a>00080 };
<a name="l00081"></a>00081 <span class="comment"></span>
<a name="l00082"></a>00082 <span class="comment">//! _</span>
<a name="l00083"></a>00083 <span class="comment"></span><span class="keyword">template</span> &lt;<span class="keyword">class</span> GROUP_PRECOMP, <span class="keyword">class</span> BASE_PRECOMP = DL_FixedBasePrecomputationImpl&lt;CPP_TYPENAME GROUP_PRECOMP::Element&gt; &gt;
<a name="l00084"></a><a class="code" href="class_d_l___group_parameters___integer_based_impl.html">00084</a> <span class="keyword">class </span>CRYPTOPP_NO_VTABLE <a class="code" href="class_d_l___group_parameters___integer_based_impl.html" title="_">DL_GroupParameters_IntegerBasedImpl</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___group_parameters_impl.html" title="_">DL_GroupParametersImpl</a>&lt;GROUP_PRECOMP, BASE_PRECOMP, DL_GroupParameters_IntegerBased&gt;
<a name="l00085"></a>00085 {
<a name="l00086"></a>00086         <span class="keyword">typedef</span> <a class="code" href="class_d_l___group_parameters___integer_based_impl.html" title="_">DL_GroupParameters_IntegerBasedImpl&lt;GROUP_PRECOMP, BASE_PRECOMP&gt;</a> <a class="code" href="class_d_l___group_parameters___integer_based.html" title="_">ThisClass</a>;
<a name="l00087"></a>00087 
<a name="l00088"></a>00088 <span class="keyword">public</span>:
<a name="l00089"></a>00089         <span class="keyword">typedef</span> <span class="keyword">typename</span> GROUP_PRECOMP::Element Element;
<a name="l00090"></a>00090 
<a name="l00091"></a>00091         <span class="comment">// GeneratibleCryptoMaterial interface</span>
<a name="l00092"></a><a class="code" href="class_d_l___group_parameters___integer_based_impl.html#aa017775352184937c5f064a4776d587e">00092</a>         <span class="keywordtype">bool</span> GetVoidValue(<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="l00093"></a>00093 <span class="keyword">                </span>{<span class="keywordflow">return</span> GetValueHelper&lt;DL_GroupParameters_IntegerBased&gt;(<span class="keyword">this</span>, name, valueType, pValue).Assignable();}
<a name="l00094"></a>00094 
<a name="l00095"></a><a class="code" href="class_d_l___group_parameters___integer_based_impl.html#a0d668d2148cf57078a93f3a5a4b4ac2a">00095</a>         <span class="keywordtype">void</span> AssignFrom(<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="l00096"></a>00096                 {AssignFromHelper&lt;DL_GroupParameters_IntegerBased&gt;(<span class="keyword">this</span>, source);}
<a name="l00097"></a>00097 
<a name="l00098"></a>00098         <span class="comment">// DL_GroupParameters</span>
<a name="l00099"></a>00099         <span class="keyword">const</span> <a class="code" href="class_d_l___fixed_base_precomputation.html">DL_FixedBasePrecomputation&lt;Element&gt;</a> &amp; GetBasePrecomputation()<span class="keyword"> const </span>{<span class="keywordflow">return</span> this-&gt;m_gpc;}
<a name="l00100"></a>00100         <a class="code" href="class_d_l___fixed_base_precomputation.html">DL_FixedBasePrecomputation&lt;Element&gt;</a> &amp; AccessBasePrecomputation() {<span class="keywordflow">return</span> this-&gt;m_gpc;}
<a name="l00101"></a>00101 
<a name="l00102"></a>00102         <span class="comment">// IntegerGroupParameters</span>
<a name="l00103"></a>00103         <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp; GetModulus()<span class="keyword"> const </span>{<span class="keywordflow">return</span> this-&gt;m_groupPrecomputation.GetModulus();}
<a name="l00104"></a>00104     <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp; GetGenerator()<span class="keyword"> const </span>{<span class="keywordflow">return</span> this-&gt;m_gpc.GetBase(this-&gt;GetGroupPrecomputation());}
<a name="l00105"></a>00105 
<a name="l00106"></a>00106         <span class="keywordtype">void</span> SetModulusAndSubgroupGenerator(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;g)         <span class="comment">// these have to be set together</span>
<a name="l00107"></a>00107                 {this-&gt;m_groupPrecomputation.SetModulus(p); this-&gt;m_gpc.SetBase(this-&gt;GetGroupPrecomputation(), g); this-&gt;ParametersChanged();}
<a name="l00108"></a>00108 
<a name="l00109"></a>00109         <span class="comment">// non-inherited</span>
<a name="l00110"></a>00110         <span class="keywordtype">bool</span> operator==(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters___integer_based_impl.html" title="_">DL_GroupParameters_IntegerBasedImpl&lt;GROUP_PRECOMP, BASE_PRECOMP&gt;</a> &amp;rhs)<span class="keyword"> const</span>
<a name="l00111"></a>00111 <span class="keyword">                </span>{<span class="keywordflow">return</span> GetModulus() == rhs.GetModulus() &amp;&amp; GetGenerator() == rhs.GetGenerator() &amp;&amp; this-&gt;GetSubgroupOrder() == rhs.GetSubgroupOrder();}
<a name="l00112"></a>00112         <span class="keywordtype">bool</span> operator!=(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters___integer_based_impl.html" title="_">DL_GroupParameters_IntegerBasedImpl&lt;GROUP_PRECOMP, BASE_PRECOMP&gt;</a> &amp;rhs)<span class="keyword"> const</span>
<a name="l00113"></a>00113 <span class="keyword">                </span>{<span class="keywordflow">return</span> !operator==(rhs);}
<a name="l00114"></a>00114 };
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 CRYPTOPP_DLL_TEMPLATE_CLASS <a class="code" href="class_d_l___group_parameters___integer_based_impl.html">DL_GroupParameters_IntegerBasedImpl&lt;ModExpPrecomputation&gt;</a>;
<a name="l00117"></a>00117 <span class="comment"></span>
<a name="l00118"></a>00118 <span class="comment">//! GF(p) group parameters</span>
<a name="l00119"></a><a class="code" href="class_d_l___group_parameters___g_f_p.html">00119</a> <span class="comment"></span><span class="keyword">class </span>CRYPTOPP_DLL <a class="code" href="class_d_l___group_parameters___g_f_p.html" title="GF(p) group parameters.">DL_GroupParameters_GFP</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___group_parameters___integer_based_impl.html" title="_">DL_GroupParameters_IntegerBasedImpl</a>&lt;ModExpPrecomputation&gt;
<a name="l00120"></a>00120 {
<a name="l00121"></a>00121 <span class="keyword">public</span>:
<a name="l00122"></a>00122         <span class="comment">// DL_GroupParameters</span>
<a name="l00123"></a>00123         <span class="keywordtype">bool</span> IsIdentity(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;element)<span class="keyword"> const </span>{<span class="keywordflow">return</span> element == <a class="code" href="class_integer.html#a8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>();}
<a name="l00124"></a>00124         <span class="keywordtype">void</span> SimultaneousExponentiate(<a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Element</a> *results, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Element</a> &amp;base, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> *exponents, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> exponentsCount) <span class="keyword">const</span>;
<a name="l00125"></a>00125 
<a name="l00126"></a>00126         <span class="comment">// NameValuePairs interface</span>
<a name="l00127"></a><a class="code" href="class_d_l___group_parameters___g_f_p.html#a02a6a339e6fb0458ef4cea824dfa965d">00127</a>         <span class="keywordtype">bool</span> <a class="code" href="class_d_l___group_parameters___integer_based_impl.html#aa017775352184937c5f064a4776d587e" title="to be implemented by derived classes, users should use one of the above functions...">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="l00128"></a>00128 <span class="keyword">        </span>{
<a name="l00129"></a>00129                 <span class="keywordflow">return</span> GetValueHelper&lt;DL_GroupParameters_IntegerBased&gt;(<span class="keyword">this</span>, name, valueType, pValue).Assignable();
<a name="l00130"></a>00130         }
<a name="l00131"></a>00131 
<a name="l00132"></a>00132         <span class="comment">// used by MQV</span>
<a name="l00133"></a>00133         Element MultiplyElements(<span class="keyword">const</span> Element &amp;a, <span class="keyword">const</span> Element &amp;b) <span class="keyword">const</span>;
<a name="l00134"></a>00134         Element CascadeExponentiate(<span class="keyword">const</span> Element &amp;element1, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;exponent1, <span class="keyword">const</span> Element &amp;element2, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;exponent2) <span class="keyword">const</span>;
<a name="l00135"></a>00135 
<a name="l00136"></a>00136 <span class="keyword">protected</span>:
<a name="l00137"></a>00137         <span class="keywordtype">int</span> GetFieldType()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 1;}
<a name="l00138"></a>00138 };
<a name="l00139"></a>00139 <span class="comment"></span>
<a name="l00140"></a>00140 <span class="comment">//! GF(p) group parameters that default to same primes</span>
<a name="l00141"></a><a class="code" href="class_d_l___group_parameters___g_f_p___default_safe_prime.html">00141</a> <span class="comment"></span><span class="keyword">class </span>CRYPTOPP_DLL <a class="code" href="class_d_l___group_parameters___g_f_p___default_safe_prime.html" title="GF(p) group parameters that default to same primes.">DL_GroupParameters_GFP_DefaultSafePrime</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___group_parameters___g_f_p.html" title="GF(p) group parameters.">DL_GroupParameters_GFP</a>
<a name="l00142"></a>00142 {
<a name="l00143"></a>00143 <span class="keyword">public</span>:
<a name="l00144"></a>00144         <span class="keyword">typedef</span> <a class="code" href="struct_enum_to_type.html">NoCofactorMultiplication</a> <a class="code" href="struct_enum_to_type.html">DefaultCofactorOption</a>;
<a name="l00145"></a>00145 
<a name="l00146"></a>00146 <span class="keyword">protected</span>:
<a name="l00147"></a>00147         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> GetDefaultSubgroupOrderSize(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> modulusSize)<span class="keyword"> const </span>{<span class="keywordflow">return</span> modulusSize-1;}
<a name="l00148"></a>00148 };
<a name="l00149"></a>00149 <span class="comment"></span>
<a name="l00150"></a>00150 <span class="comment">//! GDSA algorithm</span>
<a name="l00151"></a>00151 <span class="comment"></span><span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00152"></a><a class="code" href="class_d_l___algorithm___g_d_s_a.html">00152</a> <span class="keyword">class </span><a class="code" href="class_d_l___algorithm___g_d_s_a.html" title="GDSA algorithm.">DL_Algorithm_GDSA</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___elgamal_like_signature_algorithm.html" title="interface for Elgamal-like signature algorithms">DL_ElgamalLikeSignatureAlgorithm</a>&lt;T&gt;
<a name="l00153"></a>00153 {
<a name="l00154"></a>00154 <span class="keyword">public</span>:
<a name="l00155"></a>00155         <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * CRYPTOPP_API StaticAlgorithmName() {<span class="keywordflow">return</span> <span class="stringliteral">&quot;DSA-1363&quot;</span>;}
<a name="l00156"></a>00156 
<a name="l00157"></a>00157         <span class="keywordtype">void</span> Sign(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters.html" title="interface for DL group parameters">DL_GroupParameters&lt;T&gt;</a> &amp;params, <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 class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;k, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;e, <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;r, <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;s)<span class="keyword"> const</span>
<a name="l00158"></a>00158 <span class="keyword">        </span>{
<a name="l00159"></a>00159                 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;q = params.GetSubgroupOrder();
<a name="l00160"></a>00160                 r %= q;
<a name="l00161"></a>00161                 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> kInv = k.<a class="code" href="class_integer.html#a881f9c714ee42f35718725a43d4d7db3" title="calculate multiplicative inverse of *this mod n">InverseMod</a>(q);
<a name="l00162"></a>00162                 s = (kInv * (x*r + e)) % q;
<a name="l00163"></a>00163                 assert(!!r &amp;&amp; !!s);
<a name="l00164"></a>00164         }
<a name="l00165"></a>00165 
<a name="l00166"></a>00166         <span class="keywordtype">bool</span> Verify(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters.html" title="interface for DL group parameters">DL_GroupParameters&lt;T&gt;</a> &amp;params, <span class="keyword">const</span> <a class="code" href="class_d_l___public_key.html" title="interface for DL public keys">DL_PublicKey&lt;T&gt;</a> &amp;publicKey, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;e, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;r, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;s)<span class="keyword"> const</span>
<a name="l00167"></a>00167 <span class="keyword">        </span>{
<a name="l00168"></a>00168                 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;q = params.GetSubgroupOrder();
<a name="l00169"></a>00169                 <span class="keywordflow">if</span> (r&gt;=q || r&lt;1 || s&gt;=q || s&lt;1)
<a name="l00170"></a>00170                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00171"></a>00171 
<a name="l00172"></a>00172                 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> w = s.<a class="code" href="class_integer.html#a881f9c714ee42f35718725a43d4d7db3" title="calculate multiplicative inverse of *this mod n">InverseMod</a>(q);
<a name="l00173"></a>00173                 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> u1 = (e * w) % q;
<a name="l00174"></a>00174                 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> u2 = (r * w) % q;
<a name="l00175"></a>00175                 <span class="comment">// verify r == (g^u1 * y^u2 mod p) mod q</span>
<a name="l00176"></a>00176                 <span class="keywordflow">return</span> r == params.ConvertElementToInteger(publicKey.CascadeExponentiateBaseAndPublicElement(u1, u2)) % q;
<a name="l00177"></a>00177         }
<a name="l00178"></a>00178 };
<a name="l00179"></a>00179 
<a name="l00180"></a>00180 CRYPTOPP_DLL_TEMPLATE_CLASS <a class="code" href="class_d_l___algorithm___g_d_s_a.html" title="GDSA algorithm.">DL_Algorithm_GDSA&lt;Integer&gt;</a>;
<a name="l00181"></a>00181 <span class="comment"></span>
<a name="l00182"></a>00182 <span class="comment">//! NR algorithm</span>
<a name="l00183"></a>00183 <span class="comment"></span><span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00184"></a><a class="code" href="class_d_l___algorithm___n_r.html">00184</a> <span class="keyword">class </span><a class="code" href="class_d_l___algorithm___n_r.html" title="NR algorithm.">DL_Algorithm_NR</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___elgamal_like_signature_algorithm.html" title="interface for Elgamal-like signature algorithms">DL_ElgamalLikeSignatureAlgorithm</a>&lt;T&gt;
<a name="l00185"></a>00185 {
<a name="l00186"></a>00186 <span class="keyword">public</span>:
<a name="l00187"></a>00187         <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * CRYPTOPP_API StaticAlgorithmName() {<span class="keywordflow">return</span> <span class="stringliteral">&quot;NR&quot;</span>;}
<a name="l00188"></a>00188 
<a name="l00189"></a>00189         <span class="keywordtype">void</span> Sign(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters.html" title="interface for DL group parameters">DL_GroupParameters&lt;T&gt;</a> &amp;params, <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 class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;k, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;e, <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;r, <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;s)<span class="keyword"> const</span>
<a name="l00190"></a>00190 <span class="keyword">        </span>{
<a name="l00191"></a>00191                 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;q = params.GetSubgroupOrder();
<a name="l00192"></a>00192                 r = (r + e) % q;
<a name="l00193"></a>00193                 s = (k - x*r) % q;
<a name="l00194"></a>00194                 assert(!!r);
<a name="l00195"></a>00195         }
<a name="l00196"></a>00196 
<a name="l00197"></a>00197         <span class="keywordtype">bool</span> Verify(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters.html" title="interface for DL group parameters">DL_GroupParameters&lt;T&gt;</a> &amp;params, <span class="keyword">const</span> <a class="code" href="class_d_l___public_key.html" title="interface for DL public keys">DL_PublicKey&lt;T&gt;</a> &amp;publicKey, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;e, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;r, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;s)<span class="keyword"> const</span>
<a name="l00198"></a>00198 <span class="keyword">        </span>{
<a name="l00199"></a>00199                 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;q = params.GetSubgroupOrder();
<a name="l00200"></a>00200                 <span class="keywordflow">if</span> (r&gt;=q || r&lt;1 || s&gt;=q)
<a name="l00201"></a>00201                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00202"></a>00202 
<a name="l00203"></a>00203                 <span class="comment">// check r == (m_g^s * m_y^r + m) mod m_q</span>
<a name="l00204"></a>00204                 <span class="keywordflow">return</span> r == (params.ConvertElementToInteger(publicKey.CascadeExponentiateBaseAndPublicElement(s, r)) + e) % q;
<a name="l00205"></a>00205         }
<a name="l00206"></a>00206 };
<a name="l00207"></a>00207 <span class="comment"></span>
<a name="l00208"></a>00208 <span class="comment">/*! DSA public key format is defined in 7.3.3 of RFC 2459. The</span>
<a name="l00209"></a>00209 <span class="comment">        private key format is defined in 12.9 of PKCS #11 v2.10. */</span>
<a name="l00210"></a>00210 <span class="keyword">template</span> &lt;<span class="keyword">class</span> GP&gt;
<a name="l00211"></a><a class="code" href="class_d_l___public_key___g_f_p.html">00211</a> <span class="keyword">class </span><a class="code" href="class_d_l___public_key___g_f_p.html">DL_PublicKey_GFP</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___public_key_impl.html" title="_">DL_PublicKeyImpl</a>&lt;GP&gt;
<a name="l00212"></a>00212 {
<a name="l00213"></a>00213 <span class="keyword">public</span>:
<a name="l00214"></a>00214         <span class="keywordtype">void</span> Initialize(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters___integer_based.html" title="_">DL_GroupParameters_IntegerBased</a> &amp;params, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;y)
<a name="l00215"></a>00215                 {this-&gt;AccessGroupParameters().Initialize(params); this-&gt;SetPublicElement(y);}
<a name="l00216"></a>00216         <span class="keywordtype">void</span> Initialize(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;g, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;y)
<a name="l00217"></a>00217                 {this-&gt;AccessGroupParameters().Initialize(p, g); this-&gt;SetPublicElement(y);}
<a name="l00218"></a>00218         <span class="keywordtype">void</span> Initialize(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;q, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;g, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;y)
<a name="l00219"></a>00219                 {this-&gt;AccessGroupParameters().Initialize(p, q, g); this-&gt;SetPublicElement(y);}
<a name="l00220"></a>00220 
<a name="l00221"></a>00221         <span class="comment">// X509PublicKey</span>
<a name="l00222"></a><a class="code" href="class_d_l___public_key___g_f_p.html#a9776ea4e0c4629e9e699145e0cf20d36">00222</a>         <span class="keywordtype">void</span> <a class="code" href="class_d_l___public_key___g_f_p.html#a9776ea4e0c4629e9e699145e0cf20d36" title="decode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header...">BERDecodePublicKey</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;bt, <span class="keywordtype">bool</span>, <span class="keywordtype">size_t</span>)
<a name="l00223"></a>00223                 {this-&gt;SetPublicElement(<a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a>(bt));}
<a name="l00224"></a><a class="code" href="class_d_l___public_key___g_f_p.html#a132a1c79c696cb4589e08e5f448df6d0">00224</a>         <span class="keywordtype">void</span> <a class="code" href="class_d_l___public_key___g_f_p.html#a132a1c79c696cb4589e08e5f448df6d0" title="encode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header...">DEREncodePublicKey</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="l00225"></a>00225 <span class="keyword">                </span>{this-&gt;GetPublicElement().DEREncode(bt);}
<a name="l00226"></a>00226 };
<a name="l00227"></a>00227 <span class="comment"></span>
<a name="l00228"></a>00228 <span class="comment">//! DL private key (in GF(p) groups)</span>
<a name="l00229"></a>00229 <span class="comment"></span><span class="keyword">template</span> &lt;<span class="keyword">class</span> GP&gt;
<a name="l00230"></a><a class="code" href="class_d_l___private_key___g_f_p.html">00230</a> <span class="keyword">class </span><a class="code" href="class_d_l___private_key___g_f_p.html" title="DL private key (in GF(p) groups).">DL_PrivateKey_GFP</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___private_key_impl.html" title="_">DL_PrivateKeyImpl</a>&lt;GP&gt;
<a name="l00231"></a>00231 {
<a name="l00232"></a>00232 <span class="keyword">public</span>:
<a name="l00233"></a>00233         <span class="keywordtype">void</span> Initialize(<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> modulusBits)
<a name="l00234"></a>00234                 {this-&gt;<a class="code" href="class_generatable_crypto_material.html#a38d492343c32e530a5c2781b5797f755" title="calls the above function with a NameValuePairs object that just specifies &amp;quot;KeySize&amp;quot;...">GenerateRandomWithKeySize</a>(rng, modulusBits);}
<a name="l00235"></a>00235         <span class="keywordtype">void</span> Initialize(<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;p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;g)
<a name="l00236"></a>00236                 {this-&gt;<a class="code" href="class_d_l___private_key_impl.html#ab80a3771a5ef623677775f7c5dddb1e0" title="generate a random key or crypto parameters">GenerateRandom</a>(rng, MakeParameters(<span class="stringliteral">&quot;Modulus&quot;</span>, p)(<span class="stringliteral">&quot;SubgroupGenerator&quot;</span>, g));}
<a name="l00237"></a>00237         <span class="keywordtype">void</span> Initialize(<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;p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;q, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;g)
<a name="l00238"></a>00238                 {this-&gt;<a class="code" href="class_d_l___private_key_impl.html#ab80a3771a5ef623677775f7c5dddb1e0" title="generate a random key or crypto parameters">GenerateRandom</a>(rng, MakeParameters(<span class="stringliteral">&quot;Modulus&quot;</span>, p)(<span class="stringliteral">&quot;SubgroupOrder&quot;</span>, q)(<span class="stringliteral">&quot;SubgroupGenerator&quot;</span>, g));}
<a name="l00239"></a>00239         <span class="keywordtype">void</span> Initialize(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters___integer_based.html" title="_">DL_GroupParameters_IntegerBased</a> &amp;params, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;x)
<a name="l00240"></a>00240                 {this-&gt;AccessGroupParameters().Initialize(params); this-&gt;SetPrivateExponent(x);}
<a name="l00241"></a>00241         <span class="keywordtype">void</span> Initialize(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;g, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;x)
<a name="l00242"></a>00242                 {this-&gt;AccessGroupParameters().Initialize(p, g); this-&gt;SetPrivateExponent(x);}
<a name="l00243"></a>00243         <span class="keywordtype">void</span> Initialize(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;q, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;g, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;x)
<a name="l00244"></a>00244                 {this-&gt;AccessGroupParameters().Initialize(p, q, g); this-&gt;SetPrivateExponent(x);}
<a name="l00245"></a>00245 };
<a name="l00246"></a>00246 <span class="comment"></span>
<a name="l00247"></a>00247 <span class="comment">//! DL signing/verification keys (in GF(p) groups)</span>
<a name="l00248"></a><a class="code" href="struct_d_l___signature_keys___g_f_p.html">00248</a> <span class="comment"></span><span class="keyword">struct </span><a class="code" href="struct_d_l___signature_keys___g_f_p.html" title="DL signing/verification keys (in GF(p) groups).">DL_SignatureKeys_GFP</a>
<a name="l00249"></a>00249 {
<a name="l00250"></a>00250         <span class="keyword">typedef</span> <a class="code" href="class_d_l___group_parameters___g_f_p.html" title="GF(p) group parameters.">DL_GroupParameters_GFP</a> <a class="code" href="class_d_l___group_parameters___g_f_p.html" title="GF(p) group parameters.">GroupParameters</a>;
<a name="l00251"></a>00251         <span class="keyword">typedef</span> <a class="code" href="class_d_l___public_key___g_f_p.html">DL_PublicKey_GFP&lt;GroupParameters&gt;</a> <a class="code" href="class_d_l___public_key___g_f_p.html">PublicKey</a>;
<a name="l00252"></a>00252         <span class="keyword">typedef</span> <a class="code" href="class_d_l___private_key___g_f_p.html" title="DL private key (in GF(p) groups).">DL_PrivateKey_GFP&lt;GroupParameters&gt;</a> <a class="code" href="class_d_l___private_key___g_f_p.html" title="DL private key (in GF(p) groups).">PrivateKey</a>;
<a name="l00253"></a>00253 };
<a name="l00254"></a>00254 <span class="comment"></span>
<a name="l00255"></a>00255 <span class="comment">//! DL encryption/decryption keys (in GF(p) groups)</span>
<a name="l00256"></a><a class="code" href="struct_d_l___crypto_keys___g_f_p.html">00256</a> <span class="comment"></span><span class="keyword">struct </span><a class="code" href="struct_d_l___crypto_keys___g_f_p.html" title="DL encryption/decryption keys (in GF(p) groups).">DL_CryptoKeys_GFP</a>
<a name="l00257"></a>00257 {
<a name="l00258"></a>00258         <span class="keyword">typedef</span> <a class="code" href="class_d_l___group_parameters___g_f_p___default_safe_prime.html" title="GF(p) group parameters that default to same primes.">DL_GroupParameters_GFP_DefaultSafePrime</a> <a class="code" href="class_d_l___group_parameters___g_f_p___default_safe_prime.html" title="GF(p) group parameters that default to same primes.">GroupParameters</a>;
<a name="l00259"></a>00259         <span class="keyword">typedef</span> <a class="code" href="class_d_l___public_key___g_f_p.html">DL_PublicKey_GFP&lt;GroupParameters&gt;</a> <a class="code" href="class_d_l___public_key___g_f_p.html">PublicKey</a>;
<a name="l00260"></a>00260         <span class="keyword">typedef</span> <a class="code" href="class_d_l___private_key___g_f_p.html" title="DL private key (in GF(p) groups).">DL_PrivateKey_GFP&lt;GroupParameters&gt;</a> <a class="code" href="class_d_l___private_key___g_f_p.html" title="DL private key (in GF(p) groups).">PrivateKey</a>;
<a name="l00261"></a>00261 };
<a name="l00262"></a>00262 <span class="comment"></span>
<a name="l00263"></a>00263 <span class="comment">//! provided for backwards compatibility, this class uses the old non-standard Crypto++ key format</span>
<a name="l00264"></a>00264 <span class="comment"></span><span class="keyword">template</span> &lt;<span class="keyword">class</span> BASE&gt;
<a name="l00265"></a><a class="code" href="class_d_l___public_key___g_f_p___old_format.html">00265</a> <span class="keyword">class </span><a class="code" href="class_d_l___public_key___g_f_p___old_format.html" title="provided for backwards compatibility, this class uses the old non-standard Crypto++...">DL_PublicKey_GFP_OldFormat</a> : <span class="keyword">public</span> <a class="code" href="class_b_a_s_e.html">BASE</a>
<a name="l00266"></a>00266 {
<a name="l00267"></a>00267 <span class="keyword">public</span>:
<a name="l00268"></a>00268         <span class="keywordtype">void</span> BERDecode(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;bt)
<a name="l00269"></a>00269         {
<a name="l00270"></a>00270                 <a class="code" href="class_b_e_r_sequence_decoder.html" title="BER Sequence Decoder.">BERSequenceDecoder</a> seq(bt);
<a name="l00271"></a>00271                         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> v1(seq);
<a name="l00272"></a>00272                         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> v2(seq);
<a name="l00273"></a>00273                         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> v3(seq);
<a name="l00274"></a>00274 
<a name="l00275"></a>00275                         <span class="keywordflow">if</span> (seq.EndReached())
<a name="l00276"></a>00276                         {
<a name="l00277"></a>00277                                 this-&gt;AccessGroupParameters().Initialize(v1, v1/2, v2);
<a name="l00278"></a>00278                                 this-&gt;SetPublicElement(v3);
<a name="l00279"></a>00279                         }
<a name="l00280"></a>00280                         <span class="keywordflow">else</span>
<a name="l00281"></a>00281                         {
<a name="l00282"></a>00282                                 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> v4(seq);
<a name="l00283"></a>00283                                 this-&gt;AccessGroupParameters().Initialize(v1, v2, v3);
<a name="l00284"></a>00284                                 this-&gt;SetPublicElement(v4);
<a name="l00285"></a>00285                         }
<a name="l00286"></a>00286 
<a name="l00287"></a>00287                 seq.MessageEnd();
<a name="l00288"></a>00288         }
<a name="l00289"></a>00289 
<a name="l00290"></a>00290         <span class="keywordtype">void</span> DEREncode(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;bt)<span class="keyword"> const</span>
<a name="l00291"></a>00291 <span class="keyword">        </span>{
<a name="l00292"></a>00292                 <a class="code" href="class_d_e_r_sequence_encoder.html" title="DER Sequence Encoder.">DERSequenceEncoder</a> seq(bt);
<a name="l00293"></a>00293                         this-&gt;GetGroupParameters().GetModulus().DEREncode(seq);
<a name="l00294"></a>00294                         <span class="keywordflow">if</span> (this-&gt;GetGroupParameters().GetCofactor() != 2)
<a name="l00295"></a>00295                                 this-&gt;GetGroupParameters().GetSubgroupOrder().DEREncode(seq);
<a name="l00296"></a>00296                         this-&gt;GetGroupParameters().GetGenerator().DEREncode(seq);
<a name="l00297"></a>00297                         this-&gt;GetPublicElement().DEREncode(seq);
<a name="l00298"></a>00298                 seq.MessageEnd();
<a name="l00299"></a>00299         }
<a name="l00300"></a>00300 };
<a name="l00301"></a>00301 <span class="comment"></span>
<a name="l00302"></a>00302 <span class="comment">//! provided for backwards compatibility, this class uses the old non-standard Crypto++ key format</span>
<a name="l00303"></a>00303 <span class="comment"></span><span class="keyword">template</span> &lt;<span class="keyword">class</span> BASE&gt;
<a name="l00304"></a><a class="code" href="class_d_l___private_key___g_f_p___old_format.html">00304</a> <span class="keyword">class </span><a class="code" href="class_d_l___private_key___g_f_p___old_format.html" title="provided for backwards compatibility, this class uses the old non-standard Crypto++...">DL_PrivateKey_GFP_OldFormat</a> : <span class="keyword">public</span> <a class="code" href="class_b_a_s_e.html">BASE</a>
<a name="l00305"></a>00305 {
<a name="l00306"></a>00306 <span class="keyword">public</span>:
<a name="l00307"></a>00307         <span class="keywordtype">void</span> BERDecode(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;bt)
<a name="l00308"></a>00308         {
<a name="l00309"></a>00309                 <a class="code" href="class_b_e_r_sequence_decoder.html" title="BER Sequence Decoder.">BERSequenceDecoder</a> seq(bt);
<a name="l00310"></a>00310                         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> v1(seq);
<a name="l00311"></a>00311                         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> v2(seq);
<a name="l00312"></a>00312                         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> v3(seq);
<a name="l00313"></a>00313                         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> v4(seq);
<a name="l00314"></a>00314 
<a name="l00315"></a>00315                         <span class="keywordflow">if</span> (seq.EndReached())
<a name="l00316"></a>00316                         {
<a name="l00317"></a>00317                                 this-&gt;AccessGroupParameters().Initialize(v1, v1/2, v2);
<a name="l00318"></a>00318                                 this-&gt;SetPrivateExponent(v4 % (v1/2));  <span class="comment">// some old keys may have x &gt;= q</span>
<a name="l00319"></a>00319                         }
<a name="l00320"></a>00320                         <span class="keywordflow">else</span>
<a name="l00321"></a>00321                         {
<a name="l00322"></a>00322                                 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> v5(seq);
<a name="l00323"></a>00323                                 this-&gt;AccessGroupParameters().Initialize(v1, v2, v3);
<a name="l00324"></a>00324                                 this-&gt;SetPrivateExponent(v5);
<a name="l00325"></a>00325                         }
<a name="l00326"></a>00326 
<a name="l00327"></a>00327                 seq.MessageEnd();
<a name="l00328"></a>00328         }
<a name="l00329"></a>00329 
<a name="l00330"></a>00330         <span class="keywordtype">void</span> DEREncode(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;bt)<span class="keyword"> const</span>
<a name="l00331"></a>00331 <span class="keyword">        </span>{
<a name="l00332"></a>00332                 <a class="code" href="class_d_e_r_sequence_encoder.html" title="DER Sequence Encoder.">DERSequenceEncoder</a> seq(bt);
<a name="l00333"></a>00333                         this-&gt;GetGroupParameters().GetModulus().DEREncode(seq);
<a name="l00334"></a>00334                         <span class="keywordflow">if</span> (this-&gt;GetGroupParameters().GetCofactor() != 2)
<a name="l00335"></a>00335                                 this-&gt;GetGroupParameters().GetSubgroupOrder().DEREncode(seq);
<a name="l00336"></a>00336                         this-&gt;GetGroupParameters().GetGenerator().DEREncode(seq);
<a name="l00337"></a>00337                         this-&gt;GetGroupParameters().ExponentiateBase(this-&gt;GetPrivateExponent()).DEREncode(seq);
<a name="l00338"></a>00338                         this-&gt;GetPrivateExponent().DEREncode(seq);
<a name="l00339"></a>00339                 seq.MessageEnd();
<a name="l00340"></a>00340         }
<a name="l00341"></a>00341 };
<a name="l00342"></a>00342 <span class="comment"></span>
<a name="l00343"></a>00343 <span class="comment">//! &lt;a href=&quot;http://www.weidai.com/scan-mirror/sig.html#DSA-1363&quot;&gt;DSA-1363&lt;/a&gt;</span>
<a name="l00344"></a>00344 <span class="comment"></span><span class="keyword">template</span> &lt;<span class="keyword">class</span> H&gt;
<a name="l00345"></a><a class="code" href="struct_g_d_s_a.html">00345</a> <span class="keyword">struct </span><a class="code" href="struct_g_d_s_a.html" title="DSA-1363">GDSA</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___s_s.html" title="Discrete Log Based Signature Scheme.">DL_SS</a>&lt;
<a name="l00346"></a>00346         DL_SignatureKeys_GFP, 
<a name="l00347"></a>00347         DL_Algorithm_GDSA&lt;Integer&gt;, 
<a name="l00348"></a>00348         DL_SignatureMessageEncodingMethod_DSA,
<a name="l00349"></a>00349         H&gt;
<a name="l00350"></a>00350 {
<a name="l00351"></a>00351 };
<a name="l00352"></a>00352 <span class="comment"></span>
<a name="l00353"></a>00353 <span class="comment">//! &lt;a href=&quot;http://www.weidai.com/scan-mirror/sig.html#NR&quot;&gt;NR&lt;/a&gt;</span>
<a name="l00354"></a>00354 <span class="comment"></span><span class="keyword">template</span> &lt;<span class="keyword">class</span> H&gt;
<a name="l00355"></a><a class="code" href="struct_n_r.html">00355</a> <span class="keyword">struct </span><a class="code" href="struct_n_r.html" title="NR">NR</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___s_s.html" title="Discrete Log Based Signature Scheme.">DL_SS</a>&lt;
<a name="l00356"></a>00356         DL_SignatureKeys_GFP, 
<a name="l00357"></a>00357         DL_Algorithm_NR&lt;Integer&gt;, 
<a name="l00358"></a>00358         DL_SignatureMessageEncodingMethod_NR,
<a name="l00359"></a>00359         H&gt;
<a name="l00360"></a>00360 {
<a name="l00361"></a>00361 };
<a name="l00362"></a>00362 <span class="comment"></span>
<a name="l00363"></a>00363 <span class="comment">//! DSA group parameters, these are GF(p) group parameters that are allowed by the DSA standard</span>
<a name="l00364"></a><a class="code" href="class_d_l___group_parameters___d_s_a.html">00364</a> <span class="comment"></span><span class="keyword">class </span>CRYPTOPP_DLL <a class="code" href="class_d_l___group_parameters___d_s_a.html" title="DSA group parameters, these are GF(p) group parameters that are allowed by the DSA...">DL_GroupParameters_DSA</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___group_parameters___g_f_p.html" title="GF(p) group parameters.">DL_GroupParameters_GFP</a>
<a name="l00365"></a>00365 {
<a name="l00366"></a>00366 <span class="keyword">public</span>:<span class="comment"></span>
<a name="l00367"></a>00367 <span class="comment">        /*! also checks that the lengths of p and q are allowed by the DSA standard */</span>
<a name="l00368"></a>00368         <span class="keywordtype">bool</span> ValidateGroup(<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>;<span class="comment"></span>
<a name="l00369"></a>00369 <span class="comment">        /*! parameters: (ModulusSize), or (Modulus, SubgroupOrder, SubgroupGenerator) */</span><span class="comment"></span>
<a name="l00370"></a>00370 <span class="comment">        /*! ModulusSize must be between DSA::MIN_PRIME_LENGTH and DSA::MAX_PRIME_LENGTH, and divisible by DSA::PRIME_LENGTH_MULTIPLE */</span>
<a name="l00371"></a>00371         <span class="keywordtype">void</span> <a class="code" href="class_d_l___group_parameters___integer_based.html#a8c9a79c493a215ca37408bb7ddfb5533">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="l00372"></a>00372 };
<a name="l00373"></a>00373 
<a name="l00374"></a>00374 <span class="keyword">struct </span><a class="code" href="struct_d_s_a.html" title="DSA">DSA</a>;
<a name="l00375"></a>00375 <span class="comment"></span>
<a name="l00376"></a>00376 <span class="comment">//! DSA keys</span>
<a name="l00377"></a><a class="code" href="struct_d_l___keys___d_s_a.html">00377</a> <span class="comment"></span><span class="keyword">struct </span><a class="code" href="struct_d_l___keys___d_s_a.html" title="DSA keys.">DL_Keys_DSA</a>
<a name="l00378"></a>00378 {
<a name="l00379"></a>00379         <span class="keyword">typedef</span> <a class="code" href="class_d_l___public_key___g_f_p.html">DL_PublicKey_GFP&lt;DL_GroupParameters_DSA&gt;</a> <a class="code" href="class_d_l___public_key___g_f_p.html">PublicKey</a>;
<a name="l00380"></a>00380         <span class="keyword">typedef</span> <a class="code" href="class_d_l___private_key___with_signature_pairwise_consistency_test.html" title="_">DL_PrivateKey_WithSignaturePairwiseConsistencyTest&lt;DL_PrivateKey_GFP&lt;DL_GroupParameters_DSA&gt;</a>, <a class="code" href="struct_d_s_a.html" title="DSA">DSA</a>&gt; <a class="code" href="class_d_l___private_key___with_signature_pairwise_consistency_test.html" title="_">PrivateKey</a>;
<a name="l00381"></a>00381 };
<a name="l00382"></a>00382 <span class="comment"></span>
<a name="l00383"></a>00383 <span class="comment">//! &lt;a href=&quot;http://www.weidai.com/scan-mirror/sig.html#DSA&quot;&gt;DSA&lt;/a&gt;</span>
<a name="l00384"></a><a class="code" href="struct_d_s_a.html">00384</a> <span class="comment"></span><span class="keyword">struct </span>CRYPTOPP_DLL <a class="code" href="struct_d_s_a.html" title="DSA">DSA</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___s_s.html" title="Discrete Log Based Signature Scheme.">DL_SS</a>&lt;
<a name="l00385"></a>00385         DL_Keys_DSA, 
<a name="l00386"></a>00386         DL_Algorithm_GDSA&lt;Integer&gt;, 
<a name="l00387"></a>00387         DL_SignatureMessageEncodingMethod_DSA,
<a name="l00388"></a>00388         SHA, 
<a name="l00389"></a>00389         DSA&gt;
<a name="l00390"></a>00390 {
<a name="l00391"></a>00391         <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * CRYPTOPP_API StaticAlgorithmName() {<span class="keywordflow">return</span> <span class="stringliteral">&quot;DSA&quot;</span>;}
<a name="l00392"></a>00392 <span class="comment"></span>
<a name="l00393"></a>00393 <span class="comment">        //! Generate DSA primes according to NIST standard</span>
<a name="l00394"></a>00394 <span class="comment"></span><span class="comment">        /*! Both seedLength and primeLength are in bits, but seedLength should</span>
<a name="l00395"></a>00395 <span class="comment">                be a multiple of 8.</span>
<a name="l00396"></a>00396 <span class="comment">                If useInputCounterValue == true, the counter parameter is taken as input, otherwise it&apos;s used for output</span>
<a name="l00397"></a>00397 <span class="comment">        */</span>
<a name="l00398"></a>00398         <span class="keyword">static</span> <span class="keywordtype">bool</span> CRYPTOPP_API GeneratePrimes(<span class="keyword">const</span> byte *seed, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> seedLength, <span class="keywordtype">int</span> &amp;counter,
<a name="l00399"></a>00399                                                                 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;p, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> primeLength, <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &amp;q, <span class="keywordtype">bool</span> useInputCounterValue = <span class="keyword">false</span>);
<a name="l00400"></a>00400 
<a name="l00401"></a>00401         <span class="keyword">static</span> <span class="keywordtype">bool</span> CRYPTOPP_API IsValidPrimeLength(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pbits)
<a name="l00402"></a>00402                 {<span class="keywordflow">return</span> pbits &gt;= MIN_PRIME_LENGTH &amp;&amp; pbits &lt;= MAX_PRIME_LENGTH &amp;&amp; pbits % PRIME_LENGTH_MULTIPLE == 0;}
<a name="l00403"></a>00403 <span class="comment"></span>
<a name="l00404"></a>00404 <span class="comment">        //! FIPS 186-2 Change Notice 1 changed the minimum modulus length to 1024</span>
<a name="l00405"></a>00405 <span class="comment"></span>        <span class="keyword">enum</span> {
<a name="l00406"></a>00406 <span class="preprocessor">#if (DSA_1024_BIT_MODULUS_ONLY)</span>
<a name="l00407"></a>00407 <span class="preprocessor"></span>                MIN_PRIME_LENGTH = 1024,
<a name="l00408"></a>00408 <span class="preprocessor">#else</span>
<a name="l00409"></a>00409 <span class="preprocessor"></span>                MIN_PRIME_LENGTH = 512,
<a name="l00410"></a>00410 <span class="preprocessor">#endif</span>
<a name="l00411"></a>00411 <span class="preprocessor"></span>                MAX_PRIME_LENGTH = 1024, PRIME_LENGTH_MULTIPLE = 64};
<a name="l00412"></a>00412 };
<a name="l00413"></a>00413 
<a name="l00414"></a>00414 CRYPTOPP_DLL_TEMPLATE_CLASS <a class="code" href="class_d_l___public_key___g_f_p.html">DL_PublicKey_GFP&lt;DL_GroupParameters_DSA&gt;</a>;
<a name="l00415"></a>00415 CRYPTOPP_DLL_TEMPLATE_CLASS <a class="code" href="class_d_l___private_key___g_f_p.html" title="DL private key (in GF(p) groups).">DL_PrivateKey_GFP&lt;DL_GroupParameters_DSA&gt;</a>;
<a name="l00416"></a>00416 CRYPTOPP_DLL_TEMPLATE_CLASS <a class="code" href="class_d_l___private_key___with_signature_pairwise_consistency_test.html" title="_">DL_PrivateKey_WithSignaturePairwiseConsistencyTest&lt;DL_PrivateKey_GFP&lt;DL_GroupParameters_DSA&gt;</a>, <a class="code" href="struct_d_s_a.html" title="DSA">DSA</a>&gt;;
<a name="l00417"></a>00417 <span class="comment"></span>
<a name="l00418"></a>00418 <span class="comment">//! the XOR encryption method, for use with DL-based cryptosystems</span>
<a name="l00419"></a>00419 <span class="comment"></span><span class="keyword">template</span> &lt;<span class="keyword">class</span> MAC, <span class="keywordtype">bool</span> DHAES_MODE&gt;
<a name="l00420"></a><a class="code" href="class_d_l___encryption_algorithm___xor.html">00420</a> <span class="keyword">class </span><a class="code" href="class_d_l___encryption_algorithm___xor.html" title="the XOR encryption method, for use with DL-based cryptosystems">DL_EncryptionAlgorithm_Xor</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___symmetric_encryption_algorithm.html" title="interface for symmetric encryption algorithms used in DL cryptosystems">DL_SymmetricEncryptionAlgorithm</a>
<a name="l00421"></a>00421 {
<a name="l00422"></a>00422 <span class="keyword">public</span>:
<a name="l00423"></a>00423         <span class="keywordtype">bool</span> ParameterSupported(<span class="keyword">const</span> <span class="keywordtype">char</span> *name)<span class="keyword"> const </span>{<span class="keywordflow">return</span> strcmp(name, Name::EncodingParameters()) == 0;}
<a name="l00424"></a>00424         <span class="keywordtype">size_t</span> GetSymmetricKeyLength(<span class="keywordtype">size_t</span> plaintextLength)<span class="keyword"> const</span>
<a name="l00425"></a>00425 <span class="keyword">                </span>{<span class="keywordflow">return</span> plaintextLength + MAC::DEFAULT_KEYLENGTH;}
<a name="l00426"></a>00426         <span class="keywordtype">size_t</span> GetSymmetricCiphertextLength(<span class="keywordtype">size_t</span> plaintextLength)<span class="keyword"> const</span>
<a name="l00427"></a>00427 <span class="keyword">                </span>{<span class="keywordflow">return</span> plaintextLength + MAC::DIGESTSIZE;}
<a name="l00428"></a>00428         <span class="keywordtype">size_t</span> GetMaxSymmetricPlaintextLength(<span class="keywordtype">size_t</span> ciphertextLength)<span class="keyword"> const</span>
<a name="l00429"></a>00429 <span class="keyword">                </span>{<span class="keywordflow">return</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)SaturatingSubtract(ciphertextLength, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)MAC::DIGESTSIZE);}
<a name="l00430"></a>00430         <span class="keywordtype">void</span> SymmetricEncrypt(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &amp;rng, <span class="keyword">const</span> byte *key, <span class="keyword">const</span> byte *plaintext, <span class="keywordtype">size_t</span> plaintextLength, byte *ciphertext, <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;parameters)<span class="keyword"> const</span>
<a name="l00431"></a>00431 <span class="keyword">        </span>{
<a name="l00432"></a>00432                 <span class="keyword">const</span> byte *cipherKey, *macKey;
<a name="l00433"></a>00433                 <span class="keywordflow">if</span> (DHAES_MODE)
<a name="l00434"></a>00434                 {
<a name="l00435"></a>00435                         macKey = key;
<a name="l00436"></a>00436                         cipherKey = key + MAC::DEFAULT_KEYLENGTH;
<a name="l00437"></a>00437                 }
<a name="l00438"></a>00438                 <span class="keywordflow">else</span>
<a name="l00439"></a>00439                 {
<a name="l00440"></a>00440                         cipherKey = key;
<a name="l00441"></a>00441                         macKey = key + plaintextLength;
<a name="l00442"></a>00442                 }
<a name="l00443"></a>00443 
<a name="l00444"></a>00444                 <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> encodingParameters;
<a name="l00445"></a>00445                 parameters.<a class="code" href="class_name_value_pairs.html#a96686e9f8d6ce3ab870e516fb72b608e" title="get a named value, returns true if the name exists">GetValue</a>(Name::EncodingParameters(), encodingParameters);
<a name="l00446"></a>00446 
<a name="l00447"></a>00447                 xorbuf(ciphertext, plaintext, cipherKey, plaintextLength);
<a name="l00448"></a>00448                 MAC mac(macKey);
<a name="l00449"></a>00449                 mac.Update(ciphertext, plaintextLength);
<a name="l00450"></a>00450                 mac.Update(encodingParameters.begin(), encodingParameters.size());
<a name="l00451"></a>00451                 <span class="keywordflow">if</span> (DHAES_MODE)
<a name="l00452"></a>00452                 {
<a name="l00453"></a>00453                         byte L[8] = {0,0,0,0};
<a name="l00454"></a>00454                         PutWord(<span class="keyword">false</span>, BIG_ENDIAN_ORDER, L+4, word32(encodingParameters.size()));
<a name="l00455"></a>00455                         mac.Update(L, 8);
<a name="l00456"></a>00456                 }
<a name="l00457"></a>00457                 mac.Final(ciphertext + plaintextLength);
<a name="l00458"></a>00458         }
<a name="l00459"></a>00459         <a class="code" href="struct_decoding_result.html" title="used to return decoding results">DecodingResult</a> SymmetricDecrypt(<span class="keyword">const</span> byte *key, <span class="keyword">const</span> byte *ciphertext, <span class="keywordtype">size_t</span> ciphertextLength, byte *plaintext, <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;parameters)<span class="keyword"> const</span>
<a name="l00460"></a>00460 <span class="keyword">        </span>{
<a name="l00461"></a>00461                 <span class="keywordtype">size_t</span> plaintextLength = GetMaxSymmetricPlaintextLength(ciphertextLength);
<a name="l00462"></a>00462                 <span class="keyword">const</span> byte *cipherKey, *macKey;
<a name="l00463"></a>00463                 <span class="keywordflow">if</span> (DHAES_MODE)
<a name="l00464"></a>00464                 {
<a name="l00465"></a>00465                         macKey = key;
<a name="l00466"></a>00466                         cipherKey = key + MAC::DEFAULT_KEYLENGTH;
<a name="l00467"></a>00467                 }
<a name="l00468"></a>00468                 <span class="keywordflow">else</span>
<a name="l00469"></a>00469                 {
<a name="l00470"></a>00470                         cipherKey = key;
<a name="l00471"></a>00471                         macKey = key + plaintextLength;
<a name="l00472"></a>00472                 }
<a name="l00473"></a>00473 
<a name="l00474"></a>00474                 <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> encodingParameters;
<a name="l00475"></a>00475                 parameters.<a class="code" href="class_name_value_pairs.html#a96686e9f8d6ce3ab870e516fb72b608e" title="get a named value, returns true if the name exists">GetValue</a>(Name::EncodingParameters(), encodingParameters);
<a name="l00476"></a>00476 
<a name="l00477"></a>00477                 MAC mac(macKey);
<a name="l00478"></a>00478                 mac.Update(ciphertext, plaintextLength);
<a name="l00479"></a>00479                 mac.Update(encodingParameters.begin(), encodingParameters.size());
<a name="l00480"></a>00480                 <span class="keywordflow">if</span> (DHAES_MODE)
<a name="l00481"></a>00481                 {
<a name="l00482"></a>00482                         byte L[8] = {0,0,0,0};
<a name="l00483"></a>00483                         PutWord(<span class="keyword">false</span>, BIG_ENDIAN_ORDER, L+4, word32(encodingParameters.size()));
<a name="l00484"></a>00484                         mac.Update(L, 8);
<a name="l00485"></a>00485                 }
<a name="l00486"></a>00486                 <span class="keywordflow">if</span> (!mac.Verify(ciphertext + plaintextLength))
<a name="l00487"></a>00487                         <span class="keywordflow">return</span> <a class="code" href="struct_decoding_result.html" title="used to return decoding results">DecodingResult</a>();
<a name="l00488"></a>00488 
<a name="l00489"></a>00489                 xorbuf(plaintext, ciphertext, cipherKey, plaintextLength);
<a name="l00490"></a>00490                 <span class="keywordflow">return</span> <a class="code" href="struct_decoding_result.html" title="used to return decoding results">DecodingResult</a>(plaintextLength);
<a name="l00491"></a>00491         }
<a name="l00492"></a>00492 };
<a name="l00493"></a>00493 <span class="comment"></span>
<a name="l00494"></a>00494 <span class="comment">//! _</span>
<a name="l00495"></a>00495 <span class="comment"></span><span class="keyword">template</span> &lt;<span class="keyword">class</span> T, <span class="keywordtype">bool</span> DHAES_MODE, <span class="keyword">class</span> KDF&gt;
<a name="l00496"></a><a class="code" href="class_d_l___key_derivation_algorithm___p1363.html">00496</a> <span class="keyword">class </span><a class="code" href="class_d_l___key_derivation_algorithm___p1363.html" title="_">DL_KeyDerivationAlgorithm_P1363</a> : <span class="keyword">public</span> <a class="code" href="class_d_l___key_derivation_algorithm.html" title="interface for key derivation algorithms used in DL cryptosystems">DL_KeyDerivationAlgorithm</a>&lt;T&gt;
<a name="l00497"></a>00497 {
<a name="l00498"></a>00498 <span class="keyword">public</span>:
<a name="l00499"></a>00499         <span class="keywordtype">bool</span> ParameterSupported(<span class="keyword">const</span> <span class="keywordtype">char</span> *name)<span class="keyword"> const </span>{<span class="keywordflow">return</span> strcmp(name, Name::KeyDerivationParameters()) == 0;}
<a name="l00500"></a>00500         <span class="keywordtype">void</span> Derive(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters.html" title="interface for DL group parameters">DL_GroupParameters&lt;T&gt;</a> &amp;params, byte *derivedKey, <span class="keywordtype">size_t</span> derivedLength, <span class="keyword">const</span> T &amp;agreedElement, <span class="keyword">const</span> T &amp;ephemeralPublicKey, <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;parameters)<span class="keyword"> const</span>
<a name="l00501"></a>00501 <span class="keyword">        </span>{
<a name="l00502"></a>00502                 <a class="code" href="class_sec_block.html">SecByteBlock</a> agreedSecret;
<a name="l00503"></a>00503                 <span class="keywordflow">if</span> (DHAES_MODE)
<a name="l00504"></a>00504                 {
<a name="l00505"></a>00505                         agreedSecret.<a class="code" href="class_sec_block.html#a90d46e577c951d81a2d25a4742a3e979" title="change size, without preserving contents">New</a>(params.GetEncodedElementSize(<span class="keyword">true</span>) + params.GetEncodedElementSize(<span class="keyword">false</span>));
<a name="l00506"></a>00506                         params.EncodeElement(<span class="keyword">true</span>, ephemeralPublicKey, agreedSecret);
<a name="l00507"></a>00507                         params.EncodeElement(<span class="keyword">false</span>, agreedElement, agreedSecret + params.GetEncodedElementSize(<span class="keyword">true</span>));
<a name="l00508"></a>00508                 }
<a name="l00509"></a>00509                 <span class="keywordflow">else</span>
<a name="l00510"></a>00510                 {
<a name="l00511"></a>00511                         agreedSecret.<a class="code" href="class_sec_block.html#a90d46e577c951d81a2d25a4742a3e979" title="change size, without preserving contents">New</a>(params.GetEncodedElementSize(<span class="keyword">false</span>));
<a name="l00512"></a>00512                         params.EncodeElement(<span class="keyword">false</span>, agreedElement, agreedSecret);
<a name="l00513"></a>00513                 }
<a name="l00514"></a>00514 
<a name="l00515"></a>00515                 <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> derivationParameters;
<a name="l00516"></a>00516                 parameters.<a class="code" href="class_name_value_pairs.html#a96686e9f8d6ce3ab870e516fb72b608e" title="get a named value, returns true if the name exists">GetValue</a>(Name::KeyDerivationParameters(), derivationParameters);
<a name="l00517"></a>00517                 KDF::DeriveKey(derivedKey, derivedLength, agreedSecret, agreedSecret.size(), derivationParameters.begin(), derivationParameters.size());
<a name="l00518"></a>00518         }
<a name="l00519"></a>00519 };
<a name="l00520"></a>00520 <span class="comment"></span>
<a name="l00521"></a>00521 <span class="comment">//! Discrete Log Integrated Encryption Scheme, AKA &lt;a href=&quot;http://www.weidai.com/scan-mirror/ca.html#DLIES&quot;&gt;DLIES&lt;/a&gt;</span>
<a name="l00522"></a>00522 <span class="comment"></span><span class="keyword">template</span> &lt;<span class="keyword">class</span> COFACTOR_OPTION = NoCofactorMultiplication, <span class="keywordtype">bool</span> DHAES_MODE = true&gt;
<a name="l00523"></a><a class="code" href="struct_d_l_i_e_s.html">00523</a> <span class="keyword">struct </span><a class="code" href="struct_d_l_i_e_s.html" title="Discrete Log Integrated Encryption Scheme, AKA DLIES.">DLIES</a>
<a name="l00524"></a>00524         : <span class="keyword">public</span> <a class="code" href="class_d_l___e_s.html" title="Discrete Log Based Encryption Scheme.">DL_ES</a>&lt;
<a name="l00525"></a>00525                 DL_CryptoKeys_GFP,
<a name="l00526"></a>00526                 DL_KeyAgreementAlgorithm_DH&lt;Integer, COFACTOR_OPTION&gt;,
<a name="l00527"></a>00527                 DL_KeyDerivationAlgorithm_P1363&lt;Integer, DHAES_MODE, P1363_KDF2&lt;SHA1&gt; &gt;,
<a name="l00528"></a>00528                 DL_EncryptionAlgorithm_Xor&lt;HMAC&lt;SHA1&gt;, DHAES_MODE&gt;,
<a name="l00529"></a>00529                 DLIES&lt;&gt; &gt;
<a name="l00530"></a>00530 {
<a name="l00531"></a>00531         <span class="keyword">static</span> std::string CRYPTOPP_API StaticAlgorithmName() {<span class="keywordflow">return</span> <span class="stringliteral">&quot;DLIES&quot;</span>;} <span class="comment">// TODO: fix this after name is standardized</span>
<a name="l00532"></a>00532 };
<a name="l00533"></a>00533 
<a name="l00534"></a>00534 NAMESPACE_END
<a name="l00535"></a>00535 
<a name="l00536"></a>00536 <span class="preprocessor">#endif</span>
</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>