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

📄 bench2_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<a name="l00069"></a>00069         <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++)<a name="l00070"></a>00070                 priv.<a class="code" href="class_p_k___decryptor.html#b7466675ed050c440c16508f8a88cac1" title="decrypt a byte string, and return the length of plaintext">Decrypt</a>(rng, ciphertext, ciphertext.size(), plaintext);<a name="l00071"></a>00071 <a name="l00072"></a>00072         OutputResultOperations(name, <span class="stringliteral">"Decryption"</span>, <span class="keyword">false</span>, i, timeTaken);<a name="l00073"></a>00073 }<a name="l00074"></a>00074 <a name="l00075"></a>00075 <span class="keywordtype">void</span> BenchMarkSigning(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <a class="code" href="class_p_k___signer.html" title="interface for public-key signers">PK_Signer</a> &amp;key, <span class="keywordtype">double</span> timeTotal, <span class="keywordtype">bool</span> pc=<span class="keyword">false</span>)<a name="l00076"></a>00076 {<a name="l00077"></a>00077         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len = 16;<a name="l00078"></a>00078         <a class="code" href="class_l_c___r_n_g.html" title="linear congruential generator">LC_RNG</a> rng((word32)time(NULL));<a name="l00079"></a>00079         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">AlignedSecByteBlock</a> message(len), signature(key.<a class="code" href="class_p_k___signature_scheme.html#6e7deb95f656d3b3998b86ad971773f0" title="signature length if it only depends on the key, otherwise 0">SignatureLength</a>());<a name="l00080"></a>00080         rng.GenerateBlock(message, len);<a name="l00081"></a>00081 <a name="l00082"></a>00082         clock_t start = clock();<a name="l00083"></a>00083         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;<a name="l00084"></a>00084         <span class="keywordtype">double</span> timeTaken;<a name="l00085"></a>00085         <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++)<a name="l00086"></a>00086                 key.<a class="code" href="class_p_k___signer.html#6781cdd4a4a750a9720e268c90a24387" title="sign a message">SignMessage</a>(rng, message, len, signature);<a name="l00087"></a>00087 <a name="l00088"></a>00088         OutputResultOperations(name, <span class="stringliteral">"Signature"</span>, pc, i, timeTaken);<a name="l00089"></a>00089 <a name="l00090"></a>00090         <span class="keywordflow">if</span> (!pc &amp;&amp; key.<a class="code" href="class_private_key_algorithm.html#59f3867165685cc6ac6be3f53d5f371b" title="returns a const reference to the crypto material used by this object">GetMaterial</a>().<a class="code" href="class_crypto_material.html#35720c07870fcda4ae39148f8524274e" title="whether this object supports precomputation">SupportsPrecomputation</a>())<a name="l00091"></a>00091         {<a name="l00092"></a>00092                 key.<a class="code" href="class_private_key_algorithm.html#48cf4528f16263f2200d5b908a0b8ffb" title="returns a reference to the crypto material used by this object">AccessMaterial</a>().<a class="code" href="class_crypto_material.html#39e512d2ea70d0e967db98c19994a7fd" title="do precomputation">Precompute</a>(16);<a name="l00093"></a>00093                 BenchMarkSigning(name, key, timeTotal, <span class="keyword">true</span>);<a name="l00094"></a>00094         }<a name="l00095"></a>00095 }<a name="l00096"></a>00096 <a name="l00097"></a>00097 <span class="keywordtype">void</span> BenchMarkVerification(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keyword">const</span> <a class="code" href="class_p_k___signer.html" title="interface for public-key signers">PK_Signer</a> &amp;priv, <a class="code" href="class_p_k___verifier.html" title="interface for public-key signature verifiers">PK_Verifier</a> &amp;pub, <span class="keywordtype">double</span> timeTotal, <span class="keywordtype">bool</span> pc=<span class="keyword">false</span>)<a name="l00098"></a>00098 {<a name="l00099"></a>00099         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len = 16;<a name="l00100"></a>00100         <a class="code" href="class_l_c___r_n_g.html" title="linear congruential generator">LC_RNG</a> rng((word32)time(NULL));<a name="l00101"></a>00101         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">AlignedSecByteBlock</a> message(len), signature(pub.<a class="code" href="class_p_k___signature_scheme.html#6e7deb95f656d3b3998b86ad971773f0" title="signature length if it only depends on the key, otherwise 0">SignatureLength</a>());<a name="l00102"></a>00102         rng.GenerateBlock(message, len);<a name="l00103"></a>00103         priv.<a class="code" href="class_p_k___signer.html#6781cdd4a4a750a9720e268c90a24387" title="sign a message">SignMessage</a>(rng, message, len, signature);<a name="l00104"></a>00104 <a name="l00105"></a>00105         clock_t start = clock();<a name="l00106"></a>00106         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;<a name="l00107"></a>00107         <span class="keywordtype">double</span> timeTaken;<a name="l00108"></a>00108         <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++)<a name="l00109"></a>00109                 pub.<a class="code" href="class_p_k___verifier.html#4640a967fd291f8be86c1b721dc73b2d" title="check whether input signature is a valid signature for input message">VerifyMessage</a>(message, len, signature, signature.size());<a name="l00110"></a>00110 <a name="l00111"></a>00111         OutputResultOperations(name, <span class="stringliteral">"Verification"</span>, pc, i, timeTaken);<a name="l00112"></a>00112 <a name="l00113"></a>00113         <span class="keywordflow">if</span> (!pc &amp;&amp; pub.<a class="code" href="class_public_key_algorithm.html#8c2bb02751348ff151ad9d4756cafd74" title="returns a const reference to the crypto material used by this object">GetMaterial</a>().<a class="code" href="class_crypto_material.html#35720c07870fcda4ae39148f8524274e" title="whether this object supports precomputation">SupportsPrecomputation</a>())<a name="l00114"></a>00114         {<a name="l00115"></a>00115                 pub.<a class="code" href="class_public_key_algorithm.html#74b77db3086e07caf5506fda9ec204e7" title="returns a reference to the crypto material used by this object">AccessMaterial</a>().<a class="code" href="class_crypto_material.html#39e512d2ea70d0e967db98c19994a7fd" title="do precomputation">Precompute</a>(16);<a name="l00116"></a>00116                 BenchMarkVerification(name, priv, pub, timeTotal, <span class="keyword">true</span>);<a name="l00117"></a>00117         }<a name="l00118"></a>00118 }<a name="l00119"></a>00119 <a name="l00120"></a>00120 <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" title="interface for domains of simple key agreement protocols">SimpleKeyAgreementDomain</a> &amp;d, <span class="keywordtype">double</span> timeTotal, <span class="keywordtype">bool</span> pc=<span class="keyword">false</span>)<a name="l00121"></a>00121 {<a name="l00122"></a>00122         <a class="code" href="class_l_c___r_n_g.html" title="linear congruential generator">LC_RNG</a> rng((word32)time(NULL));<a name="l00123"></a>00123         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> priv(d.<a class="code" href="class_simple_key_agreement_domain.html#131fa4e8260ec044fc12a540e8470325" title="return length of private keys in this domain">PrivateKeyLength</a>()), pub(d.<a class="code" href="class_simple_key_agreement_domain.html#0a96f98bb61ae0777604e035e7984bd1" title="return length of public keys in this domain">PublicKeyLength</a>());<a name="l00124"></a>00124 <a name="l00125"></a>00125         clock_t start = clock();<a name="l00126"></a>00126         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;<a name="l00127"></a>00127         <span class="keywordtype">double</span> timeTaken;<a name="l00128"></a>00128         <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++)<a name="l00129"></a>00129                 d.<a class="code" href="class_simple_key_agreement_domain.html#75629cd8157dca667c6aff0562ca59af" title="generate private/public key pair">GenerateKeyPair</a>(rng, priv, pub);<a name="l00130"></a>00130 <a name="l00131"></a>00131         OutputResultOperations(name, <span class="stringliteral">"Key-Pair Generation"</span>, pc, i, timeTaken);<a name="l00132"></a>00132 <a name="l00133"></a>00133         <span class="keywordflow">if</span> (!pc &amp;&amp; d.<a class="code" href="class_key_agreement_algorithm.html#3a1eb8e141b2f26a21efed7a1d7744c9" title="returns a const reference to the crypto material used by this object">GetMaterial</a>().<a class="code" href="class_crypto_material.html#35720c07870fcda4ae39148f8524274e" title="whether this object supports precomputation">SupportsPrecomputation</a>())<a name="l00134"></a>00134         {<a name="l00135"></a>00135                 d.<a class="code" href="class_key_agreement_algorithm.html#b9c52198ff0dd877243c9520d96beaaa" title="returns a reference to the crypto material used by this object">AccessMaterial</a>().<a class="code" href="class_crypto_material.html#39e512d2ea70d0e967db98c19994a7fd" title="do precomputation">Precompute</a>(16);<a name="l00136"></a>00136                 BenchMarkKeyGen(name, d, timeTotal, <span class="keyword">true</span>);<a name="l00137"></a>00137         }<a name="l00138"></a>00138 }<a name="l00139"></a>00139 <a name="l00140"></a>00140 <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" title="interface for domains of authenticated key agreement protocols">AuthenticatedKeyAgreementDomain</a> &amp;d, <span class="keywordtype">double</span> timeTotal, <span class="keywordtype">bool</span> pc=<span class="keyword">false</span>)<a name="l00141"></a>00141 {<a name="l00142"></a>00142         <a class="code" href="class_l_c___r_n_g.html" title="linear congruential generator">LC_RNG</a> rng((word32)time(NULL));<a name="l00143"></a>00143         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> priv(d.<a class="code" href="class_authenticated_key_agreement_domain.html#33c0c85b5ea7b2bd97d91676997b0e34" title="return length of ephemeral private keys in this domain">EphemeralPrivateKeyLength</a>()), pub(d.<a class="code" href="class_authenticated_key_agreement_domain.html#50a15071c932e3bb134c6cb8f4c6d4f1" title="return length of ephemeral public keys in this domain">EphemeralPublicKeyLength</a>());<a name="l00144"></a>00144 <a name="l00145"></a>00145         clock_t start = clock();<a name="l00146"></a>00146         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;<a name="l00147"></a>00147         <span class="keywordtype">double</span> timeTaken;<a name="l00148"></a>00148         <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++)<a name="l00149"></a>00149                 d.<a class="code" href="class_authenticated_key_agreement_domain.html#18f1fc5fa590be704d53759e44fba093" title="generate private/public key pair">GenerateEphemeralKeyPair</a>(rng, priv, pub);<a name="l00150"></a>00150 <a name="l00151"></a>00151         OutputResultOperations(name, <span class="stringliteral">"Key-Pair Generation"</span>, pc, i, timeTaken);<a name="l00152"></a>00152 <a name="l00153"></a>00153         <span class="keywordflow">if</span> (!pc &amp;&amp; d.<a class="code" href="class_key_agreement_algorithm.html#3a1eb8e141b2f26a21efed7a1d7744c9" title="returns a const reference to the crypto material used by this object">GetMaterial</a>().<a class="code" href="class_crypto_material.html#35720c07870fcda4ae39148f8524274e" title="whether this object supports precomputation">SupportsPrecomputation</a>())<a name="l00154"></a>00154         {<a name="l00155"></a>00155                 d.<a class="code" href="class_key_agreement_algorithm.html#b9c52198ff0dd877243c9520d96beaaa" title="returns a reference to the crypto material used by this object">AccessMaterial</a>().<a class="code" href="class_crypto_material.html#39e512d2ea70d0e967db98c19994a7fd" title="do precomputation">Precompute</a>(16);<a name="l00156"></a>00156                 BenchMarkKeyGen(name, d, timeTotal, <span class="keyword">true</span>);<a name="l00157"></a>00157         }

⌨️ 快捷键说明

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