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

📄 default_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<a name="l00170"></a>00170         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> key(KEYLENGTH);<a name="l00171"></a>00171         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> IV(BLOCKSIZE);<a name="l00172"></a>00172         GenerateKeyIV(m_passphrase, m_passphrase.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>(), salt, SALTLENGTH, key, IV);<a name="l00173"></a>00173 <a name="l00174"></a>00174         m_cipher.SetKeyWithIV(key, key.size(), IV);<a name="l00175"></a>00175         std::auto_ptr&lt;StreamTransformationFilter&gt; decryptor(<span class="keyword">new</span> <a class="code" href="class_stream_transformation_filter.html" title="Filter Wrapper for StreamTransformation.">StreamTransformationFilter</a>(m_cipher));<a name="l00176"></a>00176 <a name="l00177"></a>00177         decryptor-&gt;Put(keyCheck, BLOCKSIZE);<a name="l00178"></a>00178         decryptor-&gt;ForceNextPut();<a name="l00179"></a>00179         decryptor-&gt;Get(check+BLOCKSIZE, BLOCKSIZE);<a name="l00180"></a>00180 <a name="l00181"></a>00181         <a class="code" href="class_proxy_filter.html#98a1d161913c42feb64951c396f0f3e0">SetFilter</a>(decryptor.release());<a name="l00182"></a>00182 <a name="l00183"></a>00183         <span class="keywordflow">if</span> (memcmp(check, check+BLOCKSIZE, BLOCKSIZE))<a name="l00184"></a>00184         {<a name="l00185"></a>00185                 <a class="code" href="class_default_decryptor.html#9b887466b08abc8eea2c2825b9ab3d2d">m_state</a> = <a class="code" href="class_default_decryptor.html#7961421ac0c0b58da061c793afbd8fa7bd88dfa019e7b11db45c6a10fc9008a6">KEY_BAD</a>;<a name="l00186"></a>00186                 <span class="keywordflow">if</span> (m_throwException)<a name="l00187"></a>00187                         <span class="keywordflow">throw</span> KeyBadErr();<a name="l00188"></a>00188         }<a name="l00189"></a>00189         <span class="keywordflow">else</span><a name="l00190"></a>00190                 <a class="code" href="class_default_decryptor.html#9b887466b08abc8eea2c2825b9ab3d2d">m_state</a> = <a class="code" href="class_default_decryptor.html#7961421ac0c0b58da061c793afbd8fa7186a86c06cbe907ada52bf5445058b8b">KEY_GOOD</a>;<a name="l00191"></a>00191 }<a name="l00192"></a>00192 <a name="l00193"></a>00193 <span class="comment">// ********************************************************</span><a name="l00194"></a>00194 <a name="l00195"></a>00195 <span class="keyword">static</span> <a class="code" href="class_h_m_a_c.html" title="HMAC">DefaultMAC</a> * NewDefaultEncryptorMAC(<span class="keyword">const</span> byte *passphrase, <span class="keywordtype">size_t</span> passphraseLength)<a name="l00196"></a>00196 {<a name="l00197"></a>00197         <span class="keywordtype">size_t</span> macKeyLength = <a class="code" href="class_variable_key_length.html#5bf532b28513e7e1d3d7202fd044b4c9">DefaultMAC::StaticGetValidKeyLength</a>(16);<a name="l00198"></a>00198         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> macKey(macKeyLength);<a name="l00199"></a>00199         <span class="comment">// since the MAC is encrypted there is no reason to mash the passphrase for many iterations</span><a name="l00200"></a>00200         Mash(passphrase, passphraseLength, macKey, macKeyLength, 1);<a name="l00201"></a>00201         <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="class_h_m_a_c.html" title="HMAC">DefaultMAC</a>(macKey, macKeyLength);<a name="l00202"></a>00202 }<a name="l00203"></a>00203 <a name="l00204"></a><a class="code" href="class_default_encryptor_with_m_a_c.html#50ae737f4a59b5e41db94700a3db8048">00204</a> <a class="code" href="class_default_encryptor_with_m_a_c.html#50ae737f4a59b5e41db94700a3db8048">DefaultEncryptorWithMAC::DefaultEncryptorWithMAC</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *passphrase, <a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> *attachment)<a name="l00205"></a>00205         : <a class="code" href="class_proxy_filter.html" title="Base class for Filter classes that are proxies for a chain of other filters.">ProxyFilter</a>(NULL, 0, 0, attachment)<a name="l00206"></a>00206         , m_mac(NewDefaultEncryptorMAC((const byte *)passphrase, strlen(passphrase)))<a name="l00207"></a>00207 {<a name="l00208"></a>00208         <a class="code" href="class_proxy_filter.html#98a1d161913c42feb64951c396f0f3e0">SetFilter</a>(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html" title="Filter Wrapper for HashTransformation.">HashFilter</a>(*m_mac, <span class="keyword">new</span> <a class="code" href="class_default_encryptor.html" title="Password-Based Encryptor using DES-EDE2.">DefaultEncryptor</a>(passphrase), <span class="keyword">true</span>));<a name="l00209"></a>00209 }<a name="l00210"></a>00210 <a name="l00211"></a><a class="code" href="class_default_encryptor_with_m_a_c.html#c1ec6e244c0ef9a71b9ccfd803db5cf3">00211</a> <a class="code" href="class_default_encryptor_with_m_a_c.html#50ae737f4a59b5e41db94700a3db8048">DefaultEncryptorWithMAC::DefaultEncryptorWithMAC</a>(<span class="keyword">const</span> byte *passphrase, <span class="keywordtype">size_t</span> passphraseLength, <a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> *attachment)<a name="l00212"></a>00212         : <a class="code" href="class_proxy_filter.html" title="Base class for Filter classes that are proxies for a chain of other filters.">ProxyFilter</a>(NULL, 0, 0, attachment)<a name="l00213"></a>00213         , m_mac(NewDefaultEncryptorMAC(passphrase, passphraseLength))<a name="l00214"></a>00214 {<a name="l00215"></a>00215         <a class="code" href="class_proxy_filter.html#98a1d161913c42feb64951c396f0f3e0">SetFilter</a>(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html" title="Filter Wrapper for HashTransformation.">HashFilter</a>(*m_mac, <span class="keyword">new</span> <a class="code" href="class_default_encryptor.html" title="Password-Based Encryptor using DES-EDE2.">DefaultEncryptor</a>(passphrase, passphraseLength), <span class="keyword">true</span>));<a name="l00216"></a>00216 }<a name="l00217"></a>00217 <a name="l00218"></a><a class="code" href="class_default_encryptor_with_m_a_c.html#15f048b97d7a5339a6f96523b613db61">00218</a> <span class="keywordtype">void</span> <a class="code" href="class_default_encryptor_with_m_a_c.html#15f048b97d7a5339a6f96523b613db61">DefaultEncryptorWithMAC::LastPut</a>(<span class="keyword">const</span> byte *inString, <span class="keywordtype">size_t</span> length)<a name="l00219"></a>00219 {<a name="l00220"></a>00220         <a class="code" href="class_proxy_filter.html#1f89e47a61f678d1d2dbb52ca2ba2996">m_filter</a>-&gt;MessageEnd();<a name="l00221"></a>00221 }<a name="l00222"></a>00222 <a name="l00223"></a>00223 <span class="comment">// ********************************************************</span><a name="l00224"></a>00224 <a name="l00225"></a><a class="code" href="class_default_decryptor_with_m_a_c.html#b83261139931c1a86c404c30b1f343de">00225</a> <a class="code" href="class_default_decryptor_with_m_a_c.html#b83261139931c1a86c404c30b1f343de">DefaultDecryptorWithMAC::DefaultDecryptorWithMAC</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *passphrase, <a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> *attachment, <span class="keywordtype">bool</span> throwException)<a name="l00226"></a>00226         : <a class="code" href="class_proxy_filter.html" title="Base class for Filter classes that are proxies for a chain of other filters.">ProxyFilter</a>(NULL, 0, 0, attachment)<a name="l00227"></a>00227         , m_mac(NewDefaultEncryptorMAC((const byte *)passphrase, strlen(passphrase)))<a name="l00228"></a>00228         , m_throwException(throwException)<a name="l00229"></a>00229 {<a name="l00230"></a>00230         <a class="code" href="class_proxy_filter.html#98a1d161913c42feb64951c396f0f3e0">SetFilter</a>(<span class="keyword">new</span> <a class="code" href="class_default_decryptor.html" title="Password-Based Decryptor using DES-EDE2.">DefaultDecryptor</a>(passphrase, m_hashVerifier=<span class="keyword">new</span> <a class="code" href="class_hash_verification_filter.html" title="Filter Wrapper for HashTransformation.">HashVerifier</a>(*m_mac, NULL, <a class="code" href="class_hash_verification_filter.html#4e171785f3f9b00d0a10f4c2afa1cc70aba5187c6265a8684096f2b4d4bfa9d1">HashVerifier::PUT_MESSAGE</a>), throwException));<a name="l00231"></a>00231 }<a name="l00232"></a>00232 <a name="l00233"></a><a class="code" href="class_default_decryptor_with_m_a_c.html#40ad312c0cd1c674051765581e28e997">00233</a> <a class="code" href="class_default_decryptor_with_m_a_c.html#b83261139931c1a86c404c30b1f343de">DefaultDecryptorWithMAC::DefaultDecryptorWithMAC</a>(<span class="keyword">const</span> byte *passphrase, <span class="keywordtype">size_t</span> passphraseLength, <a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> *attachment, <span class="keywordtype">bool</span> throwException)<a name="l00234"></a>00234         : <a class="code" href="class_proxy_filter.html" title="Base class for Filter classes that are proxies for a chain of other filters.">ProxyFilter</a>(NULL, 0, 0, attachment)<a name="l00235"></a>00235         , m_mac(NewDefaultEncryptorMAC(passphrase, passphraseLength))<a name="l00236"></a>00236         , m_throwException(throwException)<a name="l00237"></a>00237 {<a name="l00238"></a>00238         <a class="code" href="class_proxy_filter.html#98a1d161913c42feb64951c396f0f3e0">SetFilter</a>(<span class="keyword">new</span> <a class="code" href="class_default_decryptor.html" title="Password-Based Decryptor using DES-EDE2.">DefaultDecryptor</a>(passphrase, passphraseLength, m_hashVerifier=<span class="keyword">new</span> <a class="code" href="class_hash_verification_filter.html" title="Filter Wrapper for HashTransformation.">HashVerifier</a>(*m_mac, NULL, <a class="code" href="class_hash_verification_filter.html#4e171785f3f9b00d0a10f4c2afa1cc70aba5187c6265a8684096f2b4d4bfa9d1">HashVerifier::PUT_MESSAGE</a>), throwException));<a name="l00239"></a>00239 }<a name="l00240"></a>00240 <a name="l00241"></a><a class="code" href="class_default_decryptor_with_m_a_c.html#d565397a7ba3b57d8391c10d8bf76405">00241</a> <a class="code" href="class_default_decryptor.html#7961421ac0c0b58da061c793afbd8fa7">DefaultDecryptor::State</a> <a class="code" href="class_default_decryptor_with_m_a_c.html#d565397a7ba3b57d8391c10d8bf76405">DefaultDecryptorWithMAC::CurrentState</a>()<span class="keyword"> const</span><a name="l00242"></a>00242 <span class="keyword"></span>{<a name="l00243"></a>00243         <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><span class="keyword">const </span><a class="code" href="class_default_decryptor.html" title="Password-Based Decryptor using DES-EDE2.">DefaultDecryptor</a> *<span class="keyword">&gt;</span>(<a class="code" href="class_proxy_filter.html#1f89e47a61f678d1d2dbb52ca2ba2996">m_filter</a>.<a class="code" href="classmember__ptr.html#2d10dec2a51691b589d56b71ec78e59a">get</a>())-&gt;<a class="code" href="class_default_decryptor_with_m_a_c.html#d565397a7ba3b57d8391c10d8bf76405">CurrentState</a>();<a name="l00244"></a>00244 }<a name="l00245"></a>00245 <a name="l00246"></a><a class="code" href="class_default_decryptor_with_m_a_c.html#453ffefbd0a001b596ad63225e90472f">00246</a> <span class="keywordtype">bool</span> <a class="code" href="class_default_decryptor_with_m_a_c.html#453ffefbd0a001b596ad63225e90472f">DefaultDecryptorWithMAC::CheckLastMAC</a>()<span class="keyword"> const</span><a name="l00247"></a>00247 <span class="keyword"></span>{<a name="l00248"></a>00248         <span class="keywordflow">return</span> m_hashVerifier-&gt;<a class="code" href="class_hash_verification_filter.html#2145cdd7d14c8305fa784dc4622f8ad1">GetLastResult</a>();<a name="l00249"></a>00249 }<a name="l00250"></a>00250 <a name="l00251"></a><a class="code" href="class_default_decryptor_with_m_a_c.html#d9adeb4d5449e65de3ae460758ebe76d">00251</a> <span class="keywordtype">void</span> <a class="code" href="class_default_decryptor_with_m_a_c.html#d9adeb4d5449e65de3ae460758ebe76d">DefaultDecryptorWithMAC::LastPut</a>(<span class="keyword">const</span> byte *inString, <span class="keywordtype">size_t</span> length)<a name="l00252"></a>00252 {<a name="l00253"></a>00253         <a class="code" href="class_proxy_filter.html#1f89e47a61f678d1d2dbb52ca2ba2996">m_filter</a>-&gt;MessageEnd();<a name="l00254"></a>00254         <span class="keywordflow">if</span> (m_throwException &amp;&amp; !<a class="code" href="class_default_decryptor_with_m_a_c.html#453ffefbd0a001b596ad63225e90472f">CheckLastMAC</a>())<a name="l00255"></a>00255                 <span class="keywordflow">throw</span> <a class="code" href="class_default_decryptor_with_m_a_c_1_1_m_a_c_bad_err.html">MACBadErr</a>();<a name="l00256"></a>00256 }<a name="l00257"></a>00257 <a name="l00258"></a>00258 NAMESPACE_END</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Fri Jun 1 11:11:20 2007 for Crypto++ by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.2 </small></address></body></html>

⌨️ 快捷键说明

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