📄 bench2_8cpp-source.html
字号:
<a name="l00158"></a>00158 }<a name="l00159"></a>00159 <a name="l00160"></a>00160 <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" title="interface for domains of simple key agreement protocols">SimpleKeyAgreementDomain</a> &d, <span class="keywordtype">double</span> timeTotal, <span class="keywordtype">bool</span> pc=<span class="keyword">false</span>)<a name="l00161"></a>00161 {<a name="l00162"></a>00162 <a class="code" href="class_l_c___r_n_g.html" title="linear congruential generator">LC_RNG</a> rng((word32)time(NULL));<a name="l00163"></a>00163 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> priv1(d.<a class="code" href="class_simple_key_agreement_domain.html#131fa4e8260ec044fc12a540e8470325" title="return length of private keys in this domain">PrivateKeyLength</a>()), priv2(d.<a class="code" href="class_simple_key_agreement_domain.html#131fa4e8260ec044fc12a540e8470325" title="return length of private keys in this domain">PrivateKeyLength</a>());<a name="l00164"></a>00164 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> pub1(d.<a class="code" href="class_simple_key_agreement_domain.html#0a96f98bb61ae0777604e035e7984bd1" title="return length of public keys in this domain">PublicKeyLength</a>()), pub2(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="l00165"></a>00165 d.<a class="code" href="class_simple_key_agreement_domain.html#75629cd8157dca667c6aff0562ca59af" title="generate private/public key pair">GenerateKeyPair</a>(rng, priv1, pub1);<a name="l00166"></a>00166 d.<a class="code" href="class_simple_key_agreement_domain.html#75629cd8157dca667c6aff0562ca59af" title="generate private/public key pair">GenerateKeyPair</a>(rng, priv2, pub2);<a name="l00167"></a>00167 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> val(d.<a class="code" href="class_simple_key_agreement_domain.html#fbf257cf0f75e66070e2636939e9c2ca" title="return length of agreed value produced">AgreedValueLength</a>());<a name="l00168"></a>00168 <a name="l00169"></a>00169 clock_t start = clock();<a name="l00170"></a>00170 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;<a name="l00171"></a>00171 <span class="keywordtype">double</span> timeTaken;<a name="l00172"></a>00172 <span class="keywordflow">for</span> (timeTaken=(<span class="keywordtype">double</span>)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)<a name="l00173"></a>00173 {<a name="l00174"></a>00174 d.<a class="code" href="class_simple_key_agreement_domain.html#732339ca730408cca7b1191fc32eb39e" title="derive agreed value from your private key and couterparty's public key, return false...">Agree</a>(val, priv1, pub2);<a name="l00175"></a>00175 d.<a class="code" href="class_simple_key_agreement_domain.html#732339ca730408cca7b1191fc32eb39e" title="derive agreed value from your private key and couterparty's public key, return false...">Agree</a>(val, priv2, pub1);<a name="l00176"></a>00176 }<a name="l00177"></a>00177 <a name="l00178"></a>00178 OutputResultOperations(name, <span class="stringliteral">"Key Agreement"</span>, pc, i, timeTaken);<a name="l00179"></a>00179 }<a name="l00180"></a>00180 <a name="l00181"></a>00181 <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" title="interface for domains of authenticated key agreement protocols">AuthenticatedKeyAgreementDomain</a> &d, <span class="keywordtype">double</span> timeTotal, <span class="keywordtype">bool</span> pc=<span class="keyword">false</span>)<a name="l00182"></a>00182 {<a name="l00183"></a>00183 <a class="code" href="class_l_c___r_n_g.html" title="linear congruential generator">LC_RNG</a> rng((word32)time(NULL));<a name="l00184"></a>00184 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> spriv1(d.<a class="code" href="class_authenticated_key_agreement_domain.html#0a16421c7c21463f4b8a986b80f6c852" title="return length of static private keys in this domain">StaticPrivateKeyLength</a>()), spriv2(d.<a class="code" href="class_authenticated_key_agreement_domain.html#0a16421c7c21463f4b8a986b80f6c852" title="return length of static private keys in this domain">StaticPrivateKeyLength</a>());<a name="l00185"></a>00185 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> epriv1(d.<a class="code" href="class_authenticated_key_agreement_domain.html#33c0c85b5ea7b2bd97d91676997b0e34" title="return length of ephemeral private keys in this domain">EphemeralPrivateKeyLength</a>()), epriv2(d.<a class="code" href="class_authenticated_key_agreement_domain.html#33c0c85b5ea7b2bd97d91676997b0e34" title="return length of ephemeral private keys in this domain">EphemeralPrivateKeyLength</a>());<a name="l00186"></a>00186 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> spub1(d.<a class="code" href="class_authenticated_key_agreement_domain.html#744821a5d32333557adf304c09aeff6b" title="return length of static public keys in this domain">StaticPublicKeyLength</a>()), spub2(d.<a class="code" href="class_authenticated_key_agreement_domain.html#744821a5d32333557adf304c09aeff6b" title="return length of static public keys in this domain">StaticPublicKeyLength</a>());<a name="l00187"></a>00187 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> epub1(d.<a class="code" href="class_authenticated_key_agreement_domain.html#50a15071c932e3bb134c6cb8f4c6d4f1" title="return length of ephemeral public keys in this domain">EphemeralPublicKeyLength</a>()), epub2(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="l00188"></a>00188 d.<a class="code" href="class_authenticated_key_agreement_domain.html#e2c306a6582c6e592ecb2c13abfd7c9f" title="generate private/public key pair">GenerateStaticKeyPair</a>(rng, spriv1, spub1);<a name="l00189"></a>00189 d.<a class="code" href="class_authenticated_key_agreement_domain.html#e2c306a6582c6e592ecb2c13abfd7c9f" title="generate private/public key pair">GenerateStaticKeyPair</a>(rng, spriv2, spub2);<a name="l00190"></a>00190 d.<a class="code" href="class_authenticated_key_agreement_domain.html#18f1fc5fa590be704d53759e44fba093" title="generate private/public key pair">GenerateEphemeralKeyPair</a>(rng, epriv1, epub1);<a name="l00191"></a>00191 d.<a class="code" href="class_authenticated_key_agreement_domain.html#18f1fc5fa590be704d53759e44fba093" title="generate private/public key pair">GenerateEphemeralKeyPair</a>(rng, epriv2, epub2);<a name="l00192"></a>00192 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> val(d.<a class="code" href="class_authenticated_key_agreement_domain.html#6d8b96f8a17e555bc9c6565d169a2418" title="return length of agreed value produced">AgreedValueLength</a>());<a name="l00193"></a>00193 <a name="l00194"></a>00194 clock_t start = clock();<a name="l00195"></a>00195 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;<a name="l00196"></a>00196 <span class="keywordtype">double</span> timeTaken;<a name="l00197"></a>00197 <span class="keywordflow">for</span> (timeTaken=(<span class="keywordtype">double</span>)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2)<a name="l00198"></a>00198 {<a name="l00199"></a>00199 d.<a class="code" href="class_authenticated_key_agreement_domain.html#c9808fb56eacee0c08a9bbd22fe2c98e" title="derive agreed value from your private keys and couterparty's public keys, return...">Agree</a>(val, spriv1, epriv1, spub2, epub2);<a name="l00200"></a>00200 d.<a class="code" href="class_authenticated_key_agreement_domain.html#c9808fb56eacee0c08a9bbd22fe2c98e" title="derive agreed value from your private keys and couterparty's public keys, return...">Agree</a>(val, spriv2, epriv2, spub1, epub1);<a name="l00201"></a>00201 }<a name="l00202"></a>00202 <a name="l00203"></a>00203 OutputResultOperations(name, <span class="stringliteral">"Key Agreement"</span>, pc, i, timeTaken);<a name="l00204"></a>00204 }<a name="l00205"></a>00205 <a name="l00206"></a>00206 <span class="comment">//VC60 workaround: compiler bug triggered without the extra dummy parameters</span><a name="l00207"></a>00207 <span class="keyword">template</span> <<span class="keyword">class</span> SCHEME><a name="l00208"></a>00208 <span class="keywordtype">void</span> BenchMarkCrypto(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename, <span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keywordtype">double</span> timeTotal, SCHEME *x=NULL)<a name="l00209"></a>00209 {<a name="l00210"></a>00210 <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a> f(filename, <span class="keyword">true</span>, <span class="keyword">new</span> <a class="code" href="class_hex_decoder.html" title="Decode base 16 data back to bytes.">HexDecoder</a>());<a name="l00211"></a>00211 <span class="keyword">typename</span> SCHEME::Decryptor priv(f);<a name="l00212"></a>00212 <span class="keyword">typename</span> SCHEME::Encryptor pub(priv);<a name="l00213"></a>00213 BenchMarkEncryption(name, pub, timeTotal);<a name="l00214"></a>00214 BenchMarkDecryption(name, priv, pub, timeTotal);<a name="l00215"></a>00215 }<a name="l00216"></a>00216 <a name="l00217"></a>00217 <span class="comment">//VC60 workaround: compiler bug triggered without the extra dummy parameters</span><a name="l00218"></a>00218 <span class="keyword">template</span> <<span class="keyword">class</span> SCHEME><a name="l00219"></a>00219 <span class="keywordtype">void</span> BenchMarkSignature(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename, <span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keywordtype">double</span> timeTotal, SCHEME *x=NULL)<a name="l00220"></a>00220 {<a name="l00221"></a>00221 <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a> f(filename, <span class="keyword">true</span>, <span class="keyword">new</span> <a class="code" href="class_hex_decoder.html" title="Decode base 16 data back to bytes.">HexDecoder</a>());<a name="l00222"></a>00222 <span class="keyword">typename</span> SCHEME::Signer priv(f);<a name="l00223"></a>00223 <span class="keyword">typename</span> SCHEME::Verifier pub(priv);<a name="l00224"></a>00224 BenchMarkSigning(name, priv, timeTotal);<a name="l00225"></a>00225 BenchMarkVerification(name, priv, pub, timeTotal);<a name="l00226"></a>00226 }<a name="l00227"></a>00227 <a name="l00228"></a>00228 <span class="comment">//VC60 workaround: compiler bug triggered without the extra dummy parameters</span><a name="l00229"></a>00229 <span class="keyword">template</span> <<span class="keyword">class</span> D><a name="l00230"></a>00230 <span class="keywordtype">void</span> BenchMarkKeyAgreement(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename, <span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keywordtype">double</span> timeTotal, D *x=NULL)<a name="l00231"></a>00231 {<a name="l00232"></a>00232 <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a> f(filename, <span class="keyword">true</span>, <span class="keyword">new</span> <a class="code" href="class_hex_decoder.html" title="Decode base 16 data back to bytes.">HexDecoder</a>());<a name="l00233"></a>00233 D d(f);<a name="l00234"></a>00234 BenchMarkKeyGen(name, d, timeTotal);<a name="l00235"></a>00235 BenchMarkAgreement(name, d, timeTotal);<a name="l00236"></a>00236 }<a name="l00237"></a>00237 <a name="l00238"></a>00238 <span class="keyword">extern</span> <span class="keywordtype">double</span> g_hertz;<a name="l00239"></a>00239 <a name="l00240"></a>00240 <span class="keywordtype">void</span> BenchmarkAll2(<span class="keywordtype">double</span> t, <span class="keywordtype">double</span> hertz)<a name="l00241"></a>00241 {<a name="l00242"></a>00242 g_hertz = hertz;<a name="l00243"></a>00243 <a name="l00244"></a>00244 cout << <span class="stringliteral">"<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right>"</span> << endl;<a name="l00245"></a>00245 cout << <span class="stringliteral">"<THEAD><TR><TH>Operation<TH>Milliseconds/Operation"</span> << (g_hertz ? <span class="stringliteral">"<TH>Megacycles/Operation"</span> : <span class="stringliteral">""</span>) << endl;<a name="l00246"></a>00246
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -