Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up AEAD on wrong prekey #1369

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/libspark/aead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ AEADEncryptedData AEAD::encrypt(const GroupElement& prekey, const std::string ad
// NOTE: This uses a fixed zero nonce, which is safe when used in Spark as directed
// It is NOT safe in general to do this!
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
Loading