| 140 | } |
| 141 | |
| 142 | bool decryptor::decrypt_impl(aead_cipher_manager& cipher_manager, media_type this_media_type, inbound_frame_processor& encrypted_frame, array_view<uint8_t> frame) |
| 143 | { |
| 144 | auto tag = encrypted_frame.get_tag(); |
| 145 | auto truncated_nonce = encrypted_frame.get_truncated_nonce(); |
| 146 | auto authenticated_data = encrypted_frame.get_authenticated_data(); |
| 147 | auto ciphertext_buffer = encrypted_frame.get_ciphertext(); |
| 148 | auto plaintext = encrypted_frame.get_plaintext(); |
| 149 | |
| 150 | // expand the truncated nonce to the full sized one needed for decryption |
| 151 | auto nonce_buffer = std::array<uint8_t, AES_GCM_128_NONCE_BYTES>(); |
| 152 | memcpy(nonce_buffer.data() + AES_GCM_128_TRUNCATED_SYNC_NONCE_OFFSET, &truncated_nonce, AES_GCM_128_TRUNCATED_SYNC_NONCE_BYTES); |
| 153 | |
| 154 | auto nonce_buffer_view = make_array_view<const uint8_t>(nonce_buffer.data(), nonce_buffer.size()); |
| 155 | |
| 156 | auto generation = cipher_manager.compute_wrapped_generation(truncated_nonce >> RATCHET_GENERATION_SHIFT_BITS); |
| 157 | |
| 158 | if (!cipher_manager.can_process_nonce(generation, truncated_nonce)) { |
| 159 | creator.log(dpp::ll_trace, "decrypt failed, cannot process nonce"); |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | // Get the cryptor for this generation |
| 164 | cipher_interface* cipher = cipher_manager.get_cipher(generation); |
| 165 | |
| 166 | if (cipher == nullptr) { |
| 167 | creator.log(dpp::ll_warning, "decrypt failed, no cryptor found for generation: " + std::to_string(generation)); |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | // perform the decryption |
| 172 | bool success = cipher->decrypt(plaintext, ciphertext_buffer, tag, nonce_buffer_view, authenticated_data); |
| 173 | stats[this_media_type].decrypt_attempts++; |
| 174 | |
| 175 | if (success) { |
| 176 | cipher_manager.report_cipher_success(generation, truncated_nonce); |
| 177 | } |
| 178 | |
| 179 | return success; |
| 180 | } |
| 181 | |
| 182 | size_t decryptor::get_max_plaintext_byte_size(media_type this_media_type, size_t encrypted_frame_size) |
| 183 | { |
nothing calls this directly
no test coverage detected