diff --git a/lib/crypto/utils.cpp b/lib/crypto/utils.cpp index cd5b79e26f7425a3dabf8b50d3e83e8fcee73878..0b2f031768359d487bd860d818400c1a2a3da445 100644 --- a/lib/crypto/utils.cpp +++ b/lib/crypto/utils.cpp @@ -203,9 +203,9 @@ encrypt_file(const std::string &plaintext) { mtx::crypto::EncryptedFile encryption_info; - // not sure if 16 bytes would be enough, 32 seems to be safe though + // iv has to be 16 bytes, key 32! BinaryBuf key = create_buffer(32); - BinaryBuf iv = create_buffer(32); + BinaryBuf iv = create_buffer(16); BinaryBuf cyphertext = AES_CTR_256_Encrypt(plaintext, key, iv); diff --git a/tests/e2ee.cpp b/tests/e2ee.cpp index baf58583d12fd270b6570f58acfbe0d387191d75..303908ff082868daae4ae66e6b2f19a805effd12 100644 --- a/tests/e2ee.cpp +++ b/tests/e2ee.cpp @@ -1139,6 +1139,10 @@ TEST(Encryption, EncryptedFile) ASSERT_EQ(plaintext, mtx::crypto::to_string(mtx::crypto::decrypt_file( mtx::crypto::to_string(encryption_data.first), encryption_data.second))); + // IV needs to be 16 bytes/128 bits + ASSERT_EQ(16, encryption_data.second.iv.size()); + // key needs to be 32 bytes/256 bits + ASSERT_EQ(32, encryption_data.second.key.k.size()); json j = R"({ "type": "m.room.message", diff --git a/tests/events.cpp b/tests/events.cpp index 62de2d710479d6efce448320cbdc3074d47cdb70..44eed16759428692a1b1eca6113cacc6f6d34925 100644 --- a/tests/events.cpp +++ b/tests/events.cpp @@ -347,7 +347,7 @@ TEST(StateEvents, JoinRules) "type": "m.room.join_rules" })"_json; - EXPECT_EQ(data, json(ns::StateEvent<ns::state::JoinRules>(data))); + EXPECT_EQ(data, json(ns::StateEvent<ns::state::JoinRules>(data))); data = R"({ "origin_server_ts": 1506761924018, @@ -363,7 +363,7 @@ TEST(StateEvents, JoinRules) "type": "m.room.join_rules" })"_json; - EXPECT_EQ(data, json(ns::StateEvent<ns::state::JoinRules>(data))); + EXPECT_EQ(data, json(ns::StateEvent<ns::state::JoinRules>(data))); data = R"({ "origin_server_ts": 1506761924018, @@ -379,7 +379,7 @@ TEST(StateEvents, JoinRules) "type": "m.room.join_rules" })"_json; - EXPECT_EQ(data, json(ns::StateEvent<ns::state::JoinRules>(data))); + EXPECT_EQ(data, json(ns::StateEvent<ns::state::JoinRules>(data))); } TEST(StateEvents, Member)