⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bench_8cpp-source.html

📁 Crypto++是一个非常强大的密码学库,主要是功能全
💻 HTML
📖 第 1 页 / 共 5 页
字号:
00262         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len = 16;00263         <a class="code" href="class_l_c___r_n_g.html">LC_RNG</a> rng(time(NULL));00264         <a class="code" href="class_sec_block.html">SecByteBlock</a> message(len), signature(pub.<a class="code" href="class_p_k___signature_scheme.html#_p_k___verifier_with_recoverya6">SignatureLength</a>());00265         rng.<a class="code" href="class_random_number_generator.html#_x917_r_n_ga4">GenerateBlock</a>(message, len);00266         priv.<a class="code" href="class_p_k___signer.html#_signer_with_recovery_templatea11">SignMessage</a>(rng, message, len, signature);00267 00268         clock_t start = clock();00269         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;00270         <span class="keywordtype">double</span> timeTaken;00271         <span class="keywordflow">for</span> (timeTaken=(<span class="keywordtype">double</span>)0, i=0; timeTaken &lt; timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)00272                 pub.<a class="code" href="class_p_k___verifier.html#_verifier_with_recovery_templatea18">VerifyMessage</a>(message, len, signature);00273 00274         OutputResultOperations(name, <span class="stringliteral">"Verification"</span>, pc, i, timeTaken);00275 00276         <span class="keywordflow">if</span> (!pc &amp;&amp; pub.<a class="code" href="class_public_key_algorithm.html#_verifier_with_recovery_templatea20">GetMaterial</a>().<a class="code" href="class_crypto_material.html#_x_t_r___d_ha32">SupportsPrecomputation</a>())00277         {00278                 pub.<a class="code" href="class_public_key_algorithm.html#_verifier_with_recovery_templatea19">AccessMaterial</a>().<a class="code" href="class_crypto_material.html#_x_t_r___d_ha33">Precompute</a>(16);00279                 BenchMarkVerification(name, priv, pub, timeTotal, <span class="keyword">true</span>);00280         }00281 }00282 00283 <span class="keywordtype">void</span> BenchMarkKeyGen(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <a class="code" href="class_simple_key_agreement_domain.html">SimpleKeyAgreementDomain</a> &amp;d, <span class="keywordtype">double</span> timeTotal, <span class="keywordtype">bool</span> pc=<span class="keyword">false</span>)00284 {00285         <a class="code" href="class_l_c___r_n_g.html">LC_RNG</a> rng(time(NULL));00286         <a class="code" href="class_sec_block.html">SecByteBlock</a> priv(d.PrivateKeyLength()), pub(d.PublicKeyLength());00287 00288         clock_t start = clock();00289         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;00290         <span class="keywordtype">double</span> timeTaken;00291         <span class="keywordflow">for</span> (timeTaken=(<span class="keywordtype">double</span>)0, i=0; timeTaken &lt; timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)00292                 d.GenerateKeyPair(rng, priv, pub);00293 00294         OutputResultOperations(name, <span class="stringliteral">"Key-Pair Generation"</span>, pc, i, timeTaken);00295 00296         <span class="keywordflow">if</span> (!pc &amp;&amp; d.GetMaterial().SupportsPrecomputation())00297         {00298                 d.AccessMaterial().Precompute(16);00299                 BenchMarkKeyGen(name, d, timeTotal, <span class="keyword">true</span>);00300         }00301 }00302 00303 <span class="keywordtype">void</span> BenchMarkKeyGen(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <a class="code" href="class_authenticated_key_agreement_domain.html">AuthenticatedKeyAgreementDomain</a> &amp;d, <span class="keywordtype">double</span> timeTotal, <span class="keywordtype">bool</span> pc=<span class="keyword">false</span>)00304 {00305         <a class="code" href="class_l_c___r_n_g.html">LC_RNG</a> rng(time(NULL));00306         <a class="code" href="class_sec_block.html">SecByteBlock</a> priv(d.EphemeralPrivateKeyLength()), pub(d.EphemeralPublicKeyLength());00307 00308         clock_t start = clock();00309         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;00310         <span class="keywordtype">double</span> timeTaken;00311         <span class="keywordflow">for</span> (timeTaken=(<span class="keywordtype">double</span>)0, i=0; timeTaken &lt; timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)00312                 d.GenerateEphemeralKeyPair(rng, priv, pub);00313 00314         OutputResultOperations(name, <span class="stringliteral">"Key-Pair Generation"</span>, pc, i, timeTaken);00315 00316         <span class="keywordflow">if</span> (!pc &amp;&amp; d.GetMaterial().SupportsPrecomputation())00317         {00318                 d.AccessMaterial().Precompute(16);00319                 BenchMarkKeyGen(name, d, timeTotal, <span class="keyword">true</span>);00320         }00321 }00322 00323 <span class="keywordtype">void</span> BenchMarkAgreement(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <a class="code" href="class_simple_key_agreement_domain.html">SimpleKeyAgreementDomain</a> &amp;d, <span class="keywordtype">double</span> timeTotal, <span class="keywordtype">bool</span> pc=<span class="keyword">false</span>)00324 {00325         <a class="code" href="class_l_c___r_n_g.html">LC_RNG</a> rng(time(NULL));00326         <a class="code" href="class_sec_block.html">SecByteBlock</a> priv1(d.PrivateKeyLength()), priv2(d.PrivateKeyLength());00327         <a class="code" href="class_sec_block.html">SecByteBlock</a> pub1(d.PublicKeyLength()), pub2(d.PublicKeyLength());00328         d.GenerateKeyPair(rng, priv1, pub1);00329         d.GenerateKeyPair(rng, priv2, pub2);00330         <a class="code" href="class_sec_block.html">SecByteBlock</a> val(d.AgreedValueLength());00331 00332         clock_t start = clock();00333         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;00334         <span class="keywordtype">double</span> timeTaken;00335         <span class="keywordflow">for</span> (timeTaken=(<span class="keywordtype">double</span>)0, i=0; timeTaken &lt; timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)00336         {00337                 d.Agree(val, priv1, pub2);00338                 d.Agree(val, priv2, pub1);00339         }00340 00341         OutputResultOperations(name, <span class="stringliteral">"Key Agreement"</span>, pc, i, timeTaken);00342 }00343 00344 <span class="keywordtype">void</span> BenchMarkAgreement(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <a class="code" href="class_authenticated_key_agreement_domain.html">AuthenticatedKeyAgreementDomain</a> &amp;d, <span class="keywordtype">double</span> timeTotal, <span class="keywordtype">bool</span> pc=<span class="keyword">false</span>)00345 {00346         <a class="code" href="class_l_c___r_n_g.html">LC_RNG</a> rng(time(NULL));00347         <a class="code" href="class_sec_block.html">SecByteBlock</a> spriv1(d.StaticPrivateKeyLength()), spriv2(d.StaticPrivateKeyLength());00348         <a class="code" href="class_sec_block.html">SecByteBlock</a> epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength());00349         <a class="code" href="class_sec_block.html">SecByteBlock</a> spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength());00350         <a class="code" href="class_sec_block.html">SecByteBlock</a> epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength());00351         d.GenerateStaticKeyPair(rng, spriv1, spub1);00352         d.GenerateStaticKeyPair(rng, spriv2, spub2);00353         d.GenerateEphemeralKeyPair(rng, epriv1, epub1);00354         d.GenerateEphemeralKeyPair(rng, epriv2, epub2);00355         <a class="code" href="class_sec_block.html">SecByteBlock</a> val(d.AgreedValueLength());00356 00357         clock_t start = clock();00358         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;00359         <span class="keywordtype">double</span> timeTaken;00360         <span class="keywordflow">for</span> (timeTaken=(<span class="keywordtype">double</span>)0, i=0; timeTaken &lt; timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)00361         {00362                 d.Agree(val, spriv1, epriv1, spub2, epub2);00363                 d.Agree(val, spriv2, epriv2, spub1, epub1);00364         }00365 00366         OutputResultOperations(name, <span class="stringliteral">"Key Agreement"</span>, pc, i, timeTaken);00367 }00368 00369 <span class="comment">//VC60 workaround: compiler bug triggered without the extra dummy parameters</span>00370 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;00371 <span class="keywordtype">void</span> BenchMarkKeyed(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keywordtype">double</span> timeTotal, T *x=NULL)00372 {00373         T c;00374         c.SetKeyWithIV(key, c.DefaultKeyLength(), key);00375         BenchMark(name, c, timeTotal);00376 }00377 00378 <span class="comment">//VC60 workaround: compiler bug triggered without the extra dummy parameters</span>00379 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;00380 <span class="keywordtype">void</span> BenchMarkKeyedVariable(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keywordtype">double</span> timeTotal, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> keyLength, T *x=NULL)00381 {00382         T c;00383         c.SetKeyWithIV(key, keyLength, key);00384         BenchMark(name, c, timeTotal);00385 }00386 00387 <span class="comment">//VC60 workaround: compiler bug triggered without the extra dummy parameters</span>00388 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;00389 <span class="keywordtype">void</span> BenchMarkKeyless(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keywordtype">double</span> timeTotal, T *x=NULL)00390 {00391         T c;00392         BenchMark(name, c, timeTotal);00393 }00394 00395 <span class="comment">//VC60 workaround: compiler bug triggered without the extra dummy parameters</span>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -