Skip to content

Commit

Permalink
Speed up AEAD on wrong prekey
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Nov 30, 2023
1 parent 39c41e5 commit 7f5e9bc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/libspark/aead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char> key = SparkUtils::kdf_aead(prekey);
std::vector<unsigned char> key_commitment = SparkUtils::commit_aead(prekey);

// Assert that the key commitment is valid
std::vector<unsigned char> 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<unsigned char> key = SparkUtils::kdf_aead(prekey);

// Set up the result
CDataStream result(SER_NETWORK, PROTOCOL_VERSION);

Expand Down

0 comments on commit 7f5e9bc

Please sign in to comment.