diff --git a/src/libspark/aead.cpp b/src/libspark/aead.cpp index ada79bcc2c..c2c3428b66 100644 --- a/src/libspark/aead.cpp +++ b/src/libspark/aead.cpp @@ -44,15 +44,15 @@ AEADEncryptedData AEAD::encrypt(const GroupElement& prekey, const std::string ad // Perform authenticated decryption with ChaCha20-Poly1305 using key commitment CDataStream AEAD::decrypt_and_verify(const GroupElement& prekey, const std::string additional_data, AEADEncryptedData& data) { - // Derive the key and commitment - std::vector key = SparkUtils::kdf_aead(prekey); - std::vector key_commitment = SparkUtils::commit_aead(prekey); - // Assert that the key commitment is valid + std::vector key_commitment = SparkUtils::commit_aead(prekey); if (key_commitment != data.key_commitment) { throw std::runtime_error("Bad AEAD key commitment"); } + // Derive the key + std::vector key = SparkUtils::kdf_aead(prekey); + // Set up the result CDataStream result(SER_NETWORK, PROTOCOL_VERSION);