| 2156 | } |
| 2157 | |
| 2158 | Status TmpWriteHandle::CheckHashAndDecrypt( |
| 2159 | MemRange buffer, const BufferPoolClientCounters* counters) { |
| 2160 | DCHECK(FLAGS_disk_spill_encryption); |
| 2161 | DCHECK(write_range_ != nullptr); |
| 2162 | SCOPED_TIMER2(parent_->encryption_timer_, |
| 2163 | counters == nullptr ? nullptr : counters->encryption_time); |
| 2164 | |
| 2165 | // GCM mode will verify the integrity by itself |
| 2166 | if (!key_.IsGcmMode()) { |
| 2167 | if (!hash_.Verify(buffer.data(), buffer.len())) { |
| 2168 | return Status(TErrorCode::SCRATCH_READ_VERIFY_FAILED, buffer.len(), |
| 2169 | write_range_->file(), GetBackendString(), write_range_->offset()); |
| 2170 | } |
| 2171 | } |
| 2172 | Status decrypt_status = key_.Decrypt(buffer.data(), buffer.len(), buffer.data()); |
| 2173 | if (!decrypt_status.ok()) { |
| 2174 | // Treat decryption failing as a verification failure, but include extra info from |
| 2175 | // the decryption status. |
| 2176 | Status result_status(TErrorCode::SCRATCH_READ_VERIFY_FAILED, buffer.len(), |
| 2177 | write_range_->file(), GetBackendString(), write_range_->offset()); |
| 2178 | result_status.MergeStatus(decrypt_status); |
| 2179 | return result_status; |
| 2180 | } |
| 2181 | return Status::OK(); |
| 2182 | } |
| 2183 | |
| 2184 | void TmpWriteHandle::FreeCompressedBuffer() { |
| 2185 | if (compressed_.buffer() == nullptr) return; |