| 180 | |
| 181 | template <class BC, class H, class Info> |
| 182 | void DataDecryptor<BC,H,Info>::CheckKey(const byte *salt, const byte *keyCheck) |
| 183 | { |
| 184 | SecByteBlock check(STDMAX((unsigned int)2*BLOCKSIZE, (unsigned int)DIGESTSIZE)); |
| 185 | |
| 186 | H hash; |
| 187 | hash.Update(m_passphrase, m_passphrase.size()); |
| 188 | hash.Update(salt, SALTLENGTH); |
| 189 | hash.Final(check); |
| 190 | |
| 191 | SecByteBlock key(KEYLENGTH); |
| 192 | SecByteBlock IV(BLOCKSIZE); |
| 193 | GenerateKeyIV<BC,H,Info>(m_passphrase, m_passphrase.size(), salt, SALTLENGTH, ITERATIONS, key, IV); |
| 194 | |
| 195 | m_cipher.SetKeyWithIV(key, key.size(), IV); |
| 196 | member_ptr<StreamTransformationFilter> decryptor(new StreamTransformationFilter(m_cipher)); |
| 197 | |
| 198 | decryptor->Put(keyCheck, BLOCKSIZE); |
| 199 | decryptor->ForceNextPut(); |
| 200 | decryptor->Get(check+BLOCKSIZE, BLOCKSIZE); |
| 201 | |
| 202 | SetFilter(decryptor.release()); |
| 203 | |
| 204 | if (!VerifyBufsEqual(check, check+BLOCKSIZE, BLOCKSIZE)) |
| 205 | { |
| 206 | m_state = KEY_BAD; |
| 207 | if (m_throwException) |
| 208 | throw KeyBadErr(); |
| 209 | } |
| 210 | else |
| 211 | m_state = KEY_GOOD; |
| 212 | } |
| 213 | |
| 214 | // ******************************************************** |
| 215 |
nothing calls this directly
no test coverage detected