📄 gfpcrypt_8h-source.html
字号:
<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><a class="code" href="class_d_l___algorithm___n_r.html#1751a1111a3dc80e289eb522fc752747">00197</a> <span class="keywordtype">bool</span> <a class="code" href="class_d_l___algorithm___n_r.html#1751a1111a3dc80e289eb522fc752747">Verify</a>(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters.html" title="interface for DL group parameters">DL_GroupParameters<T></a> &params, <span class="keyword">const</span> <a class="code" href="class_d_l___public_key.html" title="interface for DL public keys">DL_PublicKey<T></a> &publicKey, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &e, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &r, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &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> &q = params.<a class="code" href="class_d_l___group_parameters.html#3555cec872358c0f314a375f56119c99">GetSubgroupOrder</a>();<a name="l00200"></a>00200 <span class="keywordflow">if</span> (r>=q || r<1 || s>=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.<a class="code" href="class_d_l___group_parameters.html#fb36d983bb45fe3b8acb1767c0060700">ConvertElementToInteger</a>(publicKey.<a class="code" href="class_d_l___public_key.html#63d54207437aeb69fcccdd1fbbde12e8">CascadeExponentiateBaseAndPublicElement</a>(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> <<span class="keyword">class</span> GP><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><GP><a name="l00212"></a>00212 {<a name="l00213"></a>00213 <span class="keyword">public</span>:<a name="l00214"></a><a class="code" href="class_d_l___public_key___g_f_p.html#06b9c78e45b40b6a5bdf3f3bb5a9b806">00214</a> <span class="keywordtype">void</span> <a class="code" href="class_d_l___public_key___g_f_p.html#06b9c78e45b40b6a5bdf3f3bb5a9b806">Initialize</a>(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters___integer_based.html" title="_">DL_GroupParameters_IntegerBased</a> &params, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &y)<a name="l00215"></a>00215 {this-><a class="code" href="class_d_l___key_impl.html#2ec144a5bedd2151b4bd0bb5118f1a8f">AccessGroupParameters</a>().Initialize(params); this-><a class="code" href="class_d_l___public_key.html#86cac45fc0ddaf07c057061b93cd8ce1">SetPublicElement</a>(y);}<a name="l00216"></a><a class="code" href="class_d_l___public_key___g_f_p.html#3488c76b9b7aa9b78ef83bc30b546c6d">00216</a> <span class="keywordtype">void</span> <a class="code" href="class_d_l___public_key___g_f_p.html#06b9c78e45b40b6a5bdf3f3bb5a9b806">Initialize</a>(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &g, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &y)<a name="l00217"></a>00217 {this-><a class="code" href="class_d_l___key_impl.html#2ec144a5bedd2151b4bd0bb5118f1a8f">AccessGroupParameters</a>().Initialize(p, g); this-><a class="code" href="class_d_l___public_key.html#86cac45fc0ddaf07c057061b93cd8ce1">SetPublicElement</a>(y);}<a name="l00218"></a><a class="code" href="class_d_l___public_key___g_f_p.html#df536d6b1f23579db94bf563b8af45eb">00218</a> <span class="keywordtype">void</span> <a class="code" href="class_d_l___public_key___g_f_p.html#06b9c78e45b40b6a5bdf3f3bb5a9b806">Initialize</a>(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &q, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &g, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &y)<a name="l00219"></a>00219 {this-><a class="code" href="class_d_l___key_impl.html#2ec144a5bedd2151b4bd0bb5118f1a8f">AccessGroupParameters</a>().Initialize(p, q, g); this-><a class="code" href="class_d_l___public_key.html#86cac45fc0ddaf07c057061b93cd8ce1">SetPublicElement</a>(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#9776ea4e0c4629e9e699145e0cf20d36">00222</a> <span class="keywordtype">void</span> <a class="code" href="class_d_l___public_key___g_f_p.html#9776ea4e0c4629e9e699145e0cf20d36" 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> &bt, <span class="keywordtype">bool</span>, <span class="keywordtype">size_t</span>)<a name="l00223"></a>00223 {this-><a class="code" href="class_d_l___public_key.html#86cac45fc0ddaf07c057061b93cd8ce1">SetPublicElement</a>(<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#132a1c79c696cb4589e08e5f448df6d0">00224</a> <span class="keywordtype">void</span> <a class="code" href="class_d_l___public_key___g_f_p.html#132a1c79c696cb4589e08e5f448df6d0" 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> &bt)<span class="keyword"> const</span><a name="l00225"></a>00225 <span class="keyword"> </span>{this-><a class="code" href="class_d_l___public_key.html#b748086e14a92416ff49183f81f777c4">GetPublicElement</a>().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> <<span class="keyword">class</span> GP><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><GP><a name="l00231"></a>00231 {<a name="l00232"></a>00232 <span class="keyword">public</span>:<a name="l00233"></a><a class="code" href="class_d_l___private_key___g_f_p.html#d069712f5fa3ce6761d3f24d9c55b97d">00233</a> <span class="keywordtype">void</span> <a class="code" href="class_d_l___private_key___g_f_p.html#d069712f5fa3ce6761d3f24d9c55b97d">Initialize</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> modulusBits)<a name="l00234"></a>00234 {this-><a class="code" href="class_generatable_crypto_material.html#38d492343c32e530a5c2781b5797f755" title="calls the above function with a NameValuePairs object that just specifies "KeySize"...">GenerateRandomWithKeySize</a>(rng, modulusBits);}<a name="l00235"></a><a class="code" href="class_d_l___private_key___g_f_p.html#a9a70c3bbfed80f78b2303f78c5cc65f">00235</a> <span class="keywordtype">void</span> <a class="code" href="class_d_l___private_key___g_f_p.html#d069712f5fa3ce6761d3f24d9c55b97d">Initialize</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &g)<a name="l00236"></a>00236 {this-><a class="code" href="class_d_l___private_key_impl.html#b80a3771a5ef623677775f7c5dddb1e0" title="generate a random key or crypto parameters">GenerateRandom</a>(rng, MakeParameters(<span class="stringliteral">"Modulus"</span>, p)(<span class="stringliteral">"SubgroupGenerator"</span>, g));}<a name="l00237"></a><a class="code" href="class_d_l___private_key___g_f_p.html#2783fbb6b0bf3d8984fa639260f9b1f2">00237</a> <span class="keywordtype">void</span> <a class="code" href="class_d_l___private_key___g_f_p.html#d069712f5fa3ce6761d3f24d9c55b97d">Initialize</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &q, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &g)<a name="l00238"></a>00238 {this-><a class="code" href="class_d_l___private_key_impl.html#b80a3771a5ef623677775f7c5dddb1e0" title="generate a random key or crypto parameters">GenerateRandom</a>(rng, MakeParameters(<span class="stringliteral">"Modulus"</span>, p)(<span class="stringliteral">"SubgroupOrder"</span>, q)(<span class="stringliteral">"SubgroupGenerator"</span>, g));}<a name="l00239"></a><a class="code" href="class_d_l___private_key___g_f_p.html#f4fe22ddafeaf3f9c1ca455fe865ea02">00239</a> <span class="keywordtype">void</span> <a class="code" href="class_d_l___private_key___g_f_p.html#d069712f5fa3ce6761d3f24d9c55b97d">Initialize</a>(<span class="keyword">const</span> <a class="code" href="class_d_l___group_parameters___integer_based.html" title="_">DL_GroupParameters_IntegerBased</a> &params, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &x)<a name="l00240"></a>00240 {this-><a class="code" href="class_d_l___key_impl.html#2ec144a5bedd2151b4bd0bb5118f1a8f">AccessGroupParameters</a>().Initialize(params); this-><a class="code" href="class_d_l___private_key_impl.html#d2756b046f9ee7f3c254c9fc2bb8be5d">SetPrivateExponent</a>(x);}<a name="l00241"></a><a class="code" href="class_d_l___private_key___g_f_p.html#e104770a2623183d9b7acd0147322532">00241</a> <span class="keywordtype">void</span> <a class="code" href="class_d_l___private_key___g_f_p.html#d069712f5fa3ce6761d3f24d9c55b97d">Initialize</a>(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &g, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &x)<a name="l00242"></a>00242 {this-><a class="code" href="class_d_l___key_impl.html#2ec144a5bedd2151b4bd0bb5118f1a8f">AccessGroupParameters</a>().Initialize(p, g); this-><a class="code" href="class_d_l___private_key_impl.html#d2756b046f9ee7f3c254c9fc2bb8be5d">SetPrivateExponent</a>(x);}<a name="l00243"></a><a class="code" href="class_d_l___private_key___g_f_p.html#d81584c72391752ad51900e846bcca63">00243</a> <span class="keywordtype">void</span> <a class="code" href="class_d_l___private_key___g_f_p.html#d069712f5fa3ce6761d3f24d9c55b97d">Initialize</a>(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &q, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &g, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &x)<a name="l00244"></a>00244 {this-><a class="code" href="class_d_l___key_impl.html#2ec144a5bedd2151b4bd0bb5118f1a8f">AccessGroupParameters</a>().Initialize(p, q, g); this-><a class="code" href="class_d_l___private_key_impl.html#d2756b046f9ee7f3c254c9fc2bb8be5d">SetPrivateExponent</a>(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><a class="code" href="struct_d_l___signature_keys___g_f_p.html#8cfc9c16dc935bb5886db63120db4666">00250</a> <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><a class="code" href="struct_d_l___signature_keys___g_f_p.html#21c8ecad310fec227efb7495a2d826a5">00251</a> <span class="keyword">typedef</span> <a class="code" href="class_d_l___public_key___g_f_p.html">DL_PublicKey_GFP<GroupParameters></a> <a class="code" href="class_d_l___public_key___g_f_p.html">PublicKey</a>;<a name="l00252"></a><a class="code" href="struct_d_l___signature_keys___g_f_p.html#ffa2c06ef72c51a673ad91993dd772ab">00252</a> <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<GroupParameters></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><a class="code" href="struct_d_l___crypto_keys___g_f_p.html#e775386f9d0dfc252bdd1b58dbb5a529">00258</a> <span class="keyword">typedef</span> DL_GroupParameters_GFP_DefaultSafePrime <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><a class="code" href="struct_d_l___crypto_keys___g_f_p.html#6675e22c646660d02ad3d01604031135">00259</a> <span class="keyword">typedef</span> <a class="code" href="class_d_l___public_key___g_f_p.html">DL_PublicKey_GFP<GroupParameters></a> <a class="code" href="class_d_l___public_key___g_f_p.html">PublicKey</a>;<a name="l00260"></a><a class="code" href="struct_d_l___crypto_keys___g_f_p.html#b9e7e2d594a87bf4a1777f23c721c22e">00260</a> <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<GroupParameters></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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -