📄 default_8cpp-source.html
字号:
00130 {00131 }00132 00133 DefaultDecryptor::DefaultDecryptor(<span class="keyword">const</span> byte *passphrase, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> passphraseLength, <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment, <span class="keywordtype">bool</span> throwException)00134 : <a class="code" href="class_proxy_filter.html">ProxyFilter</a>(NULL, SALTLENGTH+BLOCKSIZE, 0, attachment)00135 , m_state(WAITING_FOR_KEYCHECK)00136 , m_passphrase(passphrase, passphraseLength)00137 , m_throwException(throwException)00138 {00139 }00140 00141 <span class="keywordtype">void</span> DefaultDecryptor::FirstPut(<span class="keyword">const</span> byte *inString)00142 {00143 CheckKey(inString, inString+SALTLENGTH);00144 }00145 00146 <span class="keywordtype">void</span> DefaultDecryptor::LastPut(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00147 {00148 <span class="keywordflow">if</span> (m_filter.get() == NULL)00149 {00150 m_state = KEY_BAD;00151 <span class="keywordflow">if</span> (m_throwException)00152 <span class="keywordflow">throw</span> KeyBadErr();00153 }00154 <span class="keywordflow">else</span>00155 {00156 m_filter->MessageEnd();00157 m_state = WAITING_FOR_KEYCHECK;00158 }00159 }00160 00161 <span class="keywordtype">void</span> DefaultDecryptor::CheckKey(<span class="keyword">const</span> byte *salt, <span class="keyword">const</span> byte *keyCheck)00162 {00163 <a class="code" href="class_sec_block.html">SecByteBlock</a> check(STDMAX((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)2*BLOCKSIZE, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)DefaultHashModule::DIGESTSIZE));00164 00165 <a class="code" href="class_s_h_a.html">DefaultHashModule</a> hash;00166 hash.Update(m_passphrase, m_passphrase.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>());00167 hash.Update(salt, SALTLENGTH);00168 hash.<a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea13">Final</a>(check);00169 00170 <a class="code" href="class_sec_block.html">SecByteBlock</a> key(KEYLENGTH);00171 <a class="code" href="class_sec_block.html">SecByteBlock</a> <a class="code" href="namespace_name.html#a4">IV</a>(BLOCKSIZE);00172 GenerateKeyIV(m_passphrase, m_passphrase.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>(), salt, SALTLENGTH, key, <a class="code" href="namespace_name.html#a4">IV</a>);00173 00174 m_cipher.SetKeyWithIV(key, key.size(), <a class="code" href="namespace_name.html#a4">IV</a>);00175 std::auto_ptr<StreamTransformationFilter> decryptor(<span class="keyword">new</span> <a class="code" href="class_stream_transformation_filter.html">StreamTransformationFilter</a>(m_cipher));00176 00177 decryptor->Put(keyCheck, BLOCKSIZE);00178 decryptor->ForceNextPut();00179 decryptor->Get(check+BLOCKSIZE, BLOCKSIZE);00180 00181 SetFilter(decryptor.release());00182 00183 <span class="keywordflow">if</span> (memcmp(check, check+BLOCKSIZE, BLOCKSIZE))00184 {00185 m_state = KEY_BAD;00186 <span class="keywordflow">if</span> (m_throwException)00187 <span class="keywordflow">throw</span> KeyBadErr();00188 }00189 <span class="keywordflow">else</span>00190 m_state = KEY_GOOD;00191 }00192 00193 <span class="comment">// ********************************************************</span>00194 00195 <span class="keyword">static</span> <a class="code" href="class_h_m_a_c.html">DefaultMAC</a> * NewDefaultEncryptorMAC(<span class="keyword">const</span> byte *passphrase, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> passphraseLength)00196 {00197 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> macKeyLength = DefaultMAC::StaticGetValidKeyLength(16);00198 <a class="code" href="class_sec_block.html">SecByteBlock</a> macKey(macKeyLength);00199 <span class="comment">// since the MAC is encrypted there is no reason to mash the passphrase for many iterations</span>00200 Mash(passphrase, passphraseLength, macKey, macKeyLength, 1);00201 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="class_h_m_a_c.html">DefaultMAC</a>(macKey, macKeyLength);00202 }00203 00204 DefaultEncryptorWithMAC::DefaultEncryptorWithMAC(<span class="keyword">const</span> <span class="keywordtype">char</span> *passphrase, <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment)00205 : <a class="code" href="class_proxy_filter.html">ProxyFilter</a>(NULL, 0, 0, attachment)00206 , m_mac(NewDefaultEncryptorMAC((const byte *)passphrase, strlen(passphrase)))00207 {00208 SetFilter(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html">HashFilter</a>(*m_mac, <span class="keyword">new</span> <a class="code" href="class_default_encryptor.html">DefaultEncryptor</a>(passphrase), <span class="keyword">true</span>));00209 }00210 00211 DefaultEncryptorWithMAC::DefaultEncryptorWithMAC(<span class="keyword">const</span> byte *passphrase, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> passphraseLength, <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment)00212 : <a class="code" href="class_proxy_filter.html">ProxyFilter</a>(NULL, 0, 0, attachment)00213 , m_mac(NewDefaultEncryptorMAC(passphrase, passphraseLength))00214 {00215 SetFilter(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html">HashFilter</a>(*m_mac, <span class="keyword">new</span> <a class="code" href="class_default_encryptor.html">DefaultEncryptor</a>(passphrase, passphraseLength), <span class="keyword">true</span>));00216 }00217 00218 <span class="keywordtype">void</span> DefaultEncryptorWithMAC::LastPut(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00219 {00220 m_filter->MessageEnd();00221 }00222 00223 <span class="comment">// ********************************************************</span>00224 00225 DefaultDecryptorWithMAC::DefaultDecryptorWithMAC(<span class="keyword">const</span> <span class="keywordtype">char</span> *passphrase, <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment, <span class="keywordtype">bool</span> throwException)00226 : <a class="code" href="class_proxy_filter.html">ProxyFilter</a>(NULL, 0, 0, attachment)00227 , m_mac(NewDefaultEncryptorMAC((const byte *)passphrase, strlen(passphrase)))00228 , m_throwException(throwException)00229 {00230 SetFilter(<span class="keyword">new</span> <a class="code" href="class_default_decryptor.html">DefaultDecryptor</a>(passphrase, m_hashVerifier=<span class="keyword">new</span> <a class="code" href="class_hash_verification_filter.html">HashVerifier</a>(*m_mac, NULL, HashVerifier::PUT_MESSAGE), throwException));00231 }00232 00233 DefaultDecryptorWithMAC::DefaultDecryptorWithMAC(<span class="keyword">const</span> byte *passphrase, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> passphraseLength, <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment, <span class="keywordtype">bool</span> throwException)00234 : <a class="code" href="class_proxy_filter.html">ProxyFilter</a>(NULL, 0, 0, attachment)00235 , m_mac(NewDefaultEncryptorMAC(passphrase, passphraseLength))00236 , m_throwException(throwException)00237 {00238 SetFilter(<span class="keyword">new</span> <a class="code" href="class_default_decryptor.html">DefaultDecryptor</a>(passphrase, passphraseLength, m_hashVerifier=<span class="keyword">new</span> <a class="code" href="class_hash_verification_filter.html">HashVerifier</a>(*m_mac, NULL, HashVerifier::PUT_MESSAGE), throwException));00239 }00240 00241 DefaultDecryptor::State DefaultDecryptorWithMAC::CurrentState()<span class="keyword"> const</span>00242 <span class="keyword"></span>{00243 <span class="keywordflow">return</span> static_cast<const DefaultDecryptor *>(m_filter.get())->CurrentState();00244 }00245 00246 <span class="keywordtype">bool</span> DefaultDecryptorWithMAC::CheckLastMAC()<span class="keyword"> const</span>00247 <span class="keyword"></span>{00248 <span class="keywordflow">return</span> m_hashVerifier-><a class="code" href="class_hash_verification_filter.html#_hash_verification_filtera1">GetLastResult</a>();00249 }00250 00251 <span class="keywordtype">void</span> DefaultDecryptorWithMAC::LastPut(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00252 {00253 m_filter->MessageEnd();00254 <span class="keywordflow">if</span> (m_throwException && !CheckLastMAC())00255 <span class="keywordflow">throw</span> MACBadErr();00256 }00257 00258 NAMESPACE_END</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:11 2003 for Crypto++ by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -